| 1 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  * Asynchronously save all settings in the current settings page to the database. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Shows an error notification if errors occur. Shows a success notification | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * otherwise. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @param {Function} done | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | Amarkal.settings.save = function( done )  | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     Amarkal.settings._postData('save',function(res){ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |         Amarkal.settings._clearNotices(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         if(!$.isEmptyObject(res.errors)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |             for(var name in res.errors) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |                 var $comp = $('[amarkal-component-name="'+name+'"]'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |                     instance = $comp.amarkalUIComponent('instance'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |                  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |                 $comp.amarkalUIComponent('makeInvalid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |                 $comp.parent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |                      .children('.amarkal-settings-error') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |                      .addClass('amarkal-visible') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |                      .html(res.errors[name]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             Amarkal.settings.notifier.error('Some errors have occured, see below for more information.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             Amarkal.settings.sections.flag('error', instance.props.section); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             Amarkal.settings.notifier.success('Settings saved', 3000); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         done(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  * Asynchronously reset all settings in the current settings page to their  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  * default values and erase all data from the database. Shows a success  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  * notification upon completion. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  * @param {Function} done | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | Amarkal.settings.resetAll = function( done )  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     Amarkal.settings._postData('reset_all',function(res){ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         Amarkal.settings._clearNotices(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         Amarkal.settings.notifier.success('Default settings applied', 3000); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         done(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  * Asynchronously reset all settings in the current settings section to their  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  * default values and erase all section data from the database. Shows a success  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  * notification upon completion. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  * @param {Function} done | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | Amarkal.settings.resetSection = function( done )  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     Amarkal.settings._postData('reset_section',function(res){ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         Amarkal.settings._clearNotices(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         Amarkal.settings.notifier.success('Default settings applied for the section <strong>'+Amarkal.settings.sections.getTitle(Amarkal.settings.sections.activeSection)+'</strong>', 3000); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $('#amarkal-settings-form').amarkalUIForm('setData', res.values, res.errors); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         done(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  * Reset all components and clear errors | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 78 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  | Amarkal.settings._clearNotices = function() | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     // Reset all components | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     $('.amarkal-ui-component').amarkalUIComponent('reset'); | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |     $('.amarkal-settings-error').removeClass('amarkal-visible').html(''); | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     Amarkal.settings.sections.unflagAll(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  * Send serialized form data to be processed in the backend by the function given | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  * in the 'action' variable. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  * @param {string} action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  * @param {Function} done | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | Amarkal.settings._postData = function( action, done ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     var data = $('#amarkal-settings-form').amarkalUIForm('getData'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     $('#amarkal-settings-form').find('input[name^="_amarkal"]').each(function(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         data[$(this).attr('name')] = $(this).val(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     // Set the active section (if applicable) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     data['_amarkal_settings_section'] = Amarkal.settings.sections.activeSection; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     $.post(ajaxurl, { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         action: 'amarkal_settings_'+action, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         data: data | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 107 |  |  |     }, done); | 
            
                                                        
            
                                    
            
            
                | 108 |  |  | }; | 
            
                        
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.