panel actions improvement
This commit is contained in:
@@ -1,31 +1,7 @@
|
||||
{{#each panelList}}
|
||||
<div class="panel panel-{{#if style}}{{style}}{{else}}default{{/if}} panel-{{name}}{{#if hidden}} hidden{{/if}}{{#if sticked}} sticked{{/if}}" data-name="{{name}}" data-name="{{name}}">
|
||||
<div class="panel-heading">
|
||||
<div class="pull-right btn-group">
|
||||
{{#if buttonList}}
|
||||
{{#each buttonList}}
|
||||
<button type="button" class="btn btn-{{#if ../../style}}{{../../style}}{{else}}default{{/if}} btn-sm action{{#if hidden}} hidden{{/if}}" data-action="{{action}}" data-panel="{{../../name}}" {{#each data}} data-{{hyphen @key}}="{{./this}}"{{/each}} title="{{#if title}}{{translate title scope=../../scope}}{{/if}}">{{#if html}}{{{html}}}{{else}}{{translate label scope=../../../../scope}}{{/if}}</button>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{#if actionList}}
|
||||
<button type="button" class="btn btn-{{#if ../style}}{{../style}}{{else}}default{{/if}} btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{{#each actionList}}
|
||||
{{#if this}}
|
||||
<li><a {{#if link}}href="{{link}}"{{else}}href="javascript:"{{/if}} class="action{{#if hidden}} hidden{{/if}}" data-panel="{{../../../name}}" {{#if action}} data-action={{action}}{{/if}}{{#each data}} data-{{hyphen @key}}="{{./this}}"{{/each}}>{{#if html}}{{{html}}}{{else}}{{translate label scope=../../../../../scope}}{{/if}}</a></li>
|
||||
{{else}}
|
||||
{{#unless @first}}
|
||||
{{#unless @last}}
|
||||
<li class="divider"></li>
|
||||
{{/unless}}
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="pull-right btn-group panel-actions-container">{{{var actionsViewKey ../this}}}</div>
|
||||
<h4 class="panel-title">
|
||||
{{#unless notRefreshable}}
|
||||
<span style="cursor: pointer;" class="action" title="{{translate 'clickToRefresh' category='messages'}}" data-action="refresh" data-panel="{{name}}">
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{{#each buttonList}}
|
||||
<button type="button" class="btn btn-{{#if ../defs.style}}{{../defs.style}}{{else}}default{{/if}} btn-sm action{{#if hidden}} hidden{{/if}}" data-action="{{action}}" data-panel="{{../defs.name}}" {{#each data}} data-{{hyphen @key}}="{{./this}}"{{/each}} title="{{#if title}}{{translate title scope=../../scope}}{{/if}}">{{#if html}}{{{html}}}{{else}}{{translate label scope=../../../scope}}{{/if}}</button>
|
||||
{{/each}}
|
||||
|
||||
{{#if actionList}}
|
||||
<button type="button" class="btn btn-{{#if defs.style}}{{defs.style}}{{else}}default{{/if}} btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{{#each actionList}}
|
||||
{{#if this}}
|
||||
<li><a {{#if link}}href="{{link}}"{{else}}href="javascript:"{{/if}} class="action{{#if hidden}} hidden{{/if}}" {{#if action}} data-panel="{{../../../defs.name}}" data-action="{{action}}"{{/if}}{{#each data}} data-{{hyphen @key}}="{{./this}}"{{/each}}>{{#if html}}{{{html}}}{{else}}{{translate label scope=../../../scope}}{{/if}}</a></li>
|
||||
{{else}}
|
||||
{{#unless @first}}
|
||||
{{#unless @last}}
|
||||
<li class="divider"></li>
|
||||
{{/unless}}
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
@@ -2,31 +2,7 @@
|
||||
<div class="panel panel-{{#if style}}{{style}}{{else}}default{{/if}} panel-{{name}}{{#if hidden}} hidden{{/if}}{{#if sticked}} sticked{{/if}}" data-name="{{name}}" data-name="{{name}}">
|
||||
{{#if label}}
|
||||
<div class="panel-heading">
|
||||
<div class="pull-right btn-group">
|
||||
{{#if buttonList}}
|
||||
{{#each buttonList}}
|
||||
<button type="button" class="btn btn-{{#if ../../style}}{{../../style}}{{else}}default{{/if}} btn-sm action{{#if hidden}} hidden{{/if}}" data-action="{{action}}" data-panel="{{../../name}}" {{#each data}} data-{{hyphen @key}}="{{./this}}"{{/each}} title="{{#if title}}{{translate title scope=../scope}}{{/if}}">{{#if html}}{{{html}}}{{else}}{{translate label scope=../../../../scope}}{{/if}}</button>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{#if actionList}}
|
||||
<button type="button" class="btn btn-{{#if style}}{{style}}{{else}}default{{/if}} btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{{#each actionList}}
|
||||
{{#if this}}
|
||||
<li><a {{#if link}}href="{{link}}"{{else}}href="javascript:"{{/if}} class="action{{#if hidden}} hidden{{/if}}" {{#if action}} data-panel="{{../../../name}}" data-action="{{action}}"{{/if}}{{#each data}} data-{{hyphen @key}}="{{./this}}"{{/each}}>{{#if html}}{{{html}}}{{else}}{{translate label scope=../../../../../../scope}}{{/if}}</a></li>
|
||||
{{else}}
|
||||
{{#unless @first}}
|
||||
{{#unless @last}}
|
||||
<li class="divider"></li>
|
||||
{{/unless}}
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="pull-right btn-group panel-actions-container">{{{var ../actionsViewKey ../../this}}}</div>
|
||||
<h4 class="panel-title">
|
||||
{{#unless notRefreshable}}
|
||||
<span style="cursor: pointer;" class="action" title="{{translate 'clickToRefresh' category='messages'}}" data-action="refresh" data-panel="{{name}}">
|
||||
|
||||
+3
-2
@@ -27,9 +27,10 @@
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('utils', [], function () {
|
||||
|
||||
var Utils = Espo.utils = Espo.Utils = {
|
||||
|
||||
checkActionAccess: function (acl, obj, item) {
|
||||
checkActionAccess: function (acl, obj, item, isPrecise) {
|
||||
var hasAccess = true;
|
||||
if (item.acl) {
|
||||
if (!item.aclScope) {
|
||||
@@ -37,7 +38,7 @@ Espo.define('utils', [], function () {
|
||||
if (typeof obj == 'string' || obj instanceof String) {
|
||||
hasAccess = acl.check(obj, item.acl);
|
||||
} else {
|
||||
hasAccess = acl.checkModel(obj, item.acl);
|
||||
hasAccess = acl.checkModel(obj, item.acl, isPrecise);
|
||||
}
|
||||
} else {
|
||||
hasAccess = acl.check(item.scope, item.acl);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('views/record/detail-bottom', ['view'], function (Dep) {
|
||||
define('views/record/detail-bottom', 'views/record/panels-container', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
@@ -42,95 +42,6 @@ Espo.define('views/record/detail-bottom', ['view'], function (Dep) {
|
||||
|
||||
portalLayoutDisabled: false,
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
panelList: this.panelList,
|
||||
scope: this.scope,
|
||||
entityType: this.entityType
|
||||
};
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .action': function (e) {
|
||||
var $target = $(e.currentTarget);
|
||||
var action = $target.data('action');
|
||||
var panel = $target.data('panel');
|
||||
var data = $target.data();
|
||||
if (action) {
|
||||
var method = 'action' + Espo.Utils.upperCaseFirst(action);
|
||||
var d = _.clone(data);
|
||||
delete d['action'];
|
||||
delete d['panel'];
|
||||
var view = this.getView(panel);
|
||||
if (view && typeof view[method] == 'function') {
|
||||
view[method].call(view, d, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
showPanel: function (name, callback) {
|
||||
this.recordHelper.setPanelStateParam(name, 'hidden', false);
|
||||
|
||||
var isFound = false;
|
||||
this.panelList.forEach(function (d) {
|
||||
if (d.name == name) {
|
||||
d.hidden = false;
|
||||
isFound = true;
|
||||
}
|
||||
}, this);
|
||||
if (!isFound) return;
|
||||
|
||||
if (this.isRendered()) {
|
||||
var view = this.getView(name);
|
||||
if (view) {
|
||||
view.$el.closest('.panel').removeClass('hidden');
|
||||
view.disabled = false;
|
||||
view.trigger('show');
|
||||
}
|
||||
if (callback) {
|
||||
callback.call(this);
|
||||
}
|
||||
} else {
|
||||
if (callback) {
|
||||
this.once('after:render', function () {
|
||||
callback.call(this);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
hidePanel: function (name, callback) {
|
||||
this.recordHelper.setPanelStateParam(name, 'hidden', true);
|
||||
|
||||
var isFound = false;
|
||||
this.panelList.forEach(function (d) {
|
||||
if (d.name == name) {
|
||||
d.hidden = true;
|
||||
isFound = true;
|
||||
}
|
||||
}, this);
|
||||
if (!isFound) return;
|
||||
|
||||
if (this.isRendered()) {
|
||||
var view = this.getView(name);
|
||||
if (view) {
|
||||
view.$el.closest('.panel').addClass('hidden');
|
||||
view.disabled = true;
|
||||
view.trigger('hide');
|
||||
}
|
||||
if (callback) {
|
||||
callback.call(this);
|
||||
}
|
||||
} else {
|
||||
if (callback) {
|
||||
this.once('after:render', function () {
|
||||
callback.call(this);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
setupPanels: function () {
|
||||
var scope = this.scope;
|
||||
|
||||
@@ -165,41 +76,6 @@ Espo.define('views/record/detail-bottom', ['view'], function (Dep) {
|
||||
}
|
||||
},
|
||||
|
||||
setupPanelViews: function () {
|
||||
this.panelList.forEach(function (p) {
|
||||
var name = p.name;
|
||||
this.createView(name, p.view, {
|
||||
model: this.model,
|
||||
panelName: name,
|
||||
el: this.options.el + ' .panel[data-name="' + name + '"] > .panel-body',
|
||||
defs: p,
|
||||
mode: this.mode,
|
||||
recordHelper: this.recordHelper,
|
||||
inlineEditDisabled: this.inlineEditDisabled,
|
||||
readOnly: this.readOnly,
|
||||
disabled: p.hidden || false,
|
||||
recordViewObject: this.recordViewObject
|
||||
}, function (view) {
|
||||
if ('getActionList' in view) {
|
||||
p.actionList = this.filterActions(view.getActionList());
|
||||
}
|
||||
if ('getButtonList' in view) {
|
||||
p.buttonList = this.filterActions(view.getButtonList());
|
||||
}
|
||||
|
||||
if (view.titleHtml) {
|
||||
p.titleHtml = view.titleHtml;
|
||||
} else {
|
||||
if (p.label) {
|
||||
p.title = this.translate(p.label, 'labels', this.scope);
|
||||
} else {
|
||||
p.title = view.title;
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}, this);
|
||||
},
|
||||
|
||||
init: function () {
|
||||
this.recordHelper = this.options.recordHelper;
|
||||
this.scope = this.entityType = this.model.name;
|
||||
@@ -279,12 +155,20 @@ Espo.define('views/record/detail-bottom', ['view'], function (Dep) {
|
||||
return order1 - order2;
|
||||
});
|
||||
|
||||
this.panelList.forEach(function (item) {
|
||||
item.actionsViewKey = item.name + 'Actions';
|
||||
}, this);
|
||||
|
||||
this.setupPanelViews();
|
||||
this.wait(false);
|
||||
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
setReadOnly: function () {
|
||||
this.readOnly = true;
|
||||
},
|
||||
|
||||
loadRelationshipsLayout: function (callback) {
|
||||
var layoutName = 'relationships';
|
||||
if (this.getUser().isPortal() && !this.portalLayoutDisabled) {
|
||||
@@ -353,42 +237,5 @@ Espo.define('views/record/detail-bottom', ['view'], function (Dep) {
|
||||
this.panelList.push(p);
|
||||
}, this);
|
||||
},
|
||||
|
||||
filterActions: function (actions) {
|
||||
var filtered = [];
|
||||
actions.forEach(function (item) {
|
||||
if (Espo.Utils.checkActionAccess(this.getAcl(), this.model, item)) {
|
||||
filtered.push(item);
|
||||
}
|
||||
}.bind(this));
|
||||
return filtered;
|
||||
},
|
||||
|
||||
getFieldViews: function (withHidden) {
|
||||
var fields = {};
|
||||
this.panelList.forEach(function (p) {
|
||||
var panelView = this.getView(p.name);
|
||||
if ((!panelView.disabled || withHidden) && 'getFieldViews' in panelView) {
|
||||
fields = _.extend(fields, panelView.getFieldViews());
|
||||
}
|
||||
}, this);
|
||||
return fields;
|
||||
},
|
||||
|
||||
getFields: function () {
|
||||
return this.getFieldViews();
|
||||
},
|
||||
|
||||
fetch: function () {
|
||||
var data = {};
|
||||
|
||||
this.panelList.forEach(function (p) {
|
||||
var panelView = this.getView(p.name);
|
||||
if (!panelView.disabled && 'fetch' in panelView) {
|
||||
data = _.extend(data, panelView.fetch());
|
||||
}
|
||||
}, this);
|
||||
return data;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('views/record/detail-side', ['view'], function (Dep) {
|
||||
Espo.define('views/record/detail-side', 'views/record/panels-container', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
@@ -59,33 +59,6 @@ Espo.define('views/record/detail-side', ['view'], function (Dep) {
|
||||
}
|
||||
},
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
panelList: this.panelList,
|
||||
scope: this.scope,
|
||||
entityType: this.entityType
|
||||
};
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .action': function (e) {
|
||||
var $target = $(e.currentTarget);
|
||||
var action = $target.data('action');
|
||||
var panel = $target.data('panel');
|
||||
var data = $target.data();
|
||||
if (action) {
|
||||
var method = 'action' + Espo.Utils.upperCaseFirst(action);
|
||||
var d = _.clone(data);
|
||||
delete d['action'];
|
||||
delete d['panel'];
|
||||
var view = this.getView(panel);
|
||||
if (view && typeof view[method] == 'function') {
|
||||
view[method].call(view, d);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
init: function () {
|
||||
this.panelList = this.options.panelList || this.panelList;
|
||||
this.scope = this.entityType = this.options.model.name;
|
||||
@@ -145,6 +118,10 @@ Espo.define('views/record/detail-side', ['view'], function (Dep) {
|
||||
return item;
|
||||
}, this);
|
||||
|
||||
this.panelList.forEach(function (item) {
|
||||
item.actionsViewKey = item.name + 'Actions';
|
||||
}, this);
|
||||
|
||||
this.wait(true);
|
||||
this.getHelper().layoutManager.get(this.scope, 'sidePanels' + Espo.Utils.upperCaseFirst(this.type), function (layoutData) {
|
||||
if (layoutData) {
|
||||
@@ -247,137 +224,5 @@ Espo.define('views/record/detail-side', ['view'], function (Dep) {
|
||||
this.panelList.unshift(defaultPanelDefs);
|
||||
},
|
||||
|
||||
setupPanelViews: function () {
|
||||
this.panelList.forEach(function (p) {
|
||||
var o = {
|
||||
model: this.options.model,
|
||||
el: this.options.el + ' .panel[data-name="' + p.name + '"] > .panel-body',
|
||||
readOnly: this.readOnly,
|
||||
inlineEditDisabled: this.inlineEditDisabled,
|
||||
mode: this.mode,
|
||||
recordHelper: this.recordHelper,
|
||||
defs: p,
|
||||
disabled: p.hidden || false,
|
||||
recordViewObject: this.recordViewObject
|
||||
};
|
||||
o = _.extend(o, p.options);
|
||||
this.createView(p.name, p.view, o, function (view) {
|
||||
if ('getButtonList' in view) {
|
||||
p.buttonList = this.filterActions(view.getButtonList());
|
||||
}
|
||||
if ('getActionList' in view) {
|
||||
p.actionList = this.filterActions(view.getActionList());
|
||||
}
|
||||
if (p.label) {
|
||||
p.title = this.translate(p.label, 'labels', this.scope);
|
||||
} else {
|
||||
p.title = view.title;
|
||||
}
|
||||
if (view.titleHtml) {
|
||||
p.titleHtml = view.titleHtml;
|
||||
}
|
||||
}, this);
|
||||
}, this);
|
||||
},
|
||||
|
||||
getFieldViews: function (withHidden) {
|
||||
var fields = {};
|
||||
this.panelList.forEach(function (p) {
|
||||
var panelView = this.getView(p.name);
|
||||
if ((!panelView.disabled || withHidden) && 'getFieldViews' in panelView) {
|
||||
fields = _.extend(fields, panelView.getFieldViews());
|
||||
}
|
||||
}, this);
|
||||
return fields;
|
||||
},
|
||||
|
||||
getFields: function () {
|
||||
return this.getFieldViews();
|
||||
},
|
||||
|
||||
fetch: function () {
|
||||
var data = {};
|
||||
|
||||
this.panelList.forEach(function (p) {
|
||||
var panelView = this.getView(p.name);
|
||||
if (!panelView.disabled && 'fetch' in panelView) {
|
||||
data = _.extend(data, panelView.fetch());
|
||||
}
|
||||
}, this);
|
||||
return data;
|
||||
},
|
||||
|
||||
filterActions: function (actions) {
|
||||
var filtered = [];
|
||||
actions.forEach(function (item) {
|
||||
if (Espo.Utils.checkActionAccess(this.getAcl(), this.model, item)) {
|
||||
filtered.push(item);
|
||||
}
|
||||
}, this);
|
||||
return filtered;
|
||||
},
|
||||
|
||||
showPanel: function (name, callback) {
|
||||
this.recordHelper.setPanelStateParam(name, 'hidden', false);
|
||||
|
||||
var isFound = false;
|
||||
this.panelList.forEach(function (d) {
|
||||
if (d.name == name) {
|
||||
d.hidden = false;
|
||||
isFound = true;
|
||||
}
|
||||
}, this);
|
||||
if (!isFound) return;
|
||||
|
||||
if (this.isRendered()) {
|
||||
var view = this.getView(name);
|
||||
if (view) {
|
||||
view.$el.closest('.panel').removeClass('hidden');
|
||||
view.disabled = false;
|
||||
view.trigger('show');
|
||||
}
|
||||
if (callback) {
|
||||
callback.call(this);
|
||||
}
|
||||
} else {
|
||||
if (callback) {
|
||||
this.once('after:render', function () {
|
||||
callback.call(this);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
hidePanel: function (name, callback) {
|
||||
this.recordHelper.setPanelStateParam(name, 'hidden', true);
|
||||
|
||||
var isFound = false;
|
||||
this.panelList.forEach(function (d) {
|
||||
if (d.name == name) {
|
||||
d.hidden = true;
|
||||
isFound = true;
|
||||
}
|
||||
}, this);
|
||||
if (!isFound) return;
|
||||
|
||||
if (this.isRendered()) {
|
||||
var view = this.getView(name);
|
||||
if (view) {
|
||||
view.$el.closest('.panel').addClass('hidden');
|
||||
view.disabled = true;
|
||||
view.trigger('hide');
|
||||
}
|
||||
if (callback) {
|
||||
callback.call(this);
|
||||
}
|
||||
} else {
|
||||
if (callback) {
|
||||
this.once('after:render', function () {
|
||||
callback.call(this);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -992,12 +992,12 @@ Espo.define('views/record/detail', ['views/record/base', 'view-record-helper'],
|
||||
|
||||
var bottomView = this.getView('bottom');
|
||||
if (bottomView && 'setNotReadOnly' in bottomView) {
|
||||
bottomView.setNotReadOnly();
|
||||
bottomView.setNotReadOnly(onlyNotSetAsReadOnly);
|
||||
}
|
||||
|
||||
var sideView = this.getView('side');
|
||||
if (sideView && 'setNotReadOnly' in sideView) {
|
||||
sideView.setNotReadOnly();
|
||||
sideView.setNotReadOnly(onlyNotSetAsReadOnly);
|
||||
}
|
||||
|
||||
this.getFieldList().forEach(function (field) {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2018 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
define('views/record/panel-actions', 'view', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
template: 'record/panel-actions',
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
defs: this.options.defs,
|
||||
buttonList: this.getButtonList(),
|
||||
actionList: this.getActionList(),
|
||||
entityType: this.options.entityType,
|
||||
scope: this.options.scope
|
||||
};
|
||||
},
|
||||
|
||||
setup: function () {
|
||||
this.buttonList = this.options.defs.buttonList;
|
||||
this.actionList = this.options.defs.actionList;
|
||||
},
|
||||
|
||||
getButtonList: function () {
|
||||
var list = [];
|
||||
this.buttonList.forEach(function (item) {
|
||||
if (item.hidden) return;
|
||||
list.push(item);
|
||||
}, this);
|
||||
return list;
|
||||
},
|
||||
|
||||
getActionList: function () {
|
||||
var list = [];
|
||||
this.actionList.forEach(function (item) {
|
||||
if (item.hidden) return;
|
||||
list.push(item);
|
||||
}, this);
|
||||
return list;
|
||||
},
|
||||
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,238 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2018 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
define('views/record/panels-container', 'view', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
panelList: this.panelList,
|
||||
scope: this.scope,
|
||||
entityType: this.entityType
|
||||
};
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .action': function (e) {
|
||||
var $target = $(e.currentTarget);
|
||||
var action = $target.data('action');
|
||||
var panel = $target.data('panel');
|
||||
var data = $target.data();
|
||||
if (action) {
|
||||
var method = 'action' + Espo.Utils.upperCaseFirst(action);
|
||||
var d = _.clone(data);
|
||||
delete d['action'];
|
||||
delete d['panel'];
|
||||
var view = this.getView(panel);
|
||||
if (view && typeof view[method] == 'function') {
|
||||
view[method].call(view, d, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
setReadOnly: function () {
|
||||
this.readOnly = true;
|
||||
},
|
||||
|
||||
setNotReadOnly: function (onlyNotSetAsReadOnly) {
|
||||
this.readOnly = false;
|
||||
|
||||
if (onlyNotSetAsReadOnly) {
|
||||
this.panelList.forEach(function (item) {
|
||||
this.applyAccessToActions(item.buttonList);
|
||||
this.applyAccessToActions(item.actionList);
|
||||
|
||||
if (this.isRendered()) {
|
||||
var actionsView = this.getView(item.actionsViewKey);
|
||||
if (actionsView) {
|
||||
actionsView.reRender();
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
},
|
||||
|
||||
applyAccessToActions: function (actionList) {
|
||||
actionList.forEach(function (item) {
|
||||
if (Espo.Utils.checkActionAccess(this.getAcl(), this.model, item, true)) {
|
||||
if (item.isHiddenByAcl) {
|
||||
item.isHiddenByAcl = false;
|
||||
item.hidden = false;
|
||||
}
|
||||
} else {
|
||||
if (!item.hidden) {
|
||||
item.isHiddenByAcl = true;
|
||||
item.hidden = true;
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
},
|
||||
|
||||
setupPanelViews: function () {
|
||||
this.panelList.forEach(function (p) {
|
||||
|
||||
var name = p.name;
|
||||
var options = {
|
||||
model: this.model,
|
||||
panelName: name,
|
||||
el: this.options.el + ' .panel[data-name="' + name + '"] > .panel-body',
|
||||
defs: p,
|
||||
mode: this.mode,
|
||||
recordHelper: this.recordHelper,
|
||||
inlineEditDisabled: this.inlineEditDisabled,
|
||||
readOnly: this.readOnly,
|
||||
disabled: p.hidden || false,
|
||||
recordViewObject: this.recordViewObject
|
||||
};
|
||||
options = _.extend(options, p.options);
|
||||
this.createView(name, p.view, options, function (view) {
|
||||
if ('getActionList' in view) {
|
||||
p.actionList = view.getActionList();
|
||||
this.applyAccessToActions(p.actionList);
|
||||
}
|
||||
if ('getButtonList' in view) {
|
||||
p.buttonList = view.getButtonList();
|
||||
this.applyAccessToActions(p.buttonList);
|
||||
}
|
||||
|
||||
if (view.titleHtml) {
|
||||
p.titleHtml = view.titleHtml;
|
||||
} else {
|
||||
if (p.label) {
|
||||
p.title = this.translate(p.label, 'labels', this.scope);
|
||||
} else {
|
||||
p.title = view.title;
|
||||
}
|
||||
}
|
||||
|
||||
this.createView(name + 'Actions', 'views/record/panel-actions', {
|
||||
el: this.getSelector() + '.panel[data-name="'+p.name+'"] > .panel-heading > .panel-actions-container',
|
||||
model: this.model,
|
||||
defs: p,
|
||||
scope: this.scope,
|
||||
entityType: this.entityType
|
||||
});
|
||||
}, this);
|
||||
}, this);
|
||||
},
|
||||
|
||||
setupPanels: function () {},
|
||||
|
||||
getFieldViews: function (withHidden) {
|
||||
var fields = {};
|
||||
this.panelList.forEach(function (p) {
|
||||
var panelView = this.getView(p.name);
|
||||
if ((!panelView.disabled || withHidden) && 'getFieldViews' in panelView) {
|
||||
fields = _.extend(fields, panelView.getFieldViews());
|
||||
}
|
||||
}, this);
|
||||
return fields;
|
||||
},
|
||||
|
||||
getFields: function () {
|
||||
return this.getFieldViews();
|
||||
},
|
||||
|
||||
fetch: function () {
|
||||
var data = {};
|
||||
|
||||
this.panelList.forEach(function (p) {
|
||||
var panelView = this.getView(p.name);
|
||||
if (!panelView.disabled && 'fetch' in panelView) {
|
||||
data = _.extend(data, panelView.fetch());
|
||||
}
|
||||
}, this);
|
||||
return data;
|
||||
},
|
||||
|
||||
showPanel: function (name, callback) {
|
||||
this.recordHelper.setPanelStateParam(name, 'hidden', false);
|
||||
|
||||
var isFound = false;
|
||||
this.panelList.forEach(function (d) {
|
||||
if (d.name == name) {
|
||||
d.hidden = false;
|
||||
isFound = true;
|
||||
}
|
||||
}, this);
|
||||
if (!isFound) return;
|
||||
|
||||
if (this.isRendered()) {
|
||||
var view = this.getView(name);
|
||||
if (view) {
|
||||
view.$el.closest('.panel').removeClass('hidden');
|
||||
view.disabled = false;
|
||||
view.trigger('show');
|
||||
}
|
||||
if (callback) {
|
||||
callback.call(this);
|
||||
}
|
||||
} else {
|
||||
if (callback) {
|
||||
this.once('after:render', function () {
|
||||
callback.call(this);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
hidePanel: function (name, callback) {
|
||||
this.recordHelper.setPanelStateParam(name, 'hidden', true);
|
||||
|
||||
var isFound = false;
|
||||
this.panelList.forEach(function (d) {
|
||||
if (d.name == name) {
|
||||
d.hidden = true;
|
||||
isFound = true;
|
||||
}
|
||||
}, this);
|
||||
if (!isFound) return;
|
||||
|
||||
if (this.isRendered()) {
|
||||
var view = this.getView(name);
|
||||
if (view) {
|
||||
view.$el.closest('.panel').addClass('hidden');
|
||||
view.disabled = true;
|
||||
view.trigger('hide');
|
||||
}
|
||||
if (callback) {
|
||||
callback.call(this);
|
||||
}
|
||||
} else {
|
||||
if (callback) {
|
||||
this.once('after:render', function () {
|
||||
callback.call(this);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
@@ -61,13 +61,11 @@ Espo.define('views/record/panels/relationship', ['views/record/panels/bottom', '
|
||||
|
||||
var url = this.url = this.url || this.model.name + '/' + this.model.id + '/' + this.link;
|
||||
|
||||
if (!this.readOnly && !this.defs.readOnly) {
|
||||
if (!('create' in this.defs)) {
|
||||
this.defs.create = true;
|
||||
}
|
||||
if (!('select' in this.defs)) {
|
||||
this.defs.select = true;
|
||||
}
|
||||
if (!('create' in this.defs)) {
|
||||
this.defs.create = true;
|
||||
}
|
||||
if (!('select' in this.defs)) {
|
||||
this.defs.select = true;
|
||||
}
|
||||
|
||||
if (!('view' in this.defs)) {
|
||||
@@ -98,8 +96,7 @@ Espo.define('views/record/panels/relationship', ['views/record/panels/bottom', '
|
||||
title: 'Create',
|
||||
action: this.defs.createAction || 'createRelated',
|
||||
link: this.link,
|
||||
acl: 'create',
|
||||
aclScope: this.scope,
|
||||
acl: 'edit',
|
||||
html: '<span class="fas fa-plus"></span>',
|
||||
data: {
|
||||
link: this.link,
|
||||
@@ -129,8 +126,7 @@ Espo.define('views/record/panels/relationship', ['views/record/panels/bottom', '
|
||||
label: 'Select',
|
||||
action: this.defs.selectAction || 'selectRelated',
|
||||
data: data,
|
||||
acl: 'edit',
|
||||
aclScope: this.model.name
|
||||
acl: 'edit'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user