]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Allow to save maps on the cluster
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 30 Jan 2017 18:07:07 +0000 (18:07 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 30 Jan 2017 18:07:07 +0000 (18:07 +0000)
interface/index.html
interface/js/rspamd.js

index d0299304b6b788c0d399b6fb02f7faad5ac66890..11a0f3f5a89e07a026a17c03bd2373369a1c5165 100644 (file)
                        <div class="modal-footer">
                                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true" id="modalClose">Close</button>
                                <button class="btn btn-primary" id="modalSave">Save changes</button>
+                               <button class="btn btn-primary" id="modalSaveAll">Save on cluster</button>
                        </div>
                </div>
        </div>
index 17ed5949034958ca889e49f723b982f52cda7daf..ad0f5ce5f30270d122281189918814e015455790 100644 (file)
               else {
                   glyph_status = "glyphicon glyphicon-remove-circle";
               }
+              if (!('config_id' in val.data)) {
+                 val.data.config_id = "";
+              }
               if (checked_server == key) {
                 $('#clusterTable tbody').append('<tr>' +
                     '<td class="col1" title="Radio"><input type="radio" class="form-control radio" name="clusterName" value="' + key + '" checked></td>' +
                         "use strict";
                         method = typeof method !== 'undefined' ? method : "GET";
                         var req_params = {
+                            type: method,
                             jsonp: false,
                             beforeSend: function (xhr) {
                                 xhr.setRequestHeader("Password", getPassword());
                                 } else {
                                     neighbours_status[ind].status = true; //serv does not work
                                     neighbours_status[ind].data = data;
-                                    if (!('config_id' in neighbours_status[ind].data)) {
-                                        neighbours_status[ind].data.config_id = "";
-                                    }
                                 }
                                 if (neighbours_status.every(function (elt) {return elt.checked;})) {
                                     on_success(neighbours_status);
                         };
                         if (params) {
                             $.each(params, function(k, v) {
-                                req_params.k = v;
+                                req_params[k] = v;
                             });
                         }
                         $.ajax(req_params);
             $(target).modal(show = true, backdrop = true, keyboard = show);
             if (editable === false) {
                 $('#modalSave').hide();
+                $('#modalSaveAll').hide();
             } else {
                 $('#modalSave').show();
+                $('#modalSaveAll').show();
             }
             return false;
         });
         // close modal without saving
-        $(document).on('click', '[data-dismiss="modal"]', function () {
+        $('[data-dismiss="modal"]').on('click', function () {
             $('#modalBody form').hide();
         });
 
                 $(this).closest('form').find('button').attr('disabled').addClass('disabled');
             }
         });
+        function save_map_success() {
+            alertMessage('alert-modal alert-success', 'Map data successfully saved');
+            $('#modalDialog').modal('hide');
+        }
+        function save_map_error(serv, jqXHR, textStatus, errorThrown) {
+            alertMessage('alert-modal alert-error', 'Save map error on ' +
+                    serv.name + ': ' + errorThrown);
+        }
         // @save forms from modal
-        $(document).on('click', '#modalSave', function () {
+        $('#modalSave').on('click', function () {
             var form = $('#modalBody').children().filter(':visible');
             // var map = $(form).data('map');
             // var type = $(form).data('type');
             var id = $(form).attr('id');
             saveMap(action, id);
         });
-        $(document).on('click', '#modalSaveAll', function () {
+        $('#modalSaveAll').on('click', function () {
             var form = $('#modalBody').children().filter(':visible');
             // var map = $(form).data('map');
             // var type = $(form).data('type');
             var action = $(form).attr('action');
             var id = $(form).attr('id');
-            saveMap(action, id);
+            var data = $('#' + id).find('textarea').val();
+            queryNeighbours(action, save_map_success, save_map_error, "POST", {
+                "Map": id,
+            }, {
+                data: data,
+                dataType: "text",
+            });
         });
         // @upload map from modal
         function saveMap(action, id) {
                     xhr.setRequestHeader('Debug', true);
                 },
                 error: function (data) {
-                    alertMessage('alert-modal alert-error', data.statusText);
+                    save_map_error('local', null, null, data.statusText);
                 },
-                success: function () {
-                    alertMessage('alert-modal alert-success', 'Map data successfully saved');
-                    $('#modalDialog').modal('hide');
-                }
+                success: save_map_success,
             });
         }
+
         // @upload symbols from modal
         function saveSymbols(action, id) {
             var inputs = $('#' + id + ' :input[data-role="numerictextbox"]');