+Editor.prototype.saveToBranch = function(msg)
+{
+ var changed_panel = $('.panel-wrap.changed');
+ var self = this;
+ $.log('Saving to local branch - panel:', changed_panel);
+
+ if(!msg) msg = "Zapis z edytora platformy.";
+
+ if( changed_panel.length == 0) {
+ $.log('Nothing to save.');
+ return true; /* no changes */
+ }
+
+ if( changed_panel.length > 1) {
+ alert('Błąd: więcej niż jeden panel został zmodyfikowany. Nie można zapisać.');
+ return false;
+ }
+
+ saveInfo = changed_panel.data('ctrl').saveInfo();
+ var postData = ''
+
+ if(saveInfo.postData instanceof Object)
+ postData = $.param(saveInfo.postData);
+ else
+ postData = saveInfo.postData;
+
+ postData += '&' + $.param({
+ 'commit_message': msg
+ })
+
+ $.ajax({
+ url: saveInfo.url,
+ dataType: 'json',
+ success: function(data, textStatus) {
+ if (data.result != 'ok')
+ self.showPopup('save-error', data.errors[0]);
+ else {
+ self.refreshPanels(changed_panel);
+ $('#toolbar-button-save').attr('disabled', 'disabled');
+ $('#toolbar-button-commit').removeAttr('disabled');
+ if(self.autosaveTimer)
+ clearTimeout(self.autosaveTimer);
+
+ self.showPopup('save-successful');
+ }
+ },
+ error: function(rq, tstat, err) {
+ self.showPopup('save-error');
+ },
+ type: 'POST',
+ data: postData
+ });
+
+ return true;
+};
+
+Editor.prototype.autoSave = function()
+{
+ this.autosaveTimer = null;
+ // first check if there is anything to save
+ $.log('Autosave');
+ this.saveToBranch("Automatyczny zapis z edytora platformy.");