file: sourceList

This commit is contained in:
yuri
2017-02-14 12:33:28 +02:00
parent 6ec18950e4
commit 372c84bfa3
3 changed files with 105 additions and 1 deletions
@@ -4,6 +4,11 @@
"name":"required",
"type":"bool",
"default":false
},
{
"name": "sourceList",
"type": "multiEnum",
"view": "views/admin/field-manager/fields/source-list"
}
],
"actualFields":[
+17
View File
@@ -1,9 +1,26 @@
<div>
<div class="attachment-button{{#if id}} hidden{{/if}}">
<div class="pull-left">
<label style="overflow: hidden; width: 50px; cursor: pointer;">
<span class="btn btn-default" style="cursor: pointer;"><span class="glyphicon glyphicon-paperclip"></span></span>
<input type="file" class="file pull-right" style="opacity: 0; width: 1px;" {{#if acceptAttribue}}accept="{{acceptAttribue}}"{{/if}}>
</label>
</div>
{{#unless id}}
{{#if sourceList.length}}
<div class="pull-left dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">
<span class="glyphicon glyphicon-file"></span>
</button>
<ul class="dropdown-menu" role="menu">
{{#each sourceList}}
<li><a href="javascript:" class="action" data-action="insertFromSource" data-name="{{./this}}">{{translate this category='insertFromSourceLabels' scope='Attachment'}}</a></li>
{{/each}}
</ul>
</div>
{{/if}}
{{/unless}}
</div>
<div class="attachment"></div>
</div>
+83 -1
View File
@@ -88,13 +88,23 @@ Espo.define('views/fields/file', 'views/fields/link', function (Dep) {
view.render();
});
},
'click a.action[data-action="insertFromSource"]': function (e) {
var name = $(e.currentTarget).data('name');
this.insertFromSource(name);
}
},
data: function () {
return _.extend({
var data =_.extend({
id: this.model.get(this.idName),
acceptAttribue: this.acceptAttribue
}, Dep.prototype.data.call(this));
if (this.mode == 'edit') {
data.sourceList = this.sourceList;
}
return data;
},
validateRequired: function () {
@@ -113,6 +123,8 @@ Espo.define('views/fields/file', 'views/fields/link', function (Dep) {
this.typeName = this.name + 'Type';
this.foreignScope = 'Attachment';
this.sourceList = Espo.Utils.clone(this.params.sourceList || []);
if ('showPreview' in this.params) {
this.showPreview = this.params.showPreview;
}
@@ -337,6 +349,76 @@ Espo.define('views/fields/file', 'views/fields/link', function (Dep) {
return $att;
},
insertFromSource: function (source) {
var viewName =
this.getMetadata().get(['Attachment', 'sources', source, 'insertModalView']) ||
this.getMetadata().get(['clientDefs', source, 'modalViews', 'select']) ||
'views/modals/select-records';
if (viewName) {
this.notify('Loading...');
var filters = null;
if (('getSelectFilters' + source) in this) {
filters = this['getSelectFilters' + source]();
if (this.model.get('parentId') && this.model.get('parentType') === 'Account') {
if (this.getMetadata().get(['entityDefs', source, 'fields', 'account', 'type']) === 'link') {
filters = {
account: {
type: 'equals',
field: 'accountId',
value: this.model.get('parentId'),
valueName: this.model.get('parentName')
}
};
}
}
}
var boolFilterList = this.getMetadata().get(['Attachment', 'sources', source, 'boolFilterList']);
if (('getSelectBoolFilterList' + source) in this) {
boolFilterList = this['getSelectBoolFilterList' + source]();
}
var primaryFilterName = this.getMetadata().get(['Attachment', 'sources', source, 'primaryFilter']);
if (('getSelectPrimaryFilterName' + source) in this) {
primaryFilterName = this['getSelectPrimaryFilterName' + source]();
}
this.createView('insertFromSource', viewName, {
scope: source,
createButton: false,
filters: filters,
boolFilterList: boolFilterList,
primaryFilterName: primaryFilterName,
multiple: false
}, function (view) {
view.render();
this.notify(false);
this.listenToOnce(view, 'select', function (modelList) {
if (Object.prototype.toString.call(modelList) !== '[object Array]') {
modelList = [modelList];
}
modelList.forEach(function (model) {
if (model.name === 'Attachment') {
this.setAttachment(model);
} else {
this.ajaxPostRequest(source + '/action/getAttachmentList', {
id: model.id
}).done(function (attachmentList) {
attachmentList.forEach(function (item) {
this.getModelFactory().create('Attachment', function (attachment) {
attachment.set(item);
this.setAttachment(attachment, true);
}, this);
}, this);
}.bind(this));
}
}, this);
});
}, this);
return;
}
},
fetch: function () {
return {};
}