diff --git a/app/assets/javascripts/app/controllers/_ui_element/business_hours.js.coffee b/app/assets/javascripts/app/controllers/_ui_element/business_hours.js.coffee new file mode 100644 index 000000000..5f25812d6 --- /dev/null +++ b/app/assets/javascripts/app/controllers/_ui_element/business_hours.js.coffee @@ -0,0 +1,39 @@ +class App.UiElement.business_hours + @render: (attribute, params) -> + + hours = { + mon: { + active: true + timeframes: ['09:00-17:00'] + } + tue: { + active: true + timeframes: ['00:00-24:00'] + } + wed: { + active: true + timeframes: ['09:00-17:00'] + } + thu: { + active: true + timeframes: ['09:00-12:00', '13:00-17:00'] + } + fri: { + active: true + timeframes: ['09:00-17:00'] + } + sat: { + active: false + timeframes: ['10:00-14:00'] + } + sun: { + active: false + timeframes: ['10:00-14:00'] + } + } + + businessHours = new App.BusinessHours + hours: hours + + businessHours.render() + businessHours.el \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.js.coffee b/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.js.coffee new file mode 100644 index 000000000..061674eb9 --- /dev/null +++ b/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.js.coffee @@ -0,0 +1,12 @@ +class App.UiElement.holiday_selector + @render: (attribute, params) -> + console.log('aa', attribute) + days = {} + if attribute.value + days = attribute.value + days_sorted = _.keys(days).sort() + days_new = {} + for day in days_sorted + days_new[day] = days[day] + + item = $( App.view('calendar/holiday_selector')( attribute: attribute, days: days_new ) ) \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/_ui_element/ical_feed.js.coffee b/app/assets/javascripts/app/controllers/_ui_element/ical_feed.js.coffee new file mode 100644 index 000000000..dbb16fe80 --- /dev/null +++ b/app/assets/javascripts/app/controllers/_ui_element/ical_feed.js.coffee @@ -0,0 +1,35 @@ +class App.UiElement.ical_feed extends App.UiElement.ApplicationUiElement + @render: (attribute, params) -> + console.log('A', attribute) + item = $( '
' + App.view('generic/input')( attribute: attribute ) + '
' ) + + ical_feeds = App.Config.get('ical_feeds') + + if !_.isEmpty(ical_feeds) + attribute_ical = + options: ical_feeds + tag: 'searchable_select' + placeholder: App.i18n.translateInline('Search public ical feed...') + + # build options list based on config + @getConfigOptionList( attribute_ical ) + + # add null selection if needed + @addNullOption( attribute_ical ) + + # sort attribute.options + @sortOptions( attribute_ical ) + + # finde selected/checked item of list + @selectedOptions( attribute_ical ) + + templateSelections = App.UiElement.searchable_select.render(attribute_ical) + + templateSelections.find('.js-shadow').bind('change', (e) -> + val = $(e.target).val() + if val + item.find("[name=#{attribute.name}]").val(val) + ) + item.append(templateSelections) + + item \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/_ui_element/timezone.js.coffee b/app/assets/javascripts/app/controllers/_ui_element/timezone.js.coffee index d3a22f303..6f5df2b4d 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/timezone.js.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/timezone.js.coffee @@ -1,5 +1,5 @@ class App.UiElement.timezone extends App.UiElement.ApplicationUiElement - @render: (attribute) -> + @render: (attribute, params) -> attribute.options = [] timezones = App.Config.get('timezones') @@ -22,4 +22,6 @@ class App.UiElement.timezone extends App.UiElement.ApplicationUiElement # finde selected/checked item of list @selectedOptions( attribute, params ) - $( App.view('generic/select')( attribute: attribute ) ) + attribute.tag = 'searchable_select' + attribute.placeholder = App.i18n.translateInline('Enter timzone...') + App.UiElement.searchable_select.render(attribute) diff --git a/app/assets/javascripts/app/controllers/calendar.js.coffee b/app/assets/javascripts/app/controllers/calendar.js.coffee index 9dff325ba..84acd5c2b 100644 --- a/app/assets/javascripts/app/controllers/calendar.js.coffee +++ b/app/assets/javascripts/app/controllers/calendar.js.coffee @@ -1,47 +1,33 @@ class Index extends App.ControllerContent events: - 'click .js-new': 'newDialog' + 'click .js-new': 'new' + 'click .js-edit': 'edit' 'click .js-description': 'description' - hours: { - mon: { - active: true - timeframes: ['09:00-17:00'] - } - tue: { - active: true - timeframes: ['00:00-24:00'] - } - wed: { - active: true - timeframes: ['09:00-17:00'] - } - thu: { - active: true - timeframes: ['09:00-12:00', '13:00-17:00'] - } - fri: { - active: true - timeframes: ['09:00-17:00'] - } - sat: { - active: false - timeframes: ['10:00-14:00'] - } - sun: { - active: false - timeframes: ['10:00-14:00'] - } - } - constructor: -> super # check authentication return if !@authenticate() - @subscribeId = App.Calendar.subscribe(@render) - App.Calendar.fetch() + @load() + + load: => + @ajax( + id: 'calendar_index' + type: 'GET' + url: @apiPath + '/calendars' + processData: true + success: (data, status, xhr) => + + App.Config.set('ical_feeds', data.ical_feeds) + App.Config.set('timezones', data.timezones) + + # load assets + App.Collection.loadAssets(data.assets) + + @render(data) + ) render: => calendars = App.Calendar.search( @@ -80,22 +66,31 @@ class Index extends App.ControllerContent if @subscribeId App.Calendar.unsubscribe(@subscribeId) - newDialog: => - @newItemModal = new App.ControllerModal - large: true - head: 'New Calendar' - content: App.view('calendar/new')() - button: 'Create' - shown: true - cancel: true - container: @el.closest('.content') - onShown: => - businessHours = new App.BusinessHours - hours: @hours + new: => + new App.ControllerGenericNew( + pageData: + title: 'Calendars' + object: 'Calendar' + objects: 'Calendars' + genericObject: 'Calendar' + callback: @load + container: @el.closest('.content') + large: true + ) - businessHours.render() - - @el.closest('.content').find('.js-business-hours').html(businessHours.el) + edit: (e) => + id = $(e.target).closest('.action').data('id') + new App.ControllerGenericEdit( + id: id + pageData: + title: 'Calendars' + object: 'Calendar' + objects: 'Calendars' + genericObject: 'Calendar' + callback: @load + container: @el.closest('.content') + large: true + ) description: (e) => new App.ControllerGenericDescription( diff --git a/app/assets/javascripts/app/controllers/sla.js.coffee b/app/assets/javascripts/app/controllers/sla.js.coffee index 663c4f5fe..d0997edc2 100644 --- a/app/assets/javascripts/app/controllers/sla.js.coffee +++ b/app/assets/javascripts/app/controllers/sla.js.coffee @@ -12,7 +12,6 @@ class Index extends App.ControllerContent return if !@authenticate() @load() - #@subscribeId = App.Calendar.subscribe(@render) load: => @ajax( diff --git a/app/assets/javascripts/app/models/calendar.js.coffee b/app/assets/javascripts/app/models/calendar.js.coffee index 759a999e0..9ac906c1c 100644 --- a/app/assets/javascripts/app/models/calendar.js.coffee +++ b/app/assets/javascripts/app/models/calendar.js.coffee @@ -3,6 +3,19 @@ class App.Calendar extends App.Model @extend Spine.Model.Ajax @url: @apiPath + '/calendars' + @configure_attributes = [ + { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false }, + { name: 'timezone', display: 'Timezone', tag: 'timezone', null: false } + { name: 'business_hours', display: 'Business Hours', tag: 'business_hours', null: true } + { name: 'ical_url', display: 'Public Holidays iCal Feed', tag: 'ical_feed', placeholder: 'http://example.com/public_holidays.ical', null: true } + { name: 'public_holidays',display: 'Public Holidays', tag: 'holiday_selector', null: true } + { name: 'note', display: 'Note', tag: 'textarea', limit: 250, null: true }, + { name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 }, + { name: 'created_at', display: 'Created', tag: 'datetime', readonly: 1 }, + { name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 }, + { name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 }, + ] + displayName: -> "#{@name} - #{@timezone}" diff --git a/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco b/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco new file mode 100644 index 000000000..c5b8c56e8 --- /dev/null +++ b/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco @@ -0,0 +1,69 @@ + + + + + + <% for day, meta of @days: %> + class="is-inactive"<% end %>> + + + + +
<%- @T('Active') %> + <%- @T('Date') %> + <%- @T('Description') %> + <%- @T('Action') %> +
+ + <%- @Tdate(day) %> + <%= meta.summary %> + +
+
+ <%- @Icon('trash') %> <%- @T('Remove') %> +
+
+ <% end %> +
+ + <%- @Tdate('2015-12-25') %> + Some Description + +
+
+ <%- @Icon('trash') %> <%- @T('Remove') %> +
+
+
+ + <%- @Tdate('2015-12-26') %> + Some Description + +
+
+ <%- @Icon('trash') %> <%- @T('Remove') %> +
+
+
+ + + + + + +
+ <%- @Icon('plus-small') %> <%- @T('Add') %> +
+
\ No newline at end of file diff --git a/app/assets/javascripts/app/views/calendar/index.jst.eco b/app/assets/javascripts/app/views/calendar/index.jst.eco index a169ad80b..a88209d0a 100644 --- a/app/assets/javascripts/app/views/calendar/index.jst.eco +++ b/app/assets/javascripts/app/views/calendar/index.jst.eco @@ -16,7 +16,7 @@ <% end %> <% for calendar in @calendars: %> -
+

<%- @Icon('status', 'ok inline') %> <%= calendar.name %>

diff --git a/app/assets/javascripts/app/views/calendar/new.jst.eco b/app/assets/javascripts/app/views/calendar/new.jst.eco deleted file mode 100644 index 41fbe2e3c..000000000 --- a/app/assets/javascripts/app/views/calendar/new.jst.eco +++ /dev/null @@ -1,659 +0,0 @@ - -
-
- -
-
- -
-
- -
-
- -
-
- - - -
-
- -
-
- -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- - - - - - - - - - -
<%- @T('Active') %> - <%- @T('Date') %> - <%- @T('Description') %> - <%- @T('Action') %> -
- - <%- @Tdate('2015-12-24') %> - Some Description - -
-
- <%- @Icon('trash') %> <%- @T('Remove') %> -
-
-
- - <%- @Tdate('2015-12-25') %> - Some Description - -
-
- <%- @Icon('trash') %> <%- @T('Remove') %> -
-
-
- - <%- @Tdate('2015-12-26') %> - Some Description - -
-
- <%- @Icon('trash') %> <%- @T('Remove') %> -
-
-
- - - - - - -
- <%- @Icon('plus-small') %> Add Date -
-
-
-
- -
-
- -
-
- -
-
diff --git a/app/assets/javascripts/app/views/generic/ticket_selector.jst.eco b/app/assets/javascripts/app/views/generic/ticket_selector.jst.eco new file mode 100644 index 000000000..edc7adf08 --- /dev/null +++ b/app/assets/javascripts/app/views/generic/ticket_selector.jst.eco @@ -0,0 +1,26 @@ +
+
+
+
+
+ <%- @Icon('arrow-down', 'dropdown-arrow') %> +
+
+
+
+ + <%- @Icon('arrow-down', 'dropdown-arrow') %> +
+
+
+
+
+
+ <%- @Icon('minus') %> +
+
+ <%- @Icon('plus') %> +
+
+
+
\ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a31493ce0..eebf8fbe7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -286,9 +286,6 @@ class ApplicationController < ActionController::Base config[setting.name] = Setting.get(setting.name) } - # get all time zones - config['timezones'] = Calendar.timezones - # remember if we can to swich back to user if session[:switched_from_user_id] config['switch_back_to_possible'] = true diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index e62d497ea..a342ead44 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -5,7 +5,24 @@ class CalendarsController < ApplicationController def index return if deny_if_not_role(Z_ROLENAME_ADMIN) - model_index_render(Calendar, params) + + assets = {} + + # calendars + calendar_ids = [] + Calendar.all.each {|calendar| + calendar_ids.push calendar.id + assets = calendar.assets(assets) + } + + ical_feeds = Calendar.ical_feeds + timezones = Calendar.timezones + render json: { + calendar_ids: calendar_ids, + ical_feeds: ical_feeds, + timezones: timezones, + assets: assets, + }, status: :ok end def show diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 26f42ade0..925c14a33 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -80,10 +80,11 @@ returns 'US Holidays' => 'en.usa', 'Vietnamese Holidays' => 'en.vietnamese', } + all_feeds = {} gfeeds.each {|key, name| - gfeeds[key] = "http://www.google.com/calendar/ical/#{name}%23holiday%40group.v.calendar.google.com/public/basic.ics" + all_feeds["http://www.google.com/calendar/ical/#{name}%23holiday%40group.v.calendar.google.com/public/basic.ics"] = key } - gfeeds + all_feeds end =begin @@ -189,6 +190,9 @@ returns if !comment.valid_encoding? comment = comment.encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?') end + + # ignore daylight saving time entries + next if comment =~ /(daylight saving|sommerzeit|summertime)/i events[day] = comment } events.sort.to_h