From bc5642fbba7cd44e590e9db21345ed68a30c6550 Mon Sep 17 00:00:00 2001 From: Roger Almeida Date: Mon, 26 Dec 2022 18:14:46 +1100 Subject: [PATCH 1/5] :rocket: Upgrading version from 3.0.0 to 3.0.1-rc1 --- lib/recurring_select/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/recurring_select/version.rb b/lib/recurring_select/version.rb index ae77e4b3..067ea1c8 100644 --- a/lib/recurring_select/version.rb +++ b/lib/recurring_select/version.rb @@ -1,3 +1,3 @@ module RecurringSelect - VERSION = "3.0.0" + VERSION = "3.0.1-rc1" end From 0dbbab8267dddd8464c1c63c8f043ed826f72950 Mon Sep 17 00:00:00 2001 From: Roger Almeida Date: Tue, 27 Dec 2022 13:45:12 +1100 Subject: [PATCH 2/5] :fire: (Rails 7): Converted the coffeescript to javascript ahead of time --- app/assets/javascripts/jquery-mobile-rs.js | 17 + .../javascripts/jquery-mobile-rs.js.coffee | 15 - app/assets/javascripts/recurring_select.js | 116 +++++ .../javascripts/recurring_select.js.coffee | 105 ----- app/assets/javascripts/recurring_select/fr.js | 27 ++ .../javascripts/recurring_select/fr.js.coffee | 24 -- .../recurring_select_dialog.js.coffee.erb | 372 ---------------- .../recurring_select_dialog.js.erb | 400 ++++++++++++++++++ 8 files changed, 560 insertions(+), 516 deletions(-) create mode 100644 app/assets/javascripts/jquery-mobile-rs.js delete mode 100644 app/assets/javascripts/jquery-mobile-rs.js.coffee create mode 100644 app/assets/javascripts/recurring_select.js delete mode 100644 app/assets/javascripts/recurring_select.js.coffee create mode 100644 app/assets/javascripts/recurring_select/fr.js delete mode 100644 app/assets/javascripts/recurring_select/fr.js.coffee delete mode 100644 app/assets/javascripts/recurring_select_dialog.js.coffee.erb create mode 100644 app/assets/javascripts/recurring_select_dialog.js.erb diff --git a/app/assets/javascripts/jquery-mobile-rs.js b/app/assets/javascripts/jquery-mobile-rs.js new file mode 100644 index 00000000..dddbef08 --- /dev/null +++ b/app/assets/javascripts/jquery-mobile-rs.js @@ -0,0 +1,17 @@ +(function() { + $(function() { + $(document).on("recurring_select:cancel recurring_select:save", ".recurring_select", function() { + return $(this).selectmenu('refresh'); + }); + return $(document).on("recurring_select:dialog_opened", ".rs_dialog_holder", function() { + $(this).find("select").attr("data-theme", $('.recurring_select').data("theme")).attr("data-mini", true).selectmenu(); + $(this).find("input[type=text]").textinput(); + return $(this).on("recurring_select:dialog_positioned", ".rs_dialog", function() { + return $(this).css({ + "top": $(window).scrollTop() + "px" + }); + }); + }); + }); + +}).call(this); \ No newline at end of file diff --git a/app/assets/javascripts/jquery-mobile-rs.js.coffee b/app/assets/javascripts/jquery-mobile-rs.js.coffee deleted file mode 100644 index 2ce8b103..00000000 --- a/app/assets/javascripts/jquery-mobile-rs.js.coffee +++ /dev/null @@ -1,15 +0,0 @@ -#= require recurring_select -#= require_self - -$ -> - $(document).on "recurring_select:cancel recurring_select:save", ".recurring_select", -> - $(this).selectmenu('refresh') - - $(document).on "recurring_select:dialog_opened", ".rs_dialog_holder", -> - $(this).find("select").attr("data-theme", $('.recurring_select').data("theme")).attr("data-mini", true).selectmenu() - $(this).find("input[type=text]").textinput() - - $(this).on "recurring_select:dialog_positioned", ".rs_dialog", -> - $(this).css - "top" : $(window).scrollTop()+"px" - diff --git a/app/assets/javascripts/recurring_select.js b/app/assets/javascripts/recurring_select.js new file mode 100644 index 00000000..98435dd1 --- /dev/null +++ b/app/assets/javascripts/recurring_select.js @@ -0,0 +1,116 @@ +(function() { + var $, methods; + + $ = jQuery; + + $(function() { + $(document).on("focus", ".recurring_select", function() { + return $(this).recurring_select('set_initial_values'); + }); + return $(document).on("change", ".recurring_select", function() { + return $(this).recurring_select('changed'); + }); + }); + + methods = { + set_initial_values: function() { + this.data('initial-value-hash', this.val()); + return this.data('initial-value-str', $(this.find("option").get()[this.prop("selectedIndex")]).text()); + }, + changed: function() { + if (this.val() === "custom") { + return methods.open_custom.apply(this); + } else { + return methods.set_initial_values.apply(this); + } + }, + open_custom: function() { + this.data("recurring-select-active", true); + new RecurringSelectDialog(this); + return this.blur(); + }, + save: function(new_rule) { + var new_json_val; + this.find("option[data-custom]").remove(); + new_json_val = JSON.stringify(new_rule.hash); + if ($.inArray(new_json_val, this.find("option").map(function() { + return $(this).val(); + })) === -1) { + methods.insert_option.apply(this, [new_rule.str, new_json_val]); + } + this.val(new_json_val); + methods.set_initial_values.apply(this); + return this.trigger("recurring_select:save"); + }, + current_rule: function() { + return { + str: this.data("initial-value-str"), + hash: $.parseJSON(this.data("initial-value-hash")) + }; + }, + cancel: function() { + this.val(this.data("initial-value-hash")); + this.data("recurring-select-active", false); + return this.trigger("recurring_select:cancel"); + }, + insert_option: function(new_rule_str, new_rule_json) { + var new_option, separator; + separator = this.find("option:disabled"); + if (separator.length === 0) { + separator = this.find("option"); + } + separator = separator.last(); + new_option = $(document.createElement("option")); + new_option.attr("data-custom", true); + if (new_rule_str.substr(new_rule_str.length - 1) !== "*") { + new_rule_str += "*"; + } + new_option.text(new_rule_str); + new_option.val(new_rule_json); + return new_option.insertBefore(separator); + }, + methods: function() { + return methods; + } + }; + + $.fn.recurring_select = function(method) { + if (method in methods) { + return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); + } else { + return $.error("Method " + method + " does not exist on jQuery.recurring_select"); + } + }; + + $.fn.recurring_select.options = { + monthly: { + show_week: [true, true, true, true, false, false] + } + }; + + $.fn.recurring_select.texts = { + locale_iso_code: "en", + repeat: "Repeat", + last_day: "Last Day", + frequency: "Frequency", + daily: "Daily", + weekly: "Weekly", + monthly: "Monthly", + yearly: "Yearly", + every: "Every", + days: "day(s)", + weeks_on: "week(s) on", + months: "month(s)", + years: "year(s)", + day_of_month: "Day of month", + day_of_week: "Day of week", + cancel: "Cancel", + ok: "OK", + summary: "Summary", + first_day_of_week: 0, + days_first_letter: ["S", "M", "T", "W", "T", "F", "S"], + order: ["1st", "2nd", "3rd", "4th", "5th", "Last"], + show_week: [true, true, true, true, false, false] + }; + +}).call(this); \ No newline at end of file diff --git a/app/assets/javascripts/recurring_select.js.coffee b/app/assets/javascripts/recurring_select.js.coffee deleted file mode 100644 index c173d51e..00000000 --- a/app/assets/javascripts/recurring_select.js.coffee +++ /dev/null @@ -1,105 +0,0 @@ -#= require recurring_select_dialog -#= require_self - -$ = jQuery -$ -> - $(document).on "focus", ".recurring_select", -> - $(this).recurring_select('set_initial_values') - - $(document).on "change", ".recurring_select", -> - $(this).recurring_select('changed') - -methods = - set_initial_values: -> - @data 'initial-value-hash', @val() - @data 'initial-value-str', $(@find("option").get()[@.prop("selectedIndex")]).text() - - changed: -> - if @val() == "custom" - methods.open_custom.apply(@) - else - methods.set_initial_values.apply(@) - - open_custom: -> - @data "recurring-select-active", true - new RecurringSelectDialog(@) - @blur() - - save: (new_rule) -> - @find("option[data-custom]").remove() - new_json_val = JSON.stringify(new_rule.hash) - - # TODO: check for matching name, and replace that value if found - - if $.inArray(new_json_val, @find("option").map -> $(@).val()) == -1 - methods.insert_option.apply @, [new_rule.str, new_json_val] - - @val new_json_val - methods.set_initial_values.apply @ - @.trigger "recurring_select:save" - - current_rule: -> - str: @data("initial-value-str") - hash: $.parseJSON(@data("initial-value-hash")) - - cancel: -> - @val @data("initial-value-hash") - @data "recurring-select-active", false - @.trigger "recurring_select:cancel" - - - insert_option: (new_rule_str, new_rule_json) -> - separator = @find("option:disabled") - if separator.length == 0 - separator = @find("option") - separator = separator.last() - - new_option = $(document.createElement("option")) - new_option.attr "data-custom", true - - if new_rule_str.substr(new_rule_str.length - 1) != "*" - new_rule_str+="*" - - new_option.text new_rule_str - new_option.val new_rule_json - new_option.insertBefore separator - - methods: -> - methods - -$.fn.recurring_select = (method) -> - if method of methods - return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ) ); - else - $.error( "Method #{method} does not exist on jQuery.recurring_select" ); - -$.fn.recurring_select.options = { - monthly: { - show_week: [true, true, true, true, false, false] - } -} - -$.fn.recurring_select.texts = { - locale_iso_code: "en" - repeat: "Repeat" - last_day: "Last Day" - frequency: "Frequency" - daily: "Daily" - weekly: "Weekly" - monthly: "Monthly" - yearly: "Yearly" - every: "Every" - days: "day(s)" - weeks_on: "week(s) on" - months: "month(s)" - years: "year(s)" - day_of_month: "Day of month" - day_of_week: "Day of week" - cancel: "Cancel" - ok: "OK" - summary: "Summary" - first_day_of_week: 0 - days_first_letter: ["S", "M", "T", "W", "T", "F", "S" ] - order: ["1st", "2nd", "3rd", "4th", "5th", "Last"] - show_week: [true, true, true, true, false, false] -} diff --git a/app/assets/javascripts/recurring_select/fr.js b/app/assets/javascripts/recurring_select/fr.js new file mode 100644 index 00000000..9cd93777 --- /dev/null +++ b/app/assets/javascripts/recurring_select/fr.js @@ -0,0 +1,27 @@ +(function() { + $.fn.recurring_select.texts = { + locale_iso_code: "fr", + repeat: "Récurrence", + last_day: "Dernier jour", + frequency: "Fréquence", + daily: "Tous les jours", + weekly: "Toutes les semaines", + monthly: "Tous les mois", + yearly: "Tous les ans", + every: "Tous les", + days: "jour(s)", + weeks_on: "semaine(s) le", + months: "mois", + years: "année(s)", + cancel: "Annuler", + day_of_month: "Jour du mois", + day_of_week: "Jour de la semaine", + ok: "OK", + summary: "Résumé", + first_day_of_week: 1, + days_first_letter: ["D", "L", "M", "M", "J", "V", "S"], + order: ["1er", "2ème", "3ème", "4ème", "5ème", "Dernier"], + show_week: [true, true, true, true, false, false] +}; + +}).call(this); \ No newline at end of file diff --git a/app/assets/javascripts/recurring_select/fr.js.coffee b/app/assets/javascripts/recurring_select/fr.js.coffee deleted file mode 100644 index 94804ac4..00000000 --- a/app/assets/javascripts/recurring_select/fr.js.coffee +++ /dev/null @@ -1,24 +0,0 @@ -$.fn.recurring_select.texts = { - locale_iso_code: "fr" - repeat: "Récurrence" - last_day: "Dernier jour" - frequency: "Fréquence" - daily: "Tous les jours" - weekly: "Toutes les semaines" - monthly: "Tous les mois" - yearly: "Tous les ans" - every: "Tous les" - days: "jour(s)" - weeks_on: "semaine(s) le" - months: "mois" - years: "année(s)" - cancel: "Annuler" - day_of_month: "Jour du mois" - day_of_week: "Jour de la semaine" - ok: "OK" - summary: "Résumé" - first_day_of_week: 1 - days_first_letter: ["D", "L", "M", "M", "J", "V", "S" ] - order: ["1er", "2ème", "3ème", "4ème", "5ème", "Dernier"] - show_week: [true, true, true, true, false, false] -} \ No newline at end of file diff --git a/app/assets/javascripts/recurring_select_dialog.js.coffee.erb b/app/assets/javascripts/recurring_select_dialog.js.coffee.erb deleted file mode 100644 index baeccd6a..00000000 --- a/app/assets/javascripts/recurring_select_dialog.js.coffee.erb +++ /dev/null @@ -1,372 +0,0 @@ -window.RecurringSelectDialog = - class RecurringSelectDialog - constructor: (@recurring_selector) -> - @current_rule = @recurring_selector.recurring_select('current_rule') - @initDialogBox() - if not @current_rule.hash? or not @current_rule.hash.rule_type? - @freqChanged() - else - setTimeout @positionDialogVert, 10 # allow initial render - - initDialogBox: -> - $(".rs_dialog_holder").remove() - - open_in = $("body") - open_in = $(".ui-page-active") if $(".ui-page-active").length - open_in.append @template() - @outer_holder = $(".rs_dialog_holder") - @inner_holder = @outer_holder.find ".rs_dialog" - @content = @outer_holder.find ".rs_dialog_content" - @positionDialogVert(true) - @mainEventInit() - @freqInit() - @summaryInit() - @outer_holder.trigger "recurring_select:dialog_opened" - @freq_select.focus() - - positionDialogVert: (initial_positioning) => - window_height = $(window).height() - window_width = $(window).width() - dialog_height = @content.outerHeight() - if dialog_height < 80 - dialog_height = 80 - margin_top = (window_height - dialog_height)/2 - 30 - margin_top = 10 if margin_top < 10 - # if dialog_height > window_height - 20 - # dialog_height = window_height - 20 - - new_style_hash = - "margin-top" : margin_top+"px" - "min-height" : dialog_height+"px" - - if initial_positioning? - @inner_holder.css new_style_hash - @inner_holder.trigger "recurring_select:dialog_positioned" - else - @inner_holder.addClass "animated" - @inner_holder.animate new_style_hash, 200, => - @inner_holder.removeClass "animated" - @content.css {"width": "auto"} - @inner_holder.trigger "recurring_select:dialog_positioned" - - cancel: => - @outer_holder.remove() - @recurring_selector.recurring_select('cancel') - - outerCancel: (event) => - if $(event.target).hasClass("rs_dialog_holder") - @cancel() - - save: => - return if !@current_rule.str? - @outer_holder.remove() - @recurring_selector.recurring_select('save', @current_rule) - -# ========================= Init Methods =============================== - - mainEventInit: -> - # Tap hooks are for jQueryMobile - @outer_holder.on 'click tap', @outerCancel - @content.on 'click tap', 'h1 a', @cancel - @save_button = @content.find('input.rs_save').on "click tap", @save - @content.find('input.rs_cancel').on "click tap", @cancel - - freqInit: -> - @freq_select = @outer_holder.find ".rs_frequency" - if @current_rule.hash? && (rule_type = @current_rule.hash.rule_type)? - if rule_type.search(/Weekly/) != -1 - @freq_select.prop('selectedIndex', 1) - @initWeeklyOptions() - else if rule_type.search(/Monthly/) != -1 - @freq_select.prop('selectedIndex', 2) - @initMonthlyOptions() - else if rule_type.search(/Yearly/) != -1 - @freq_select.prop('selectedIndex', 3) - @initYearlyOptions() - else - @initDailyOptions() - @freq_select.on "change", @freqChanged - - initDailyOptions: -> - section = @content.find('.daily_options') - interval_input = section.find('.rs_daily_interval') - interval_input.val(@current_rule.hash.interval) - interval_input.on "change keyup", @intervalChanged - section.show() - - initWeeklyOptions: -> - section = @content.find('.weekly_options') - - # connect the interval field - interval_input = section.find('.rs_weekly_interval') - interval_input.val(@current_rule.hash.interval) - interval_input.on "change keyup", @intervalChanged - - # clear selected days - section.find(".day_holder a").each (index, element) -> - $(element).removeClass("selected") - - # connect the day fields - if @current_rule.hash.validations? && @current_rule.hash.validations.day? - $(@current_rule.hash.validations.day).each (index, val) -> - section.find(".day_holder a[data-value='"+val+"']").addClass("selected") - - section.off('click', '.day_holder a').on "click", ".day_holder a", @daysChanged - - section.show() - - initMonthlyOptions: -> - section = @content.find('.monthly_options') - interval_input = section.find('.rs_monthly_interval') - interval_input.val(@current_rule.hash.interval) - interval_input.on "change keyup", @intervalChanged - - @current_rule.hash.validations ||= {} - @current_rule.hash.validations.day_of_month ||= [] - @current_rule.hash.validations.day_of_week ||= {} - @init_calendar_days(section) - @init_calendar_weeks(section) - - in_week_mode = Object.keys(@current_rule.hash.validations.day_of_week).length > 0 - section.find(".monthly_rule_type_week").prop("checked", in_week_mode) - section.find(".monthly_rule_type_day").prop("checked", !in_week_mode) - @toggle_month_view() - section.find("input[name=monthly_rule_type]").on "change", @toggle_month_view - section.show() - - initYearlyOptions: -> - section = @content.find('.yearly_options') - interval_input = section.find('.rs_yearly_interval') - interval_input.val(@current_rule.hash.interval) - interval_input.on "change keyup", @intervalChanged - section.show() - - - summaryInit: -> - @summary = @outer_holder.find(".rs_summary") - @summaryUpdate() - -# ========================= render methods =============================== - - summaryUpdate: (new_string) => - @summary.width @content.width() - if @current_rule.hash? && @current_rule.str? - @summary.removeClass "fetching" - @save_button.removeClass("disabled") - rule_str = @current_rule.str.replace("*", "") - if rule_str.length < 20 - rule_str = "#{$.fn.recurring_select.texts["summary"]}: "+rule_str - @summary.find("span").html rule_str - else - @summary.addClass "fetching" - @save_button.addClass("disabled") - @summary.find("span").html "" - @summaryFetch() - - summaryFetch: -> - return if !(@current_rule.hash? && (rule_type = @current_rule.hash.rule_type)?) - @current_rule.hash['week_start'] = $.fn.recurring_select.texts["first_day_of_week"] - $.ajax - url: "<%= Rails.application.config.action_controller.relative_url_root %>/recurring_select/translate/#{$.fn.recurring_select.texts["locale_iso_code"]}", - type: "POST", - data: @current_rule.hash - success: @summaryFetchSuccess - - summaryFetchSuccess: (data) => - @current_rule.str = data - @summaryUpdate() - @content.css {"width": "auto"} - - init_calendar_days: (section) => - monthly_calendar = section.find(".rs_calendar_day") - monthly_calendar.html "" - for num in [1..31] - monthly_calendar.append (day_link = $(document.createElement("a")).text(num)) - if $.inArray(num, @current_rule.hash.validations.day_of_month) != -1 - day_link.addClass("selected") - - # add last day of month button - monthly_calendar.append (end_of_month_link = $(document.createElement("a")).text($.fn.recurring_select.texts["last_day"])) - end_of_month_link.addClass("end_of_month") - if $.inArray(-1, @current_rule.hash.validations.day_of_month) != -1 - end_of_month_link.addClass("selected") - - monthly_calendar.find("a").on "click tap", @dateOfMonthChanged - - init_calendar_weeks: (section) => - monthly_calendar = section.find(".rs_calendar_week") - monthly_calendar.html "" - row_labels = $.fn.recurring_select.texts["order"] - show_row = $.fn.recurring_select.options["monthly"]["show_week"] - cell_str = $.fn.recurring_select.texts["days_first_letter"] - - for num, index in [1, 2, 3, 4, 5, -1] - if show_row[index] - monthly_calendar.append "#{row_labels[num - 1]}" - for day_of_week in [$.fn.recurring_select.texts["first_day_of_week"]...(7 + $.fn.recurring_select.texts["first_day_of_week"])] - day_of_week = day_of_week % 7 - day_link = $("", {text: cell_str[day_of_week] }) - day_link.attr("day", day_of_week) - day_link.attr("instance", num) - monthly_calendar.append day_link - - $.each @current_rule.hash.validations.day_of_week, (key, value) -> - $.each value, (index, instance) -> - section.find("a[day='#{key}'][instance='#{instance}']").addClass("selected") - monthly_calendar.find("a").on "click tap", @weekOfMonthChanged - - toggle_month_view: => - week_mode = @content.find(".monthly_rule_type_week").prop("checked") - @content.find(".rs_calendar_week").toggle(week_mode) - @content.find(".rs_calendar_day").toggle(!week_mode) - -# ========================= Change callbacks =============================== - - freqChanged: => - @current_rule.hash = null unless $.isPlainObject(@current_rule.hash) # for custom values - - @current_rule.hash ||= {} - @current_rule.hash.interval = 1 - @current_rule.hash.until = null - @current_rule.hash.count = null - @current_rule.hash.validations = null - @content.find(".freq_option_section").hide(); - @content.find("input[type=radio], input[type=checkbox]").prop("checked", false) - switch @freq_select.val() - when "Weekly" - @current_rule.hash.rule_type = "IceCube::WeeklyRule" - @current_rule.str = $.fn.recurring_select.texts["weekly"] - @initWeeklyOptions() - when "Monthly" - @current_rule.hash.rule_type = "IceCube::MonthlyRule" - @current_rule.str = $.fn.recurring_select.texts["monthly"] - @initMonthlyOptions() - when "Yearly" - @current_rule.hash.rule_type = "IceCube::YearlyRule" - @current_rule.str = $.fn.recurring_select.texts["yearly"] - @initYearlyOptions() - else - @current_rule.hash.rule_type = "IceCube::DailyRule" - @current_rule.str = $.fn.recurring_select.texts["daily"] - @initDailyOptions() - @summaryUpdate() - @positionDialogVert() - - intervalChanged: (event) => - @current_rule.str = null - @current_rule.hash ||= {} - @current_rule.hash.interval = parseInt($(event.currentTarget).val()) - if @current_rule.hash.interval < 1 || isNaN(@current_rule.hash.interval) - @current_rule.hash.interval = 1 - @summaryUpdate() - - daysChanged: (event) => - $(event.currentTarget).toggleClass("selected") - @current_rule.str = null - @current_rule.hash ||= {} - @current_rule.hash.validations = {} - raw_days = @content.find(".day_holder a.selected").map -> parseInt($(this).data("value")) - @current_rule.hash.validations.day = raw_days.get() - @summaryUpdate() - false # this prevents default and propogation - - dateOfMonthChanged: (event) => - $(event.currentTarget).toggleClass("selected") - @current_rule.str = null - @current_rule.hash ||= {} - @current_rule.hash.validations = {} - raw_days = @content.find(".monthly_options .rs_calendar_day a.selected").map -> - res = if $(this).text() == $.fn.recurring_select.texts["last_day"] then -1 else parseInt($(this).text()) - res - @current_rule.hash.validations.day_of_week = {} - @current_rule.hash.validations.day_of_month = raw_days.get() - @summaryUpdate() - false - - weekOfMonthChanged: (event) => - $(event.currentTarget).toggleClass("selected") - @current_rule.str = null - @current_rule.hash ||= {} - @current_rule.hash.validations = {} - @current_rule.hash.validations.day_of_month = [] - @current_rule.hash.validations.day_of_week = {} - @content.find(".monthly_options .rs_calendar_week a.selected").each (index, elm) => - day = parseInt($(elm).attr("day")) - instance = parseInt($(elm).attr("instance")) - @current_rule.hash.validations.day_of_week[day] ||= [] - @current_rule.hash.validations.day_of_week[day].push instance - @summaryUpdate() - false - -# ========================= Change callbacks =============================== - - template: () -> - str = " -
-
-
-

