diff options
-rw-r--r-- | classes/pref/prefs.php | 37 | ||||
-rw-r--r-- | include/functions.php | 20 | ||||
-rw-r--r-- | js/PrefHelpers.js | 27 |
3 files changed, 71 insertions, 13 deletions
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 1eaa99345..cb666e945 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -1338,6 +1338,35 @@ class Pref_Prefs extends Handler_Protected { } } + function cloneprofile() { + $old_profile = $_REQUEST["old_profile"] ?? 0; + $new_title = clean($_REQUEST["new_title"]); + + if ($old_profile && $new_title) { + $new_profile = ORM::for_table('ttrss_settings_profiles')->create(); + $new_profile->title = $new_title; + $new_profile->owner_uid = $_SESSION['uid']; + + if ($new_profile->save()) { + $sth = $this->pdo->prepare("INSERT INTO ttrss_user_prefs + (owner_uid, pref_name, profile, value) + SELECT + :uid, + pref_name, + :new_profile, + value + FROM ttrss_user_prefs + WHERE owner_uid = :uid AND profile = :old_profile"); + + $sth->execute([ + "uid" => $_SESSION["uid"], + "new_profile" => $new_profile->id, + "old_profile" => $old_profile, + ]); + } + } + } + function remprofiles() { $ids = $_REQUEST["ids"] ?? []; @@ -1394,11 +1423,19 @@ class Pref_Prefs extends Handler_Protected { array_push($rv, ["title" => __("Default profile"), "id" => 0, + "initialized" => true, "active" => empty($_SESSION["profile"]) ]); foreach ($profiles as $profile) { $profile['active'] = ($_SESSION["profile"] ?? 0) == $profile->id; + + $num_settings = ORM::for_table('ttrss_user_prefs') + ->where('profile', $profile->id) + ->count(); + + $profile['initialized'] = $num_settings > 0; + array_push($rv, $profile->as_array()); }; diff --git a/include/functions.php b/include/functions.php index 694b8f398..922d3765c 100644 --- a/include/functions.php +++ b/include/functions.php @@ -162,17 +162,17 @@ /* compat shims */ - /** function is @deprecated */ + /** function is @deprecated by Config::get_version() */ function get_version() { return Config::get_version(); } - /** function is @deprecated */ + /** function is @deprecated by Config::get_schema_version() */ function get_schema_version() { return Config::get_schema_version(); } - /** function is @deprecated */ + /** function is @deprecated by Debug::log() */ function _debug($msg) { Debug::log($msg); } @@ -182,37 +182,37 @@ return Feeds::_get_counters($feed, $is_cat, true, $_SESSION["uid"]); } - /** function is @deprecated */ + /** function is @deprecated by Sanitizer::sanitize() */ function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) { return Sanitizer::sanitize($str, $force_remove_images, $owner, $site_url, $highlight_words, $article_id); } - /** function is @deprecated */ + /** function is @deprecated by UrlHelper::fetch() */ function fetch_file_contents($params) { return UrlHelper::fetch($params); } - /** function is @deprecated */ + /** function is @deprecated by UrlHelper::rewrite_relative() */ function rewrite_relative_url($base_url, $rel_url) { return UrlHelper::rewrite_relative($base_url, $rel_url); } - /** function is @deprecated */ + /** function is @deprecated by UrlHelper::validate() */ function validate_url($url) { return UrlHelper::validate($url); } - /** function is @deprecated */ + /** function is @deprecated by UserHelper::authenticate() */ function authenticate_user($login, $password, $check_only = false, $service = false) { return UserHelper::authenticate($login, $password, $check_only, $service); } - /** function is @deprecated */ + /** function is @deprecated by TimeHelper::smart_date_time() */ function smart_date_time($timestamp, $tz_offset = 0, $owner_uid = false, $eta_min = false) { return TimeHelper::smart_date_time($timestamp, $tz_offset, $owner_uid, $eta_min); } - /** function is @deprecated */ + /** function is @deprecated by TimeHelper::make_local_datetime() */ function make_local_datetime($timestamp, $long, $owner_uid = false, $no_smart_dt = false, $eta_min = false) { return TimeHelper::make_local_datetime($timestamp, $long, $owner_uid, $no_smart_dt, $eta_min); } diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index 361b653b6..30a4544fe 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -128,6 +128,24 @@ const Helpers = { getSelectedProfiles: function () { return Tables.getSelected("pref-profiles-list"); }, + cloneSelected: function() { + const sel_rows = this.getSelectedProfiles(); + + if (sel_rows.length == 1) { + const new_title = prompt(__("Name for cloned profile:")); + + if (new_title) { + xhr.post("backend.php", {op: "pref-prefs", method: "cloneprofile", "new_title": new_title, "old_profile": sel_rows[0]}, () => { + Notify.close(); + dialog.refresh(); + }); + } + + } else { + alert(__("Please select a single profile to clone.")); + } + + }, removeSelected: function () { const sel_rows = this.getSelectedProfiles(); @@ -174,7 +192,7 @@ const Helpers = { <div class="pull-right"> <input name='newprofile' dojoType='dijit.form.ValidationTextBox' required='1'> - ${App.FormFields.button_tag(__('Create profile'), "", {onclick: 'App.dialogOf(this).addProfile()'})} + ${App.FormFields.button_tag(App.FormFields.icon("add_circle") + " " + __('Add'), "", {onclick: 'App.dialogOf(this).addProfile()'})} </div> </div> @@ -198,6 +216,7 @@ const Helpers = { </script> </span>` : `${profile.title}`} ${profile.active ? __("(active)") : ""} + ${profile.initialized ? "" : __("(empty)")} </td> </tr> `).join("")} @@ -205,9 +224,11 @@ const Helpers = { </div> <footer> - ${App.FormFields.button_tag(App.FormFields.icon("delete") + " " +__('Remove selected profiles'), "", + ${App.FormFields.button_tag(App.FormFields.icon("delete") + " " +__('Remove selected'), "", {class: 'pull-left alt-danger', onclick: 'App.dialogOf(this).removeSelected()'})} - ${App.FormFields.submit_tag(App.FormFields.icon("check") + " " + __('Activate profile'), {onclick: 'App.dialogOf(this).execute()'})} + ${App.FormFields.button_tag(App.FormFields.icon("content_copy") + " " + __('Clone'), "", + {class: '', onclick: 'App.dialogOf(this).cloneSelected()'})} + ${App.FormFields.submit_tag(App.FormFields.icon("check") + " " + __('Activate'), {onclick: 'App.dialogOf(this).execute()'})} ${App.FormFields.cancel_dialog_tag(__('Cancel'))} </footer> </form> |