code_manager.js
9 months ago
code_manager_dashboard.js
9 months ago
code_manager_listmode.js
9 months ago
code_manager_message.js
9 months ago
code_manager_tabmode.js
9 months ago
notify.min.js
9 months ago
code_manager_listmode.js
221 lines
| 1 | /** |
| 2 | * JavaScript code to support code activation in list mode |
| 3 | * |
| 4 | * @author Peter Schulz |
| 5 | * @since 1.0.0 |
| 6 | */ |
| 7 | |
| 8 | var href = window.location.href; |
| 9 | var pathname = href.substring(0, href.lastIndexOf('/')) + '/admin-ajax.php'; |
| 10 | |
| 11 | jQuery(function() { |
| 12 | jQuery('#doaction').click(function () { |
| 13 | return cm_action_button(); |
| 14 | }); |
| 15 | |
| 16 | jQuery('#doaction2').click(function () { |
| 17 | return cm_action_button(); |
| 18 | }); |
| 19 | |
| 20 | new ClipboardJS('.c2c'); |
| 21 | |
| 22 | jQuery(function(){ |
| 23 | jQuery('.cm_menu_title').tooltip(); |
| 24 | jQuery('.c2c').tooltip(); |
| 25 | jQuery('.cm_tooltip').tooltip(); |
| 26 | jQuery('#disable_preview').tooltip(); |
| 27 | jQuery('#disable_preview').on('click', function() { |
| 28 | html = "<div>This turns of preview mode for all code IDs for all users. Do you want to continue?</div>"; |
| 29 | var dialog = jQuery(html).dialog({ |
| 30 | dialogClass: 'no-close', |
| 31 | title: 'Reset preview', |
| 32 | buttons: { |
| 33 | 'Yes': function() { |
| 34 | dialog.dialog('destroy'); |
| 35 | reset_preview(); |
| 36 | }, |
| 37 | 'No': function() { |
| 38 | dialog.dialog('destroy'); |
| 39 | }, |
| 40 | 'Cancel': function() { |
| 41 | dialog.dialog('destroy'); |
| 42 | } |
| 43 | } |
| 44 | }); |
| 45 | }); |
| 46 | }); |
| 47 | |
| 48 | code_type_list = '<label for="selected_code_type" style="float:left;font-weight:bold;padding-top:6px;">Show </label>'; |
| 49 | code_type_list += '<select id="selected_code_type" name="selected_code_type" onchange="jQuery(\'#cm_list_table\').submit()">'; |
| 50 | code_type_list += '<option value="*">All</option>'; |
| 51 | if (typeof code_manager_code_groups !== "undefined") { |
| 52 | for (var code_group in code_manager_code_groups) { |
| 53 | code_type_list += '<optgroup label="' + code_group + '">'; |
| 54 | code_manager_code_group = code_manager_code_groups[code_group]; |
| 55 | for (var label in code_manager_code_group) { |
| 56 | if (code_manager_selected_code_type === label) { |
| 57 | selected = ' selected'; |
| 58 | } else { |
| 59 | selected = ''; |
| 60 | } |
| 61 | code_type_list += |
| 62 | '<option value="' + label + '"' + selected + '>' + |
| 63 | code_manager_code_group[label] + |
| 64 | '</option>'; |
| 65 | } |
| 66 | code_type_list += '</optgroup>'; |
| 67 | } |
| 68 | } |
| 69 | code_type_list += '</select>'; |
| 70 | jQuery('#doaction').after('<span style="float:right">' + code_type_list + '</span>'); |
| 71 | jQuery('#doaction').after( |
| 72 | '<span style="float:right">' + |
| 73 | '<a id="disable_preview" href="javascript:void(0)" class="fas fa-eye-slash cm_menu_title" style="line-height: 30px; text-decoration: none" title="Turn of preview mode for all code IDs"></a>' + |
| 74 | '</span>' |
| 75 | ); |
| 76 | }); |
| 77 | |
| 78 | function reset_preview() { |
| 79 | jQuery.ajax({ |
| 80 | type: 'POST', |
| 81 | url: pathname + '?action=code_manager_reset_preview', |
| 82 | data: { |
| 83 | wpnonce: wpnonce, |
| 84 | page: 'code_manager_post' |
| 85 | } |
| 86 | }).done( |
| 87 | function (msg) { |
| 88 | if ( msg === 'OK' ) { |
| 89 | jQuery.notify(msg, 'success'); |
| 90 | |
| 91 | window.location.href = window.location.href; |
| 92 | } else { |
| 93 | jQuery.notify(msg, 'info'); |
| 94 | } |
| 95 | } |
| 96 | ).fail( |
| 97 | function () { |
| 98 | jQuery.notify(msg, 'error'); |
| 99 | } |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | function set_code_preview(id, wpnonce, checked) { |
| 104 | action = checked ? 'code_manager_activate_code_preview' : 'code_manager_deactivate_code_preview'; |
| 105 | mode = checked ? 'on' : 'off'; |
| 106 | jQuery.ajax({ |
| 107 | type: 'POST', |
| 108 | url: pathname + '?action=' + action, |
| 109 | data: { |
| 110 | code_id: id, |
| 111 | wpnonce: wpnonce, |
| 112 | page: 'code_manager_post' |
| 113 | } |
| 114 | }).done( |
| 115 | function (msg) { |
| 116 | if ( msg === 'OK' ) { |
| 117 | jQuery.notify('Preview ' + mode, 'success'); |
| 118 | } else { |
| 119 | jQuery.notify(msg, 'info'); |
| 120 | } |
| 121 | } |
| 122 | ).fail( |
| 123 | function () { |
| 124 | jQuery.notify('The request could not be handled', 'error'); |
| 125 | } |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | function activate_code(id, wpnonce) { |
| 130 | if (jQuery('#code_enabled_' + id).is('select')) { |
| 131 | // Listbox |
| 132 | code_item_value = jQuery('#code_enabled_' + id).val(); |
| 133 | } else { |
| 134 | // Checkbox |
| 135 | code_item_value = jQuery('#code_enabled_' + id).is(':checked') ? '1' : '0'; |
| 136 | } |
| 137 | |
| 138 | jQuery.ajax({ |
| 139 | type: 'POST', |
| 140 | url: pathname + '?action=code_manager_activate_code', |
| 141 | data: { |
| 142 | code_id: id, |
| 143 | code_item_value: code_item_value, |
| 144 | wpnonce: wpnonce, |
| 145 | page: 'code_manager_post' |
| 146 | } |
| 147 | }).done( |
| 148 | function (msg) { |
| 149 | if ( msg.substr(0, 3) === 'UPD' ) { |
| 150 | if (jQuery('#code_enabled_' + id).is("select")) { |
| 151 | switch(jQuery('#code_enabled_' + id).val()) { |
| 152 | case "0": |
| 153 | jQuery.notify('Code disabled', 'success'); |
| 154 | break; |
| 155 | case "1": |
| 156 | jQuery.notify('Code admin enabled', 'success'); |
| 157 | break; |
| 158 | case "2": |
| 159 | jQuery.notify('Code public enabled', 'success'); |
| 160 | break; |
| 161 | case "3": |
| 162 | jQuery.notify('Code both enabled', 'success'); |
| 163 | break; |
| 164 | } |
| 165 | } else { |
| 166 | if (jQuery('#code_enabled_' + id).is(':checked')) { |
| 167 | jQuery.notify('Code enabled', 'success'); |
| 168 | } else { |
| 169 | jQuery.notify('Code disabled', 'success'); |
| 170 | } |
| 171 | } |
| 172 | } else { |
| 173 | jQuery.notify('Settings not saved', 'error'); |
| 174 | } |
| 175 | } |
| 176 | ).fail( |
| 177 | function () { |
| 178 | jQuery.notify('The request could not be handled', 'error'); |
| 179 | } |
| 180 | ); |
| 181 | } |
| 182 | |
| 183 | function cm_show_notice( value ) { |
| 184 | if ('bulk-delete'===value) { |
| 185 | html = "<div>You are about to permanently delete the selected code from your site. This action cannot be undone. 'No' to stop, 'Yes' to delete.</div>"; |
| 186 | var dialog = jQuery(html).dialog({ |
| 187 | dialogClass: 'no-close', |
| 188 | title: 'Delete code?', |
| 189 | modal: true, |
| 190 | buttons: { |
| 191 | 'Yes': function() { |
| 192 | jQuery('#cm_list_table').submit(); |
| 193 | dialog.dialog('destroy'); |
| 194 | }, |
| 195 | 'No': function() { |
| 196 | dialog.dialog('destroy'); |
| 197 | }, |
| 198 | 'Cancel': function() { |
| 199 | dialog.dialog('destroy'); |
| 200 | } |
| 201 | } |
| 202 | }); |
| 203 | event.preventDefault(); |
| 204 | event.stopPropagation(); |
| 205 | return false; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | function cm_action_button() { |
| 210 | action1 = jQuery("#cm_list_table :input[name='action']").val(); |
| 211 | if (action1!=='-1') { |
| 212 | return cm_show_notice(action1); |
| 213 | } |
| 214 | action2 = jQuery("#cm_list_table :input[name='action2']").val(); |
| 215 | if (action2!=='-1') { |
| 216 | return cm_show_notice(action2); |
| 217 | } |
| 218 | jQuery.notify('No bulk action selected', 'info'); |
| 219 | return false; |
| 220 | } |
| 221 |