#{$.fn.recurring_select.texts["repeat"]}

-

- - -

- -
-

- #{$.fn.recurring_select.texts["every"]} - - #{$.fn.recurring_select.texts["days"]} -

-
-
-

- #{$.fn.recurring_select.texts["every"]} - - #{$.fn.recurring_select.texts["weeks_on"]}: -

-
- " - for day_of_week in [$.fn.recurring_select.texts["first_day_of_week"]...(7 + $.fn.recurring_select.texts["first_day_of_week"])] - day_of_week = day_of_week % 7 - str += "#{$.fn.recurring_select.texts["days_first_letter"][day_of_week]}" - - str += " -
- . -
-
-

- #{$.fn.recurring_select.texts["every"]} - - #{$.fn.recurring_select.texts["months"]}: -

-

- - -

-

-

-
-
-

- #{$.fn.recurring_select.texts["every"]} - - #{$.fn.recurring_select.texts["years"]} -

-
-

- -

-
- - -
-
-
-
- " diff --git a/app/assets/javascripts/recurring_select_dialog.js.erb b/app/assets/javascripts/recurring_select_dialog.js.erb new file mode 100644 index 00000000..7476a355 --- /dev/null +++ b/app/assets/javascripts/recurring_select_dialog.js.erb @@ -0,0 +1,400 @@ +(function() { + var RecurringSelectDialog, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + + window.RecurringSelectDialog = RecurringSelectDialog = (function() { + function RecurringSelectDialog(recurring_selector) { + this.recurring_selector = recurring_selector; + this.weekOfMonthChanged = bind(this.weekOfMonthChanged, this); + this.dateOfMonthChanged = bind(this.dateOfMonthChanged, this); + this.daysChanged = bind(this.daysChanged, this); + this.intervalChanged = bind(this.intervalChanged, this); + this.freqChanged = bind(this.freqChanged, this); + this.toggle_month_view = bind(this.toggle_month_view, this); + this.init_calendar_weeks = bind(this.init_calendar_weeks, this); + this.init_calendar_days = bind(this.init_calendar_days, this); + this.summaryFetchSuccess = bind(this.summaryFetchSuccess, this); + this.summaryUpdate = bind(this.summaryUpdate, this); + this.save = bind(this.save, this); + this.outerCancel = bind(this.outerCancel, this); + this.cancel = bind(this.cancel, this); + this.positionDialogVert = bind(this.positionDialogVert, this); + this.current_rule = this.recurring_selector.recurring_select('current_rule'); + this.initDialogBox(); + if ((this.current_rule.hash == null) || (this.current_rule.hash.rule_type == null)) { + this.freqChanged(); + } else { + setTimeout(this.positionDialogVert, 10); + } + } + + RecurringSelectDialog.prototype.initDialogBox = function() { + var open_in; + $(".rs_dialog_holder").remove(); + open_in = $("body"); + if ($(".ui-page-active").length) { + open_in = $(".ui-page-active"); + } + open_in.append(this.template()); + this.outer_holder = $(".rs_dialog_holder"); + this.inner_holder = this.outer_holder.find(".rs_dialog"); + this.content = this.outer_holder.find(".rs_dialog_content"); + this.positionDialogVert(true); + this.mainEventInit(); + this.freqInit(); + this.summaryInit(); + this.outer_holder.trigger("recurring_select:dialog_opened"); + return this.freq_select.focus(); + }; + + RecurringSelectDialog.prototype.positionDialogVert = function(initial_positioning) { + var dialog_height, margin_top, new_style_hash, window_height, window_width; + window_height = $(window).height(); + window_width = $(window).width(); + dialog_height = this.content.outerHeight(); + if (dialog_height < 80) { + dialog_height = 80; + } + margin_top = (window_height - dialog_height) / 2 - 30; + if (margin_top < 10) { + margin_top = 10; + } + new_style_hash = { + "margin-top": margin_top + "px", + "min-height": dialog_height + "px" + }; + if (initial_positioning != null) { + this.inner_holder.css(new_style_hash); + return this.inner_holder.trigger("recurring_select:dialog_positioned"); + } else { + this.inner_holder.addClass("animated"); + return this.inner_holder.animate(new_style_hash, 200, (function(_this) { + return function() { + _this.inner_holder.removeClass("animated"); + _this.content.css({ + "width": "auto" + }); + return _this.inner_holder.trigger("recurring_select:dialog_positioned"); + }; + })(this)); + } + }; + + RecurringSelectDialog.prototype.cancel = function() { + this.outer_holder.remove(); + return this.recurring_selector.recurring_select('cancel'); + }; + + RecurringSelectDialog.prototype.outerCancel = function(event) { + if ($(event.target).hasClass("rs_dialog_holder")) { + return this.cancel(); + } + }; + + RecurringSelectDialog.prototype.save = function() { + if (this.current_rule.str == null) { + return; + } + this.outer_holder.remove(); + return this.recurring_selector.recurring_select('save', this.current_rule); + }; + + RecurringSelectDialog.prototype.mainEventInit = function() { + this.outer_holder.on('click tap', this.outerCancel); + this.content.on('click tap', 'h1 a', this.cancel); + this.save_button = this.content.find('input.rs_save').on("click tap", this.save); + return this.content.find('input.rs_cancel').on("click tap", this.cancel); + }; + + RecurringSelectDialog.prototype.freqInit = function() { + var rule_type; + this.freq_select = this.outer_holder.find(".rs_frequency"); + if ((this.current_rule.hash != null) && ((rule_type = this.current_rule.hash.rule_type) != null)) { + if (rule_type.search(/Weekly/) !== -1) { + this.freq_select.prop('selectedIndex', 1); + this.initWeeklyOptions(); + } else if (rule_type.search(/Monthly/) !== -1) { + this.freq_select.prop('selectedIndex', 2); + this.initMonthlyOptions(); + } else if (rule_type.search(/Yearly/) !== -1) { + this.freq_select.prop('selectedIndex', 3); + this.initYearlyOptions(); + } else { + this.initDailyOptions(); + } + } + return this.freq_select.on("change", this.freqChanged); + }; + + RecurringSelectDialog.prototype.initDailyOptions = function() { + var interval_input, section; + section = this.content.find('.daily_options'); + interval_input = section.find('.rs_daily_interval'); + interval_input.val(this.current_rule.hash.interval); + interval_input.on("change keyup", this.intervalChanged); + return section.show(); + }; + + RecurringSelectDialog.prototype.initWeeklyOptions = function() { + var interval_input, section; + section = this.content.find('.weekly_options'); + interval_input = section.find('.rs_weekly_interval'); + interval_input.val(this.current_rule.hash.interval); + interval_input.on("change keyup", this.intervalChanged); + section.find(".day_holder a").each(function(index, element) { + return $(element).removeClass("selected"); + }); + if ((this.current_rule.hash.validations != null) && (this.current_rule.hash.validations.day != null)) { + $(this.current_rule.hash.validations.day).each(function(index, val) { + return section.find(".day_holder a[data-value='" + val + "']").addClass("selected"); + }); + } + section.off('click', '.day_holder a').on("click", ".day_holder a", this.daysChanged); + return section.show(); + }; + + RecurringSelectDialog.prototype.initMonthlyOptions = function() { + var base, base1, base2, in_week_mode, interval_input, section; + section = this.content.find('.monthly_options'); + interval_input = section.find('.rs_monthly_interval'); + interval_input.val(this.current_rule.hash.interval); + interval_input.on("change keyup", this.intervalChanged); + (base = this.current_rule.hash).validations || (base.validations = {}); + (base1 = this.current_rule.hash.validations).day_of_month || (base1.day_of_month = []); + (base2 = this.current_rule.hash.validations).day_of_week || (base2.day_of_week = {}); + this.init_calendar_days(section); + this.init_calendar_weeks(section); + in_week_mode = Object.keys(this.current_rule.hash.validations.day_of_week).length > 0; + section.find(".monthly_rule_type_week").prop("checked", in_week_mode); + section.find(".monthly_rule_type_day").prop("checked", !in_week_mode); + this.toggle_month_view(); + section.find("input[name=monthly_rule_type]").on("change", this.toggle_month_view); + return section.show(); + }; + + RecurringSelectDialog.prototype.initYearlyOptions = function() { + var interval_input, section; + section = this.content.find('.yearly_options'); + interval_input = section.find('.rs_yearly_interval'); + interval_input.val(this.current_rule.hash.interval); + interval_input.on("change keyup", this.intervalChanged); + return section.show(); + }; + + RecurringSelectDialog.prototype.summaryInit = function() { + this.summary = this.outer_holder.find(".rs_summary"); + return this.summaryUpdate(); + }; + + RecurringSelectDialog.prototype.summaryUpdate = function(new_string) { + var rule_str; + this.summary.width(this.content.width()); + if ((this.current_rule.hash != null) && (this.current_rule.str != null)) { + this.summary.removeClass("fetching"); + this.save_button.removeClass("disabled"); + rule_str = this.current_rule.str.replace("*", ""); + if (rule_str.length < 20) { + rule_str = ($.fn.recurring_select.texts["summary"] + ": ") + rule_str; + } + return this.summary.find("span").html(rule_str); + } else { + this.summary.addClass("fetching"); + this.save_button.addClass("disabled"); + this.summary.find("span").html(""); + return this.summaryFetch(); + } + }; + + RecurringSelectDialog.prototype.summaryFetch = function() { + var rule_type; + if (!((this.current_rule.hash != null) && ((rule_type = this.current_rule.hash.rule_type) != null))) { + return; + } + this.current_rule.hash['week_start'] = $.fn.recurring_select.texts["first_day_of_week"]; + return $.ajax({ + url: "<%= Rails.application.config.action_controller.relative_url_root %>/recurring_select/translate/" + $.fn.recurring_select.texts["locale_iso_code"], + type: "POST", + data: this.current_rule.hash, + success: this.summaryFetchSuccess + }); + }; + + RecurringSelectDialog.prototype.summaryFetchSuccess = function(data) { + this.current_rule.str = data; + this.summaryUpdate(); + return this.content.css({ + "width": "auto" + }); + }; + + RecurringSelectDialog.prototype.init_calendar_days = function(section) { + var day_link, end_of_month_link, i, monthly_calendar, num; + monthly_calendar = section.find(".rs_calendar_day"); + monthly_calendar.html(""); + for (num = i = 1; i <= 31; num = ++i) { + monthly_calendar.append((day_link = $(document.createElement("a")).text(num))); + if ($.inArray(num, this.current_rule.hash.validations.day_of_month) !== -1) { + day_link.addClass("selected"); + } + } + monthly_calendar.append((end_of_month_link = $(document.createElement("a")).text($.fn.recurring_select.texts["last_day"]))); + end_of_month_link.addClass("end_of_month"); + if ($.inArray(-1, this.current_rule.hash.validations.day_of_month) !== -1) { + end_of_month_link.addClass("selected"); + } + return monthly_calendar.find("a").on("click tap", this.dateOfMonthChanged); + }; + + RecurringSelectDialog.prototype.init_calendar_weeks = function(section) { + var cell_str, day_link, day_of_week, i, index, j, len, monthly_calendar, num, ref, ref1, ref2, row_labels, show_row; + monthly_calendar = section.find(".rs_calendar_week"); + monthly_calendar.html(""); + row_labels = $.fn.recurring_select.texts["order"]; + show_row = $.fn.recurring_select.options["monthly"]["show_week"]; + cell_str = $.fn.recurring_select.texts["days_first_letter"]; + ref = [1, 2, 3, 4, 5, -1]; + for (index = i = 0, len = ref.length; i < len; index = ++i) { + num = ref[index]; + if (show_row[index]) { + monthly_calendar.append("" + row_labels[num - 1] + ""); + for (day_of_week = j = ref1 = $.fn.recurring_select.texts["first_day_of_week"], ref2 = 7 + $.fn.recurring_select.texts["first_day_of_week"]; ref1 <= ref2 ? j < ref2 : j > ref2; day_of_week = ref1 <= ref2 ? ++j : --j) { + day_of_week = day_of_week % 7; + day_link = $("", { + text: cell_str[day_of_week] + }); + day_link.attr("day", day_of_week); + day_link.attr("instance", num); + monthly_calendar.append(day_link); + } + } + } + $.each(this.current_rule.hash.validations.day_of_week, function(key, value) { + return $.each(value, function(index, instance) { + return section.find("a[day='" + key + "'][instance='" + instance + "']").addClass("selected"); + }); + }); + return monthly_calendar.find("a").on("click tap", this.weekOfMonthChanged); + }; + + RecurringSelectDialog.prototype.toggle_month_view = function() { + var week_mode; + week_mode = this.content.find(".monthly_rule_type_week").prop("checked"); + this.content.find(".rs_calendar_week").toggle(week_mode); + return this.content.find(".rs_calendar_day").toggle(!week_mode); + }; + + RecurringSelectDialog.prototype.freqChanged = function() { + var base; + if (!$.isPlainObject(this.current_rule.hash)) { + this.current_rule.hash = null; + } + (base = this.current_rule).hash || (base.hash = {}); + this.current_rule.hash.interval = 1; + this.current_rule.hash.until = null; + this.current_rule.hash.count = null; + this.current_rule.hash.validations = null; + this.content.find(".freq_option_section").hide(); + this.content.find("input[type=radio], input[type=checkbox]").prop("checked", false); + switch (this.freq_select.val()) { + case "Weekly": + this.current_rule.hash.rule_type = "IceCube::WeeklyRule"; + this.current_rule.str = $.fn.recurring_select.texts["weekly"]; + this.initWeeklyOptions(); + break; + case "Monthly": + this.current_rule.hash.rule_type = "IceCube::MonthlyRule"; + this.current_rule.str = $.fn.recurring_select.texts["monthly"]; + this.initMonthlyOptions(); + break; + case "Yearly": + this.current_rule.hash.rule_type = "IceCube::YearlyRule"; + this.current_rule.str = $.fn.recurring_select.texts["yearly"]; + this.initYearlyOptions(); + break; + default: + this.current_rule.hash.rule_type = "IceCube::DailyRule"; + this.current_rule.str = $.fn.recurring_select.texts["daily"]; + this.initDailyOptions(); + } + this.summaryUpdate(); + return this.positionDialogVert(); + }; + + RecurringSelectDialog.prototype.intervalChanged = function(event) { + var base; + this.current_rule.str = null; + (base = this.current_rule).hash || (base.hash = {}); + this.current_rule.hash.interval = parseInt($(event.currentTarget).val()); + if (this.current_rule.hash.interval < 1 || isNaN(this.current_rule.hash.interval)) { + this.current_rule.hash.interval = 1; + } + return this.summaryUpdate(); + }; + + RecurringSelectDialog.prototype.daysChanged = function(event) { + var base, raw_days; + $(event.currentTarget).toggleClass("selected"); + this.current_rule.str = null; + (base = this.current_rule).hash || (base.hash = {}); + this.current_rule.hash.validations = {}; + raw_days = this.content.find(".day_holder a.selected").map(function() { + return parseInt($(this).data("value")); + }); + this.current_rule.hash.validations.day = raw_days.get(); + this.summaryUpdate(); + return false; + }; + + RecurringSelectDialog.prototype.dateOfMonthChanged = function(event) { + var base, raw_days; + $(event.currentTarget).toggleClass("selected"); + this.current_rule.str = null; + (base = this.current_rule).hash || (base.hash = {}); + this.current_rule.hash.validations = {}; + raw_days = this.content.find(".monthly_options .rs_calendar_day a.selected").map(function() { + var res; + res = $(this).text() === $.fn.recurring_select.texts["last_day"] ? -1 : parseInt($(this).text()); + return res; + }); + this.current_rule.hash.validations.day_of_week = {}; + this.current_rule.hash.validations.day_of_month = raw_days.get(); + this.summaryUpdate(); + return false; + }; + + RecurringSelectDialog.prototype.weekOfMonthChanged = function(event) { + var base; + $(event.currentTarget).toggleClass("selected"); + this.current_rule.str = null; + (base = this.current_rule).hash || (base.hash = {}); + this.current_rule.hash.validations = {}; + this.current_rule.hash.validations.day_of_month = []; + this.current_rule.hash.validations.day_of_week = {}; + this.content.find(".monthly_options .rs_calendar_week a.selected").each((function(_this) { + return function(index, elm) { + var base1, day, instance; + day = parseInt($(elm).attr("day")); + instance = parseInt($(elm).attr("instance")); + (base1 = _this.current_rule.hash.validations.day_of_week)[day] || (base1[day] = []); + return _this.current_rule.hash.validations.day_of_week[day].push(instance); + }; + })(this)); + this.summaryUpdate(); + return false; + }; + + RecurringSelectDialog.prototype.template = function() { + var day_of_week, i, ref, ref1, str; + str = "

