From c37fb02b9e72df96f6bb672fe9a15e99063cd2cd Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 23 Nov 2015 16:42:59 +0200 Subject: [PATCH] record view impovements --- frontend/client/src/router.js | 13 ++++++-- frontend/client/src/views/detail.js | 2 +- frontend/client/src/views/main.js | 13 +++++--- frontend/client/src/views/record/base.js | 21 +++++++++++- frontend/client/src/views/record/detail.js | 32 +++++++++++++------ frontend/client/src/views/record/edit.js | 13 +++++--- .../client/src/views/role/record/detail.js | 6 ++-- 7 files changed, 73 insertions(+), 27 deletions(-) diff --git a/frontend/client/src/router.js b/frontend/client/src/router.js index 4a16885758..bc35471811 100644 --- a/frontend/client/src/router.js +++ b/frontend/client/src/router.js @@ -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); diff --git a/frontend/client/src/views/detail.js b/frontend/client/src/views/detail.js index 14f625ce11..1bab5fc8d5 100644 --- a/frontend/client/src/views/detail.js +++ b/frontend/client/src/views/detail.js @@ -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', } }, diff --git a/frontend/client/src/views/main.js b/frontend/client/src/views/main.js index 5f33e90aa3..cd6c29b8e4 100644 --- a/frontend/client/src/views/main.js +++ b/frontend/client/src/views/main.js @@ -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) { diff --git a/frontend/client/src/views/record/base.js b/frontend/client/src/views/record/base.js index 78d61ead66..b4c135e459 100644 --- a/frontend/client/src/views/record/base.js +++ b/frontend/client/src/views/record/base.js @@ -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 () { diff --git a/frontend/client/src/views/record/detail.js b/frontend/client/src/views/record/detail.js index ad3af3ec91..d0b18bc9ab 100644 --- a/frontend/client/src/views/record/detail.js +++ b/frontend/client/src/views/record/detail.js @@ -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 () { diff --git a/frontend/client/src/views/record/edit.js b/frontend/client/src/views/record/edit.js index a5a6259acd..51ec776e97 100644 --- a/frontend/client/src/views/record/edit.js +++ b/frontend/client/src/views/record/edit.js @@ -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'); }, diff --git a/frontend/client/src/views/role/record/detail.js b/frontend/client/src/views/role/record/detail.js index 850a1bb0dd..088b710c92 100644 --- a/frontend/client/src/views/role/record/detail.js +++ b/frontend/client/src/views/role/record/detail.js @@ -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 = [