]> source.dussan.org Git - rspamd.git/commitdiff
Refactores code and added order of actions
authorfiredranzer <rupeshharode@gmail.com>
Tue, 6 Mar 2018 20:43:09 +0000 (02:13 +0530)
committerfiredranzer <rupeshharode@gmail.com>
Tue, 6 Mar 2018 20:43:09 +0000 (02:13 +0530)
interface/js/app/config.js

index 3af4005d08a095460326bd86170faddeda48661f..ec36dce489f9b7c9911993956faeedba8f39806a 100644 (file)
@@ -215,51 +215,35 @@ function($) {
                     $('#actionsFormField').attr('disabled', true);
                 }
 
-                $('#saveActionsClusterBtn').on('click', function() {
+                function saveActions(callback) {
                     var elts = loadActionsFromForm();
                     // String to array for comparison
                     var eltsArray = JSON.parse(loadActionsFromForm());
-                    if(eltsArray[0]>=0 && eltsArray[1]>=0 && eltsArray[2]>=0){
-                        rspamd.queryNeighbours('saveactions', null, null, "POST", {}, {
-                            data: elts,
-                            dataType: "json",
-                        });
+                    if(eltsArray[0]<0){
+                        rspamd.alertMessage('alert-modal alert-error', 'Spam can not be negative');
                     }
-                    else{
-                        if(eltsArray[0]<0){
-                            rspamd.alertMessage('alert-modal alert-error', 'spam can not be negative');
-                        }
-                        else if(eltsArray[1]<0){
-                            rspamd.alertMessage('alert-modal alert-error', 'probable_spam can not be negative');
-                        }
-                        else if(eltsArray[2]<0){
-                            rspamd.alertMessage('alert-modal alert-error', 'greylist can not be negative');
-                        }
-                        
+                    else if(eltsArray[1]<0){
+                        rspamd.alertMessage('alert-modal alert-error', 'Probable spam can not be negative');
                     }
-                });
-                $('#saveActionsBtn').on('click', function() {
-                    var elts = loadActionsFromForm();
-                    // String to array for comparison
-                    var eltsArray = JSON.parse(loadActionsFromForm());
-                    if(eltsArray[0]>=0 && eltsArray[1]>=0 && eltsArray[2]>=0){
-                        rspamd.queryLocal('saveactions', null, null, "POST", {}, {
+                    else if(eltsArray[2]<0){
+                        rspamd.alertMessage('alert-modal alert-error', 'Greylist can not be negative');
+                    }
+                    else if(eltsArray[2]<eltsArray[1]<eltsArray[0]){
+                        callback('saveactions', null, null, "POST", {}, {
                             data: elts,
                             dataType: "json",
                         });
                     }
-                    else{
-                        if(eltsArray[0]<0){
-                            rspamd.alertMessage('alert-modal alert-error', 'spam can not be negative');
-                        }
-                        else if(eltsArray[1]<0){
-                            rspamd.alertMessage('alert-modal alert-error', 'probable_spam can not be negative');
-                        }
-                        else if(eltsArray[2]<0){
-                            rspamd.alertMessage('alert-modal alert-error', 'greylist can not be negative');
-                        }
-                        
+                    else {
+                        rspamd.alertMessage('alert-modal alert-error', 'Incorrect order of metric actions threshold');
                     }
+                };
+
+                $('#saveActionsBtn').on('click', function() {
+                    saveActions(rspamd.queryLocal);
+                });
+                $('#saveActionsClusterBtn').on('click', function() {
+                    saveActions(rspamd.queryNeighbours);
                 });
             },
         });