" + $.fn.recurring_select.texts["repeat"] + "

" + $.fn.recurring_select.texts["every"] + " " + $.fn.recurring_select.texts["days"] + "

" + $.fn.recurring_select.texts["every"] + " " + $.fn.recurring_select.texts["weeks_on"] + ":

"; + for (day_of_week = i = ref = $.fn.recurring_select.texts["first_day_of_week"], ref1 = 7 + $.fn.recurring_select.texts["first_day_of_week"]; ref <= ref1 ? i < ref1 : i > ref1; day_of_week = ref <= ref1 ? ++i : --i) { + day_of_week = day_of_week % 7; + str += "" + $.fn.recurring_select.texts["days_first_letter"][day_of_week] + ""; + } + return str += "
.

" + $.fn.recurring_select.texts["every"] + " " + $.fn.recurring_select.texts["months"] + ":

" + $.fn.recurring_select.texts["every"] + " " + $.fn.recurring_select.texts["years"] + "

"; + }; + + return RecurringSelectDialog; + + })(); + +}).call(this); \ No newline at end of file From 11cc6a33da101299a1757abf3f59a17e66e0fcf2 Mon Sep 17 00:00:00 2001 From: Roger Almeida Date: Tue, 27 Dec 2022 13:46:46 +1100 Subject: [PATCH 3/5] :sparkles: (Rails 7): Upgraded ruby version from 2.5.7 to 3.1.2 and created a Gemfile for Rails 7 --- .ruby-version | 2 +- spec/gemfiles/Gemfile.rails-7.0.x | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 spec/gemfiles/Gemfile.rails-7.0.x diff --git a/.ruby-version b/.ruby-version index 35d16fb1..ef538c28 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.5.7 +3.1.2 diff --git a/spec/gemfiles/Gemfile.rails-7.0.x b/spec/gemfiles/Gemfile.rails-7.0.x new file mode 100644 index 00000000..88701f1c --- /dev/null +++ b/spec/gemfiles/Gemfile.rails-7.0.x @@ -0,0 +1,10 @@ +source "https://rubygems.org" +gemspec :path => "./../.." + +gem 'pg', platform: :ruby + +gem "jquery-rails" + +gem "rails", "~> 7.0" +gem 'webrick' +gem "sass-rails", "~> 6.0" From c897865faa8764121141baed66aa306efffa152a Mon Sep 17 00:00:00 2001 From: Roger Almeida Date: Tue, 27 Dec 2022 13:47:30 +1100 Subject: [PATCH 4/5] :rocket: (Rails 7): Release version 3.0.1-rc2 --- lib/recurring_select/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/recurring_select/version.rb b/lib/recurring_select/version.rb index 067ea1c8..b3e91635 100644 --- a/lib/recurring_select/version.rb +++ b/lib/recurring_select/version.rb @@ -1,3 +1,3 @@ module RecurringSelect - VERSION = "3.0.1-rc1" + VERSION = "3.0.1-rc2" end From 2d46f1bbc760f175dec73217806f179173118cd4 Mon Sep 17 00:00:00 2001 From: Greg Schmit <14255284+gregschmit@users.noreply.github.com> Date: Tue, 22 Aug 2023 22:32:38 -0500 Subject: [PATCH 5/5] Update version.rb --- lib/recurring_select/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/recurring_select/version.rb b/lib/recurring_select/version.rb index b3e91635..9b8de180 100644 --- a/lib/recurring_select/version.rb +++ b/lib/recurring_select/version.rb @@ -1,3 +1,3 @@ module RecurringSelect - VERSION = "3.0.1-rc2" + VERSION = "3.0.1" end