| @@ -12,100 +12,100 @@ | ||
| 12 | 12 | }); |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Show / hide fields as per conditional logic |
| 16 | - function conditionallyShowFields() { | |
| 17 | - if ($('.meta-fields').length == 0) { | |
| 18 | - return; | |
| 19 | - } | |
| 16 | + function conditionallyShowFields() { | |
| 17 | + if ($('.meta-fields').length == 0) { | |
| 18 | + return; | |
| 19 | + } | |
| 20 | 20 | |
| 21 | - $('.form-field').each(function() { | |
| 22 | - var thisField = $(this).find(':input'); | |
| 21 | + $('.form-field').each(function() { | |
| 22 | + var thisField = $(this).find(':input'); | |
| 23 | 23 | |
| 24 | - // Conditionally show/hide fields | |
| 25 | - var conditions = $(this).attr('data-conditions') || ''; | |
| 26 | - var conditionsOperator = $(this).attr('data-conditions-operator') || 'OR'; | |
| 27 | - if (conditions !== '') { | |
| 28 | - var fieldElem = $(this); | |
| 29 | - var conditionsArray = JSON.parse(conditions); | |
| 30 | - var fieldConditionResults = []; | |
| 24 | + // Conditionally show/hide fields | |
| 25 | + var conditions = $(this).attr('data-conditions') || ''; | |
| 26 | + var conditionsOperator = $(this).attr('data-conditions-operator') || 'OR'; | |
| 27 | + if (conditions !== '') { | |
| 28 | + var fieldElem = $(this); | |
| 29 | + var conditionsArray = JSON.parse(conditions); | |
| 30 | + var fieldConditionResults = []; | |
| 31 | 31 | |
| 32 | - conditionsArray.forEach(function(condition) { | |
| 33 | - var fieldClass = '.' + condition.field + '_field'; | |
| 34 | - var fieldInput = $(fieldClass + ' :input'); | |
| 35 | - var fieldInputType = fieldInput.prop('type'); | |
| 32 | + conditionsArray.forEach(function(condition) { | |
| 33 | + var fieldClass = '.' + condition.field + '_field'; | |
| 34 | + var fieldInput = $(fieldClass + ' :input'); | |
| 35 | + var fieldInputType = fieldInput.prop('type'); | |
| 36 | 36 | |
| 37 | - // Do not fetch value of hidden fields. | |
| 38 | - if(!$(fieldClass).is(':visible')){ | |
| 39 | - return; | |
| 40 | - } | |
| 37 | + // Do not fetch value of hidden fields. | |
| 38 | + if(!$(fieldClass).is(':visible')){ | |
| 39 | + return; | |
| 40 | + } | |
| 41 | 41 | |
| 42 | - // Get field value | |
| 43 | - var fieldVal = fieldInput.val(); | |
| 42 | + // Get field value | |
| 43 | + var fieldVal = fieldInput.val(); | |
| 44 | 44 | |
| 45 | - // Get field value if it's radio or checkbox | |
| 46 | - if($.inArray(fieldInputType, ['radio', 'checkbox']) !== -1) { | |
| 47 | - fieldVal = $(fieldClass + ' :input:checked').val(); | |
| 48 | - } | |
| 45 | + // Get field value if it's radio or checkbox | |
| 46 | + if($.inArray(fieldInputType, ['radio', 'checkbox']) !== -1) { | |
| 47 | + fieldVal = $(fieldClass + ' :input:checked').val(); | |
| 48 | + } | |
| 49 | 49 | |
| 50 | - var showThis = false; | |
| 51 | - if(condition.operator == '==') { | |
| 52 | - showThis = (fieldVal == condition.value) ? true : false; | |
| 53 | - } | |
| 54 | - else if(condition.operator == '!=') { | |
| 55 | - showThis = (fieldVal != condition.value) ? true : false; | |
| 56 | - } | |
| 50 | + var showThis = false; | |
| 51 | + if(condition.operator == '==') { | |
| 52 | + showThis = (fieldVal == condition.value) ? true : false; | |
| 53 | + } | |
| 54 | + else if(condition.operator == '!=') { | |
| 55 | + showThis = (fieldVal != condition.value) ? true : false; | |
| 56 | + } | |
| 57 | 57 | |
| 58 | - fieldConditionResults.push(showThis); | |
| 59 | - }); | |
| 58 | + fieldConditionResults.push(showThis); | |
| 59 | + }); | |
| 60 | 60 | |
| 61 | - if('OR' == conditionsOperator){ | |
| 62 | - var showField = false; | |
| 63 | - } | |
| 64 | - else if('AND' == conditionsOperator){ | |
| 65 | - var showField = fieldConditionResults[0]; | |
| 66 | - } | |
| 61 | + if('OR' == conditionsOperator){ | |
| 62 | + var showField = false; | |
| 63 | + } | |
| 64 | + else if('AND' == conditionsOperator){ | |
| 65 | + var showField = fieldConditionResults[0]; | |
| 66 | + } | |
| 67 | 67 | |
| 68 | - fieldConditionResults.forEach(function(showThis){ | |
| 69 | - if('OR' == conditionsOperator){ | |
| 70 | - showField = showField || showThis; | |
| 71 | - } | |
| 72 | - else if('AND' == conditionsOperator){ | |
| 73 | - showField = showField && showThis; | |
| 74 | - } | |
| 75 | - }); | |
| 68 | + fieldConditionResults.forEach(function(showThis){ | |
| 69 | + if('OR' == conditionsOperator){ | |
| 70 | + showField = showField || showThis; | |
| 71 | + } | |
| 72 | + else if('AND' == conditionsOperator){ | |
| 73 | + showField = showField && showThis; | |
| 74 | + } | |
| 75 | + }); | |
| 76 | 76 | |
| 77 | - if(showField){ | |
| 78 | - fieldElem.show(); | |
| 79 | - var disabled = fieldElem.find(':input').attr('data-disabled') || 'no'; | |
| 80 | - if('no' == disabled){ | |
| 81 | - fieldElem.find(':input').removeAttr('disabled'); | |
| 82 | - } | |
| 83 | - } | |
| 84 | - else{ | |
| 85 | - fieldElem.hide(); | |
| 86 | - fieldElem.find(':input').attr('disabled', 'disabled'); | |
| 87 | - } | |
| 88 | - } | |
| 77 | + if(showField){ | |
| 78 | + fieldElem.show(); | |
| 79 | + var disabled = fieldElem.find(':input').attr('data-disabled') || 'no'; | |
| 80 | + if('no' == disabled){ | |
| 81 | + fieldElem.find(':input').removeAttr('disabled'); | |
| 82 | + } | |
| 83 | + } | |
| 84 | + else{ | |
| 85 | + fieldElem.hide(); | |
| 86 | + fieldElem.find(':input').attr('disabled', 'disabled'); | |
| 87 | + } | |
| 88 | + } | |
| 89 | 89 | |
| 90 | - // Apply data limit on fields | |
| 91 | - if (thisField.hasClass('force-text-limit')) { | |
| 92 | - var content = thisField.val(); | |
| 93 | - var contentLength = content.length; | |
| 94 | - var limit = thisField.attr('data-limit'); | |
| 95 | - if (contentLength >= limit) { | |
| 96 | - thisField.siblings('label').find('.limit-used').text(limit); | |
| 97 | - thisField.val(content.substr(0, limit)); | |
| 98 | - } else { | |
| 99 | - thisField.siblings('label').find('.limit-used').text(contentLength); | |
| 100 | - } | |
| 101 | - } | |
| 90 | + // Apply data limit on fields | |
| 91 | + if (thisField.hasClass('force-text-limit')) { | |
| 92 | + var content = thisField.val(); | |
| 93 | + var contentLength = content.length; | |
| 94 | + var limit = thisField.attr('data-limit'); | |
| 95 | + if (contentLength >= limit) { | |
| 96 | + thisField.siblings('label').find('.limit-used').text(limit); | |
| 97 | + thisField.val(content.substr(0, limit)); | |
| 98 | + } else { | |
| 99 | + thisField.siblings('label').find('.limit-used').text(contentLength); | |
| 100 | + } | |
| 101 | + } | |
| 102 | 102 | |
| 103 | - }); | |
| 104 | - } | |
| 103 | + }); | |
| 104 | + } | |
| 105 | 105 | |
| 106 | 106 | // Fetch and display trigger fields |
| 107 | - function fetchAndDisplayTriggerFields(){ | |
| 107 | + function fetchAndDisplayTriggerFields(){ | |
| 108 | 108 | const post_id = $('#post_ID').val() || 0; |
| 109 | 109 | const trigger = $('#notifier_trigger').val() || ''; |
| 110 | 110 | |
| 111 | 111 | if('' == trigger) { |
| @@ -131,72 +131,53 @@ | ||
| 131 | 131 | }); |
| 132 | 132 | } |
| 133 | 133 | }); |
| 134 | 134 | |
| 135 | - } | |
| 135 | + } | |
| 136 | 136 | |
| 137 | 137 | // Uploading media to WP using wp.media |
| 138 | - var file_frame; | |
| 139 | - function uploadMediaFile( button, preview_media ) { | |
| 140 | - var button_id = button.attr('id'); | |
| 141 | - var field_id = button_id.replace( '_button', '' ); | |
| 142 | - var preview_id = button_id.replace( '_button', '_preview' ); | |
| 138 | + var file_frame; | |
| 139 | + function uploadMediaFile( button, preview_media ) { | |
| 140 | + var button_id = button.attr('id'); | |
| 141 | + var field_id = button_id.replace( '_button', '' ); | |
| 142 | + var preview_id = button_id.replace( '_button', '_preview' ); | |
| 143 | 143 | |
| 144 | - // Create the media frame. | |
| 145 | - file_frame = wp.media.frames.file_frame = wp.media({ | |
| 146 | - title: button.data( 'uploader_title' ), | |
| 147 | - button: { | |
| 148 | - text: button.data( 'uploader_button_text' ), | |
| 149 | - }, | |
| 150 | - library: { | |
| 151 | - type: button.data( 'uploader_supported_file_types' ).split(',') | |
| 152 | - }, | |
| 153 | - multiple: false | |
| 154 | - }); | |
| 144 | + // Create the media frame. | |
| 145 | + file_frame = wp.media.frames.file_frame = wp.media({ | |
| 146 | + title: button.data( 'uploader_title' ), | |
| 147 | + button: { | |
| 148 | + text: button.data( 'uploader_button_text' ), | |
| 149 | + }, | |
| 150 | + library: { | |
| 151 | + type: button.data( 'uploader_supported_file_types' ).split(',') | |
| 152 | + }, | |
| 153 | + multiple: false | |
| 154 | + }); | |
| 155 | 155 | |
| 156 | - // When an image is selected, run a callback. | |
| 157 | - file_frame.on( 'select', function() { | |
| 158 | - attachment = file_frame.state().get('selection').first().toJSON(); | |
| 159 | - jQuery("#"+field_id).attr('data-type', attachment.type); | |
| 160 | - jQuery("#"+field_id).attr('data-subtype', attachment.subtype); | |
| 161 | - jQuery("#"+field_id).siblings('.notifier-media-preview').find('.notifier-media-preview-item').addClass('hide'); | |
| 162 | - if( preview_media ) { | |
| 163 | - if('image' == attachment.type || ('application' == attachment.type && 'pdf' == attachment.subtype) ) { | |
| 156 | + // When an image is selected, run a callback. | |
| 157 | + file_frame.on( 'select', function() { | |
| 158 | + attachment = file_frame.state().get('selection').first().toJSON(); | |
| 159 | + jQuery("#"+field_id).attr('data-type', attachment.type); | |
| 160 | + jQuery("#"+field_id).attr('data-subtype', attachment.subtype); | |
| 161 | + jQuery("#"+field_id).siblings('.notifier-media-preview').find('.notifier-media-preview-item').addClass('hide'); | |
| 162 | + if( preview_media ) { | |
| 163 | + if('image' == attachment.type || ('application' == attachment.type && 'pdf' == attachment.subtype) ) { | |
| 164 | 164 | jQuery("#"+field_id).attr('data-url', attachment.sizes.full.url); |
| 165 | 165 | jQuery("#"+preview_id+'_image').removeClass('hide').attr('src', attachment.sizes.thumbnail.url); |
| 166 | - } | |
| 167 | - else if ('video' == attachment.type) { | |
| 168 | - jQuery("#"+field_id).attr('data-url', attachment.url); | |
| 169 | - jQuery("#"+preview_id+'_video').removeClass('hide').find('source').attr('src', attachment.url); | |
| 170 | - jQuery("#"+preview_id+'_video')[0].load(); | |
| 171 | - } | |
| 172 | - } | |
| 173 | - jQuery("#"+field_id).val(attachment.id).change(); | |
| 174 | - }); | |
| 166 | + } | |
| 167 | + else if ('video' == attachment.type) { | |
| 168 | + jQuery("#"+field_id).attr('data-url', attachment.url); | |
| 169 | + jQuery("#"+preview_id+'_video').removeClass('hide').find('source').attr('src', attachment.url); | |
| 170 | + jQuery("#"+preview_id+'_video')[0].load(); | |
| 171 | + } | |
| 172 | + } | |
| 173 | + jQuery("#"+field_id).val(attachment.id).change(); | |
| 174 | + }); | |
| 175 | 175 | |
| 176 | - // Finally, open the modal | |
| 177 | - file_frame.open(); | |
| 178 | - } | |
| 176 | + // Finally, open the modal | |
| 177 | + file_frame.open(); | |
| 178 | + } | |
| 179 | 179 | |
| 180 | - // Fetch activity logs on Tools page | |
| 181 | - function fetchActivityLogs(){ | |
| 182 | - $('.activity-log-preview-wrap').html(''); | |
| 183 | - var currenEle = $('#notifier_activity_date'); | |
| 184 | - if(currenEle.val() === ''){ | |
| 185 | - return false; | |
| 186 | - } | |
| 187 | - currenEle.addClass('disabled-field'); | |
| 188 | - data = { | |
| 189 | - 'action': 'fetch_activity_logs_by_date', | |
| 190 | - 'notifier_activity_date': currenEle.val(), | |
| 191 | - } | |
| 192 | - | |
| 193 | - notifierAjax(data, function(response){ | |
| 194 | - currenEle.removeClass('disabled-field'); | |
| 195 | - $('.activity-log-preview-wrap').html(response.preview); | |
| 196 | - }); | |
| 197 | - } | |
| 198 | - | |
| 199 | 180 | $(document).on('ready', function() { |
| 200 | 181 | |
| 201 | 182 | /***************** |
| 202 | 183 | * Dashboard page |
| @@ -314,9 +295,9 @@ | ||
| 314 | 295 | } |
| 315 | 296 | notifierAjax(data, function(response){}); |
| 316 | 297 | }); |
| 317 | 298 | |
| 318 | - // Do stuff if on the trigger edit page | |
| 299 | + // Do stuff if on the trigger edit page | |
| 319 | 300 | if ($('#notifier-trigger-data').length > 0) { |
| 320 | 301 | fetchAndDisplayTriggerFields(); // Fetch and display data and recipient fields |
| 321 | 302 | $('#notifier-trigger-data :input').on('change keyup', function(){ |
| 322 | 303 | if('notifier_trigger' == $(this).attr('name')){ |
| @@ -336,19 +317,8 @@ | ||
| 336 | 317 | $(document).on('click', '.notifier-unselect-all-checkboxes', function(e){ |
| 337 | 318 | e.preventDefault(); |
| 338 | 319 | $(this).closest('.trigger-fields-wrap').find('option').prop('selected', false); |
| 339 | 320 | $(this).closest('.trigger-fields-wrap').find('select').trigger('change'); |
| 340 | - }); | |
| 341 | - | |
| 342 | - /***************** | |
| 343 | - * Tools page | |
| 344 | - ****************/ | |
| 345 | - if($('#notifier_activity_date').length > 0){ | |
| 346 | - fetchActivityLogs(); | |
| 347 | - } | |
| 348 | - | |
| 349 | - $(document).on('change', '#notifier_activity_date', function(){ | |
| 350 | - fetchActivityLogs(); | |
| 351 | 321 | }); |
| 352 | 322 | |
| 353 | 323 | }); |
| 354 | 324 | |