From 261e7ea5d4bbac4fc9ae2c058c70846a92d7f6b0 Mon Sep 17 00:00:00 2001 From: Sacred Seven Date: Sun, 26 Oct 2014 18:24:46 +0330 Subject: JalaliCalendar in broadcast messages --- app/views/admin/broadcast_messages/index.html.haml | 47 +++++++++++++++++++--- app/views/projects/milestones/_form.html.haml | 1 + config/application.rb | 2 +- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/app/views/admin/broadcast_messages/index.html.haml b/app/views/admin/broadcast_messages/index.html.haml index 2b662eaa1d7..77495724e15 100644 --- a/app/views/admin/broadcast_messages/index.html.haml +++ b/app/views/admin/broadcast_messages/index.html.haml @@ -1,3 +1,8 @@ += stylesheet_link_tag "JalaliJSCalendar-1.4/calendar-blue" += javascript_include_tag "JalaliJSCalendar-1.4/jalali" += javascript_include_tag "JalaliJSCalendar-1.4/calendar" += javascript_include_tag "JalaliJSCalendar-1.4/calendar-setup" += javascript_include_tag "JalaliJSCalendar-1.4/lang/calendar-fa" %h3.page-title Broadcast Messages %p.light @@ -30,12 +35,14 @@ .light 6 character hex values starting with a # sign. .form-group = f.label :starts_at, class: 'control-label' - .col-sm-10.datetime-controls - = f.datetime_select :starts_at + .col-sm-10.datetime-controls{ style: 'width: auto' } + = f.hidden_field :starts_at + #datepicker1 .form-group = f.label :ends_at, class: 'control-label' - .col-sm-10.datetime-controls - = f.datetime_select :ends_at + .col-sm-10.datetime-controls{ style: 'width: auto' } + = f.hidden_field :ends_at + #datepicker2 .form-actions = f.submit "Add broadcast message", class: "btn btn-create" @@ -46,11 +53,11 @@ .pull-right - if broadcast_message.starts_at %strong - #{broadcast_message.starts_at.to_s(:short)} + #{JalaliDate.new(broadcast_message.starts_at).strftime("%A %d %b %Y %H:%M")} \... - if broadcast_message.ends_at %strong - #{broadcast_message.ends_at.to_s(:short)} + #{JalaliDate.new(broadcast_message.ends_at).strftime("%A %d %b %Y %H:%M")}   = link_to [:admin, broadcast_message], method: :delete, remote: true, class: 'remove-row btn btn-tiny' do %i.fa.fa-times.cred @@ -59,3 +66,31 @@ = paginate @broadcast_messages + +:javascript + function utcString(date) { + var utc = new Date(date.getTime() + date.getTimezoneOffset() * 60000); + return utc.toLocaleFormat("%Y/%m/%d %H:%M"); + } + var now = new Date(); + var nowCounterUTC = new Date(now.getTime() - now.getTimezoneOffset() * 60000); + Calendar.setup({ + inputField : "broadcast_message_starts_at", + flat : "datepicker1", // id of the input field + flatCallback : function(calendar) {$('#broadcast_message_starts_at').val(utcString(calendar.date))}, + ifFormat : "%Y/%m/%d %H:%M", // format of the input field + dateType : 'jalali', + timeFormat : '24', + showsTime : true, + weekNumbers : false + }).setDate(nowCounterUTC); + Calendar.setup({ + inputField : "broadcast_message_ends_at", + flat : "datepicker2", // id of the input field + flatCallback : function(calendar) {$('#broadcast_message_ends_at').val(utcString(calendar.date))}, + ifFormat : "%Y/%m/%d %H:%M", // format of the input field + dateType : 'jalali', + timeFormat : '24', + showsTime : true, + weekNumbers : false + }).setDate(nowCounterUTC); diff --git a/app/views/projects/milestones/_form.html.haml b/app/views/projects/milestones/_form.html.haml index 827b32eb9ca..6ffde743367 100644 --- a/app/views/projects/milestones/_form.html.haml +++ b/app/views/projects/milestones/_form.html.haml @@ -51,6 +51,7 @@ :javascript disableButtonIfEmptyField("#milestone_title", ".btn-save"); Calendar.setup({ + inputField : "milestone_due_date", flat : "datepicker", // id of the input field flatCallback : function(calendar) {$('#milestone_due_date').val(calendar.date.toLocaleFormat("%Y/%m/%d"))}, ifFormat : "%Y/%m/%d", // format of the input field diff --git a/config/application.rb b/config/application.rb index e36df913d0b..b3524e48634 100644 --- a/config/application.rb +++ b/config/application.rb @@ -25,7 +25,7 @@ module Gitlab # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' + config.time_zone = 'Tehran' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] -- cgit v1.2.1