Skip to content

Commit

Permalink
decaffeinate js
Browse files Browse the repository at this point in the history
  • Loading branch information
glaszig committed Sep 2, 2023
1 parent 9987a46 commit ab263ea
Show file tree
Hide file tree
Showing 7 changed files with 592 additions and 492 deletions.
18 changes: 18 additions & 0 deletions app/assets/javascripts/jquery-mobile-rs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//= require recurring_select
//= require_self

$(function() {
$(document).on("recurring_select:cancel recurring_select:save", ".recurring_select", function() {
$(this).selectmenu('refresh');
});

$(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();

$(this).on("recurring_select:dialog_positioned", ".rs_dialog", function() {
$(this).css({
"top" : $(window).scrollTop()+"px"});
});
});
});
15 changes: 0 additions & 15 deletions app/assets/javascripts/jquery-mobile-rs.js.coffee

This file was deleted.

125 changes: 125 additions & 0 deletions app/assets/javascripts/recurring_select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//= require recurring_select_dialog
//= require_self

const $ = jQuery;
$(function() {
$(document).on("focus", ".recurring_select", function() {
$(this).recurring_select('set_initial_values');
});

$(document).on("change", ".recurring_select", function() {
$(this).recurring_select('changed');
});
});

const methods = {
set_initial_values() {
this.data('initial-value-hash', this.val());
this.data('initial-value-str', $(this.find("option").get()[this.prop("selectedIndex")]).text());
},

changed() {
if (this.val() === "custom") {
methods.open_custom.apply(this);
} else {
methods.set_initial_values.apply(this);
}
},

open_custom() {
this.data("recurring-select-active", true);
new RecurringSelectDialog(this);
this.blur();
},

save(new_rule) {
this.find("option[data-custom]").remove();
const new_json_val = JSON.stringify(new_rule.hash);

// TODO: check for matching name, and replace that value if found

if ($.inArray(new_json_val, this.find("option").map(function() { $(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);
this.trigger("recurring_select:save");
},

current_rule() {
return {
str: this.data("initial-value-str"),
hash: $.parseJSON(this.data("initial-value-hash"))
};
},

cancel() {
this.val(this.data("initial-value-hash"));
this.data("recurring-select-active", false);
this.trigger("recurring_select:cancel");
},


insert_option(new_rule_str, new_rule_json) {
let separator = this.find("option:disabled");
if (separator.length === 0) {
separator = this.find("option");
}
separator = separator.last();

const 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() {
return methods;
}
};

$.fn.recurring_select = function(method) {
if (method in 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]
};
105 changes: 0 additions & 105 deletions app/assets/javascripts/recurring_select.js.coffee

This file was deleted.

Loading

0 comments on commit ab263ea

Please sign in to comment.