diff options
Diffstat (limited to 'js/PrefHelpers.js')
-rw-r--r-- | js/PrefHelpers.js | 164 |
1 files changed, 92 insertions, 72 deletions
diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index f9cb450e5..dd8fef5c6 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -1,6 +1,6 @@ 'use strict'; -/* global __, dijit, dojo, Tables, xhrPost, Notify, xhrJson */ +/* global __, dijit, dojo, Tables, xhrPost, Notify, xhrJson, App */ const Helpers = { AppPasswords: { @@ -93,7 +93,6 @@ const Helpers = { const dialog = new dijit.Dialog({ id: "profileEditDlg", title: __("Settings Profiles"), - style: "width: 600px", getSelectedProfiles: function () { return Tables.getSelected("pref-profiles-list"); }, @@ -119,22 +118,6 @@ const Helpers = { alert(__("No profiles selected.")); } }, - activateProfile: function () { - const sel_rows = this.getSelectedProfiles(); - - if (sel_rows.length == 1) { - if (confirm(__("Activate selected profile?"))) { - Notify.progress("Loading, please wait..."); - - xhrPost("backend.php", {op: "rpc", method: "setprofile", id: sel_rows.toString()}, () => { - window.location.reload(); - }); - } - - } else { - alert(__("Please choose a profile to activate.")); - } - }, addProfile: function () { if (this.validate()) { Notify.progress("Creating profile...", true); @@ -149,8 +132,19 @@ const Helpers = { } }, execute: function () { - if (this.validate()) { - // + const sel_rows = this.getSelectedProfiles(); + + if (sel_rows.length == 1) { + if (confirm(__("Activate selected profile?"))) { + Notify.progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "rpc", method: "setprofile", id: sel_rows.toString()}, () => { + window.location.reload(); + }); + } + + } else { + alert(__("Please choose a profile to activate.")); } }, href: query @@ -159,33 +153,58 @@ const Helpers = { dialog.show(); }, customizeCSS: function() { - const query = "backend.php?op=pref-prefs&method=customizeCSS"; + xhrJson("backend.php", {op: "pref-prefs", method: "customizeCSS"}, (reply) => { - if (dijit.byId("cssEditDlg")) - dijit.byId("cssEditDlg").destroyRecursive(); + const dialog = new dijit.Dialog({ + title: __("Customize stylesheet"), + apply: function() { + xhrPost("backend.php", this.attr('value'), () => { + new Effect.Appear("css_edit_apply_msg"); + $("user_css_style").innerText = this.attr('value'); + }); + }, + execute: function () { + Notify.progress('Saving data...', true); - const dialog = new dijit.Dialog({ - id: "cssEditDlg", - title: __("Customize stylesheet"), - style: "width: 600px", - apply: function() { - xhrPost("backend.php", this.attr('value'), () => { - new Effect.Appear("css_edit_apply_msg"); - $("user_css_style").innerText = this.attr('value'); - }); - }, - execute: function () { - Notify.progress('Saving data...', true); + xhrPost("backend.php", this.attr('value'), () => { + window.location.reload(); + }); + }, + content: ` + <div class='alert alert-info'> + ${__("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here.")} + </div> + + ${App.FormFields.hidden('op', 'rpc')} + ${App.FormFields.hidden('method', 'setpref')} + ${App.FormFields.hidden('key', 'USER_STYLESHEET')} + + <div id='css_edit_apply_msg' style='display : none'> + <div class='alert alert-warning'> + ${__("User CSS has been applied, you might need to reload the page to see all changes.")} + </div> + </div> + + <textarea class='panel user-css-editor' dojoType='dijit.form.SimpleTextarea' + style='font-size : 12px;' name='value'>${reply.value}</textarea> + + <footer> + <button dojoType='dijit.form.Button' class='alt-success' onclick="App.dialogOf(this).apply()"> + ${__('Apply')} + </button> + <button dojoType='dijit.form.Button' class='alt-primary' type='submit'> + ${__('Save and reload')} + </button> + <button dojoType='dijit.form.Button' onclick="App.dialogOf(this).hide()"> + ${__('Cancel')} + </button> + </footer> + ` + }); - xhrPost("backend.php", this.attr('value'), () => { - window.location.reload(); - }); + dialog.show(); - }, - href: query }); - - dialog.show(); }, confirmReset: function() { if (confirm(__("Reset to defaults?"))) { @@ -220,41 +239,42 @@ const Helpers = { } else { Notify.progress("Importing, please wait...", true); - Element.show("upload_iframe"); - - return true; - } - }, - onImportComplete: function(iframe) { - if (!iframe.contentDocument.body.innerHTML) return false; - - Element.show(iframe); - - Notify.close(); + const xhr = new XMLHttpRequest(); - if (dijit.byId('opmlImportDlg')) - dijit.byId('opmlImportDlg').destroyRecursive(); + xhr.open( 'POST', 'backend.php', true ); + xhr.onload = function () { + Notify.close(); - const content = iframe.contentDocument.body.innerHTML; + const dialog = new dijit.Dialog({ + title: __("OPML Import"), + onCancel: function () { + window.location.reload(); + }, + execute: function () { + window.location.reload(); + }, + content: ` + <div class='alert alert-info'> + ${__("If you have imported labels and/or filters, you might need to reload preferences to see your new data.")} + </div> + <div class='panel panel-scrollable'> + ${xhr.responseText} + </div> + <footer class='text-center'> + <button dojoType='dijit.form.Button' type='submit' class='alt-primary'> + ${__('Close this window')} + </button> + </footer> + ` + }); - const dialog = new dijit.Dialog({ - id: "opmlImportDlg", - title: __("OPML Import"), - style: "width: 600px", - onCancel: function () { - window.location.reload(); - }, - execute: function () { - window.location.reload(); - }, - content: content - }); + dialog.show(); + }; - dojo.connect(dialog, "onShow", function () { - Element.hide(iframe); - }); + xhr.send(new FormData($("opml_import_form"))); - dialog.show(); + return false; + } }, export: function() { console.log("export"); |