client/js/save-once.js
changeset 455 18b9be54174d
parent 447 e246651b6626
parent 444 19f0b7803aed
child 516 7d1d44b53af5
equal deleted inserted replaced
454:03e8815a012d 455:18b9be54174d
    18         }
    18         }
    19         Rkns.$.ajax({
    19         Rkns.$.ajax({
    20             url: _opts.url,
    20             url: _opts.url,
    21             data: getdata,
    21             data: getdata,
    22             beforeSend: function(){
    22             beforeSend: function(){
    23                 _proj.set({loading_status:true});
    23             	_proj.set({loadingStatus:true});
    24             },
    24             },
    25             success: function(_data) {
    25             success: function(_data) {
    26                 _proj.set(_data, {validate: true});
    26                 _renkan.dataloader.load(_data);
    27                 _proj.set({loading_status:false});
    27                 _proj.set({loadingStatus:false});
    28                 _proj.set({save_status:0});
    28                 _proj.set({saveStatus:0});
    29                 _renkan.renderer.autoScale();
    29                 _renkan.renderer.autoScale();
    30             }
    30             }
    31         });
    31         });
    32     };
    32     };
    33     var _save = function() {
    33     var _save = function() {
    37             type: _opts.http_method,
    37             type: _opts.http_method,
    38             url: _opts.url,
    38             url: _opts.url,
    39             contentType: "application/json",
    39             contentType: "application/json",
    40             data: JSON.stringify(_data),
    40             data: JSON.stringify(_data),
    41             beforeSend: function(){
    41             beforeSend: function(){
    42                 _proj.set({save_status:2});
    42             	_proj.set({saveStatus:2});
    43             },
    43             },
    44             success: function(data, textStatus, jqXHR) {
    44             success: function(data, textStatus, jqXHR) {
    45                 $(window).off("beforeunload", _onLeave);
    45                 $(window).off("beforeunload", _onLeave);
    46                 _saveWarn = false;
    46                 _saveWarn = false;
    47                 _proj.set({save_status:0});
    47                 _proj.set({saveStatus:0});
    48                 //document.location.hash = "#id=" + data.id;
    48                 //document.location.hash = "#id=" + data.id;
    49                 //$(".Rk-Notifications").text("Saved as "+document.location.href).fadeIn().delay(2000).fadeOut();
    49                 //$(".Rk-Notifications").text("Saved as "+document.location.href).fadeIn().delay(2000).fadeOut();
    50             }
    50             }
    51         });
    51         });
    52     };
    52     };
    53     var _checkLeave = function() {
    53     var _checkLeave = function() {
    54         _proj.set({save_status:1});
    54     	_proj.set({saveStatus:1});
    55         
    55 
    56         var title = _proj.get("title");
    56         var title = _proj.get("title");
    57         if (title && _proj.get("nodes").length) {
    57         if (title && _proj.get("nodes").length) {
    58             $(".Rk-Save-Button").removeClass("disabled");
    58             $(".Rk-Save-Button").removeClass("disabled");
    59         } else {
    59         } else {
    60             $(".Rk-Save-Button").addClass("disabled");
    60             $(".Rk-Save-Button").addClass("disabled");
    67             $(window).on("beforeunload", _onLeave);
    67             $(window).on("beforeunload", _onLeave);
    68         }
    68         }
    69     };
    69     };
    70     _load();
    70     _load();
    71     _proj.on("add:nodes add:edges add:users change", function(_model) {
    71     _proj.on("add:nodes add:edges add:users change", function(_model) {
    72         _model.on("change remove", function(_model) {
    72 	    _model.on("change remove", function(_model) {
    73             if(!(_model.changedAttributes.length === 1 && _model.hasChanged('save_status'))) {
    73 	    	if(!(_model.changedAttributes.length === 1 && _model.hasChanged('saveStatus'))) {
    74                 _checkLeave();
    74 	    		_checkLeave();
    75             }
    75 	    	}
    76         });
    76 	    });
    77         if(!(_proj.changedAttributes.length === 1 && _proj.hasChanged('save_status'))) {
    77 		if(!(_proj.changedAttributes.length === 1 && _proj.hasChanged('saveStatus'))) {
    78             _checkLeave();
    78 		    _checkLeave();
    79         }
    79     	}
    80     });
    80     });
    81     _renkan.renderer.save = function() {
    81     _renkan.renderer.save = function() {
    82         if ($(".Rk-Save-Button").hasClass("disabled")) {
    82         if ($(".Rk-Save-Button").hasClass("disabled")) {
    83             if (!_proj.get("title")) {
    83             if (!_proj.get("title")) {
    84                 $(".Rk-PadTitle").css("border-color","#ff0000");
    84                 $(".Rk-PadTitle").css("border-color","#ff0000");