From 8719c4350ec414800f4ee4e95bb6c16e052e2c5c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 25 Sep 2015 11:47:06 +0200 Subject: [PATCH] Moved placeholder into separate template file. --- .../_ui_element/holiday_selector.js.coffee | 22 ++--- .../views/calendar/holiday_selector.jst.eco | 98 ++++++++----------- .../holiday_selector_placeholder.jst.eco | 15 +++ 3 files changed, 67 insertions(+), 68 deletions(-) create mode 100644 app/assets/javascripts/app/views/calendar/holiday_selector_placeholder.jst.eco 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 index 6c85538eb..cd278bfa9 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.js.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/holiday_selector.js.coffee @@ -20,10 +20,10 @@ class App.UiElement.holiday_selector item.find('.js-datePicker').html(datePicker) # set active/inactive of date - item.find('.js-active').bind('click', (e) -> + item.delegate('.js-active', 'click', (e) -> active = $(e.target).prop('checked') row = $(e.target).closest('tr') - input = $(e.target).closest('tr').find('.js-description') + input = $(e.target).closest('tr').find('.js-summary') if !active row.addClass('is-inactive') input.prop('readonly', true) @@ -35,7 +35,7 @@ class App.UiElement.holiday_selector ) # remove date - item.find('.js-remove').bind('click', (e) -> + item.delegate('.js-remove', 'click', (e) -> $(e.target).closest('tr').remove() ) @@ -61,14 +61,14 @@ class App.UiElement.holiday_selector $(e.target).closest('tr').find('.js-summary').val('') # place new element - template = item.find('.js-placeholder').clone() - template.removeClass('hidden').removeClass('js-placeholder') - template.attr('data-date', date) - template.find('.js-date').html(App.i18n.translateDate(date)) - template.find('.js-active').attr('name', "{boolean}public_holidays::#{date}::active") - template.find('.js-summary').attr('name', "public_holidays::#{date}::summary") - template.find('.js-summary').val(summary) - item.find('.js-placeholder').before(template) + + template = App.view('calendar/holiday_selector_placeholder')( + placeholderDate: date + placeholderSummary: summary + nameSummary: "public_holidays::#{date}::summary" + nameActive: "{boolean}public_holidays::#{date}::active" + ) + item.find('.settings-list-controlRow').before(template) ) item 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 424c505ad..24f6b12b0 100644 --- a/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco +++ b/app/assets/javascripts/app/views/calendar/holiday_selector.jst.eco @@ -1,59 +1,43 @@ - - - - - - <% for day, meta of @days: %> - class="is-inactive"<% end %> data-date="<%= day %>"> - + +
<%- @T('Active') %> - <%- @T('Date') %> - <%- @T('Description') %> - <%- @T('Action') %> -
- - <%- @Tdate(day) %> - - -
- <% if !meta.feed: %> -
- <%- @Icon('trash') %> <%- @T('Remove') %> -
- <% end %> + + + + + + <% for day, meta of @days: %> + class="is-inactive"<% end %> data-date="<%= day %>"> + - - -
<%- @T('Active') %> + <%- @T('Date') %> + <%- @T('Description') %> + <%- @T('Action') %> +
+ + <%- @Tdate(day) %> + + +
+ <% if !meta.feed: %> +
+ <%- @Icon('trash') %> <%- @T('Remove') %>
- <% end %> + <% end %> +
+ <% end %> -
- - - - - -
- <%- @Icon('plus-small') %> <%- @T('Add') %> -
-
\ No newline at end of file +
+ + + + + +
+ <%- @Icon('plus-small') %> <%- @T('Add') %> +
+
\ No newline at end of file diff --git a/app/assets/javascripts/app/views/calendar/holiday_selector_placeholder.jst.eco b/app/assets/javascripts/app/views/calendar/holiday_selector_placeholder.jst.eco new file mode 100644 index 000000000..eddce6e5f --- /dev/null +++ b/app/assets/javascripts/app/views/calendar/holiday_selector_placeholder.jst.eco @@ -0,0 +1,15 @@ + + + + <%- @Tdate(@placeholderDate) %> + + +
+
+ <%- @Icon('trash') %> <%- @T('Remove') %> +
+
\ No newline at end of file