record view impovements

This commit is contained in:
yuri
2015-11-23 16:42:59 +02:00
parent 3fc5b08969
commit c37fb02b9e
7 changed files with 73 additions and 27 deletions
+10 -3
View File
@@ -92,19 +92,26 @@ Espo.define('router', [], function () {
});
},
execute: function (callback, args, name) {
checkConfirmLeaveOut: function (callback, context) {
context = context || this;
if (this.confirmLeaveOut) {
if (confirm(this.confirmLeaveOutMessage)) {
this.confirmLeaveOut = false;
Backbone.Router.prototype.execute.call(this, callback, args, name);
callback.call(context);
} else {
this.navigateBack({trigger: false});
}
} else {
Backbone.Router.prototype.execute.call(this, callback, args, name);
callback.call(context);
}
},
execute: function (callback, args, name) {
this.checkConfirmLeaveOut(function () {
Backbone.Router.prototype.execute.call(this, callback, args, name);
});
},
navigate: function (fragment, options) {
this.history.push(fragment);
return Backbone.Router.prototype.navigate.call(this, fragment, options);
+1 -1
View File
@@ -46,7 +46,7 @@ Espo.define('views/detail', 'views/main', function (Dep) {
view: 'Header'
},
body: {
view: 'Record.Detail',
view: 'views/record/detail',
el: '#main > .body',
}
},
+8 -5
View File
@@ -168,11 +168,14 @@ Espo.define('views/main', 'view', function (Dep) {
actionNavigateToRoot: function (data, e) {
e.stopPropagation();
var options = {
isReturn: true
};
this.getRouter().dispatch(this.scope, null, options);
this.getRouter().navigate('#' + this.scope, {trigger: false});
this.getRouter().checkConfirmLeaveOut(function () {
var options = {
isReturn: true
};
this.getRouter().dispatch(this.scope, null, options);
this.getRouter().navigate('#' + this.scope, {trigger: false});
}, this);
},
hideHeaderActionItem: function (name) {
+20 -1
View File
@@ -139,7 +139,10 @@ Espo.define('views/record/base', 'view', function (Dep) {
}
this.on('remove', function () {
this.setConfirmLeaveOut(false);
if (this.isChanged) {
this.model.set(this.attributes);
}
this.setIsNotChanged();
}, this);
this.events = this.events || {};
@@ -161,6 +164,12 @@ Espo.define('views/record/base', 'view', function (Dep) {
}
this._initDependancy();
this.listenTo(this.model, 'change', function () {
if (this.mode == 'edit') {
this.setIsChanged();
}
}, this);
},
applyDependancy: function () {
@@ -179,6 +188,14 @@ Espo.define('views/record/base', 'view', function (Dep) {
}, this);
},
setIsChanged: function () {
this.isChanged = true;
},
setIsNotChanged: function () {
this.isChanged = false;
},
validate: function () {
var notValid = false;
var fields = this.getFields();
@@ -198,6 +215,7 @@ Espo.define('views/record/base', 'view', function (Dep) {
} else {
this.notify('Saved', 'success');
}
this.setIsNotChanged();
},
beforeBeforeSave: function () {
@@ -214,6 +232,7 @@ Espo.define('views/record/base', 'view', function (Dep) {
afterNotModified: function () {
var msg = this.translate('notModified', 'messages');
Espo.Ui.warning(msg, 'warning');
this.setIsNotChanged();
},
afterNotValid: function () {
+23 -9
View File
@@ -228,7 +228,7 @@ Espo.define('views/record/detail', 'views/record/base', function (Dep) {
}, this);
this.listenTo(fieldView, 'inline-edit-off', function () {
this.inlineEditModeIsOn = false;
this.setConfirmLeaveOut(false);
this.setIsNotChanged();
}, this);
}
},
@@ -287,7 +287,7 @@ Espo.define('views/record/detail', 'views/record/base', function (Dep) {
cancelEdit: function () {
this.model.set(this.attributes);
this.setDetailMode();
this.setConfirmLeaveOut(false);
this.setIsNotChanged();
},
delete: function () {
@@ -423,7 +423,10 @@ Espo.define('views/record/detail', 'views/record/base', function (Dep) {
}
this.on('remove', function () {
this.setConfirmLeaveOut(false);
if (this.isChanged) {
this.model.set(this.attributes);
}
this.setIsNotChanged();
}, this);
this.numId = Math.floor((Math.random() * 10000) + 1);
@@ -433,9 +436,10 @@ Espo.define('views/record/detail', 'views/record/base', function (Dep) {
this.events = {};
}
// TODO remove this in future as deprecated
if ('editModeEnabled' in this) {
this.editModeDisabled = !this.editModeEnabled;
if (!this.editModeDisabled) {
if ('editModeDisabled' in this.options) {
this.editModeDisabled = this.options.editModeDisabled;
}
}
if ('buttonsPosition' in this.options) {
@@ -494,11 +498,11 @@ Espo.define('views/record/detail', 'views/record/base', function (Dep) {
this.build();
this.listenTo(this.model, 'sync', function () {
this.attributes = this.model.getClonedAttributes();
}.bind(this));
}, this);
this.listenTo(this.model, 'change', function () {
if (this.mode == 'edit' || this.inlineEditModeIsOn) {
this.setConfirmLeaveOut(true);
this.setIsChanged();
}
}, this);
@@ -515,6 +519,16 @@ Espo.define('views/record/detail', 'views/record/base', function (Dep) {
}
},
setIsChanged: function () {
this.isChanged = true;
this.setConfirmLeaveOut(true);
},
setIsNotChanged: function () {
this.isChanged = false;
this.setConfirmLeaveOut(false);
},
switchToModelByIndex: function (indexOfRecord) {
if (!this.model.collection) return;
var model = this.model.collection.at(indexOfRecord);
@@ -579,7 +593,7 @@ Espo.define('views/record/detail', 'views/record/base', function (Dep) {
this.notify('Saved', 'success');
}
this.enableButtons();
this.setConfirmLeaveOut(false);
this.setIsNotChanged();
},
beforeSave: function () {
+8 -5
View File
@@ -26,11 +26,11 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
Espo.define('Views.Record.Edit', 'Views.Record.Detail', function (Dep) {
Espo.define('views/record/edit', 'views/record/detail', function (Dep) {
return Dep.extend({
template: 'record.edit',
template: 'record/edit',
type: 'edit',
@@ -54,20 +54,23 @@ Espo.define('Views.Record.Edit', 'Views.Record.Detail', function (Dep) {
dropdownItemList: [],
sideView: 'Record.EditSide',
sideView: 'views/record/edit-side',
bottomView: 'Record.EditBottom',
bottomView: 'views/record/edit-bottom',
actionSave: function () {
this.save();
},
actionCancel: function () {
this.setConfirmLeaveOut(false);
this.cancel();
},
cancel: function () {
if (this.isChanged) {
this.model.set(this.attributes);
}
this.setIsNotChanged();
this.exit('cancel');
},
@@ -26,13 +26,13 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
Espo.define('Views.Role.Record.Detail', 'Views.Record.Detail', function (Dep) {
Espo.define('views/role/record/detail', 'views/record/detail', function (Dep) {
return Dep.extend({
sideView: 'Role.Record.DetailSide',
sideView: 'views/role/record/detail-side',
editModeEnabled: false,
editModeDisabled: true,
getDetailLayout: function (callback) {
var simpleLayout = [