From a787d66486b68c99b3f80f7dc019b9bdaa523efd Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 10 Nov 2016 16:11:59 +0100 Subject: [PATCH] Improved calendar management. --- .../_ui_element/holiday_selector.coffee | 4 +- .../controllers/_ui_element/ical_feed.coffee | 7 ++-- .../app/controllers/calendar.coffee | 13 ++---- .../javascripts/app/lib/app_post/utils.coffee | 40 +++++++++++++++++++ .../views/calendar/holiday_selector.jst.eco | 2 +- .../holiday_selector_placeholder.jst.eco | 2 +- .../app/views/generic/ical_feed.jst.eco | 2 +- app/models/calendar.rb | 36 +++++++++++------ 8 files changed, 77 insertions(+), 29 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.coffee b/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.coffee index f85efb00f..4df0411cd 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.coffee @@ -59,7 +59,9 @@ class App.UiElement.holiday_selector # check if entry already exists exists = item.find("[data-date=#{date}]").get(0) - return if exists + if exists + alert(App.i18n.translateInline('Aready exists!')) + return # reset form input $(e.target).closest('tr').find('.js-summary').val('') diff --git a/app/assets/javascripts/app/controllers/_ui_element/ical_feed.coffee b/app/assets/javascripts/app/controllers/_ui_element/ical_feed.coffee index 861bc9e99..252b5c7cb 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/ical_feed.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/ical_feed.coffee @@ -2,8 +2,9 @@ class App.UiElement.ical_feed extends App.UiElement.ApplicationUiElement @render: (attribute, params) -> - ical_feeds = App.Config.get('ical_feeds') || {} - item = $( App.view('generic/ical_feed')( attribute: attribute, ical_feeds: ical_feeds ) ) + icalFeeds = App.Config.get('ical_feeds') || {} + icalFeedsSorted = App.Utils.sortByValue(icalFeeds) + item = $( App.view('generic/ical_feed')( attribute: attribute, icalFeeds: icalFeedsSorted ) ) updateCheckList = -> return if item.find('.js-checkList').prop('checked') @@ -25,7 +26,7 @@ class App.UiElement.ical_feed extends App.UiElement.ApplicationUiElement item.find('.js-shadow').val( item.find('.js-list').val() ) # set inital state - if ical_feeds[attribute.value] + if icalFeeds[attribute.value] updateCheckList() else updateCheckManual() diff --git a/app/assets/javascripts/app/controllers/calendar.coffee b/app/assets/javascripts/app/controllers/calendar.coffee index 3e361bc9e..30ab707f2 100644 --- a/app/assets/javascripts/app/controllers/calendar.coffee +++ b/app/assets/javascripts/app/controllers/calendar.coffee @@ -51,7 +51,7 @@ class Index extends App.ControllerSubContent if itemTime < till && itemTime > from if calendar.public_holidays[day] && calendar.public_holidays[day].active public_holidays_preview[day] = calendar.public_holidays[day] - calendar.public_holidays_preview = public_holidays_preview + calendar.public_holidays_preview = App.Utils.sortByKey(public_holidays_preview) # show description button, only if content exists showDescription = false @@ -78,7 +78,6 @@ class Index extends App.ControllerSubContent object: 'Calendar' objects: 'Calendars' genericObject: 'Calendar' - callback: @load container: @el.closest('.content') large: true ) @@ -92,7 +91,6 @@ class Index extends App.ControllerSubContent object: 'Calendar' objects: 'Calendars' genericObject: 'Calendar' - callback: @load container: @el.closest('.content') large: true ) @@ -107,17 +105,12 @@ class Index extends App.ControllerSubContent callback: @load ) - default: (e) => + default: (e) -> e.preventDefault() id = $(e.target).closest('.action').data('id') item = App.Calendar.find(id) item.default = true - item.save( - done: => - @load() - fail: => - @load() - ) + item.save() description: (e) => new App.ControllerGenericDescription( diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 1ce7f98ea..b70204783 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -666,6 +666,46 @@ class App.Utils # check length, remove longer positions "#{result[1]}.#{result[2].substr(0,positions)}" + @sortByValue: (options, order = 'ASC') -> + # sort by name + byNames = [] + byNamesWithValue = {} + for i, value of options + valueTmp = value.toString().toLowerCase() + byNames.push valueTmp + byNamesWithValue[valueTmp] = [i, value] + byNames = byNames.sort() + + # do a reverse, if needed + if order == 'DESC' + byNames = byNames.reverse() + + optionsNew = {} + for i in byNames + ref = byNamesWithValue[i] + optionsNew[ref[0]] = ref[1] + optionsNew + + @sortByKey: (options, order = 'ASC') -> + # sort by name + byKeys = [] + for i, value of options + if i.toString + iTmp = i.toString().toLowerCase() + else + iTmp = i + byKeys.push iTmp + byKeys = byKeys.sort() + + # do a reverse, if needed + if order == 'DESC' + byKeys = byKeys.reverse() + + optionsNew = {} + for i in byKeys + optionsNew[i] = options[i] + optionsNew + @formatTime: (num, digits) -> # input validation diff --git a/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco b/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco index e68b1a976..4ed5a2382 100644 --- a/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco +++ b/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco @@ -25,7 +25,7 @@ <% end %> <% end %> - +