calendar timeline dashlet

This commit is contained in:
yuri
2016-04-13 12:40:45 +03:00
parent 591cbf4484
commit f0f402a8b3
8 changed files with 233 additions and 58 deletions
@@ -2,6 +2,7 @@
"view":"crm:views/dashlets/calendar",
"aclScope": "Calendar",
"options": {
"view": "crm:views/dashlets/options/calendar",
"fields": {
"title": {
"type": "varchar",
@@ -19,7 +20,12 @@
},
"mode": {
"type": "enum",
"options": ["basicWeek", "agendaWeek", "month"]
"options": ["basicWeek", "agendaWeek", "timeline", "month", "basicDay", "agendaDay"]
},
"users": {
"type": "linkMultiple",
"entity": "User",
"view": "views/fields/assigned-users"
}
},
"defaults": {
@@ -37,6 +43,10 @@
[
{"name": "mode"},
{"name": "enabledScopeList"}
],
[
{"name": "users"},
false
]
]
}
@@ -7,13 +7,17 @@
"displayRecords": "Display Records",
"isDoubleHeight": "Height 2x",
"mode": "Mode",
"enabledScopeList": "What to display"
"enabledScopeList": "What to display",
"users": "Users"
},
"options": {
"mode": {
"agendaWeek": "Week (agenda)",
"basicWeek": "Week",
"month": "Month"
"month": "Month",
"basicDay": "Day",
"agendaDay": "Day (agenda)",
"timeline": "Timeline"
}
}
}
@@ -179,10 +179,14 @@ Espo.define('crm:views/calendar/timeline', ['view', 'lib!vis'], function (Dep, V
this.enabledScopeList = [];
}
if (this.options.userId) {
this.calendarType = 'single';
if (this.options.calendarType) {
this.calendarType = 'shared';
} else {
this.calendarType = this.getStorage().get('calendar', 'timelineType') || 'single';
if (this.options.userId) {
this.calendarType = 'single';
} else {
this.calendarType = this.getStorage().get('calendar', 'timelineType') || 'single';
}
}
if (this.getAcl().get('userPermission' === 'no')) {
@@ -447,6 +451,7 @@ Espo.define('crm:views/calendar/timeline', ['view', 'lib!vis'], function (Dep, V
timeline.on('changed', function (e) {
if (this.calendarType === 'single') return;
if (this.options.userList) return;
var $title = this.$el.find('.vis-labelset .group-title');
if ($title.size() === 0) return;
@@ -457,15 +462,6 @@ Espo.define('crm:views/calendar/timeline', ['view', 'lib!vis'], function (Dep, V
this.orderUserList(list);
}.bind(this));
timeline.on('groupDragged', function (e) {
//console.log(e);
/*var list = [];
this.$el.find('.vis-labelset .group-title').each(function (i, el) {
list.push($(el).attr('data-id'));
});
this.orderUserList(list);*/
}.bind(this));
timeline.on('rangechanged', function (e) {
this.start = moment(e.start);
this.end = moment(e.end);
@@ -545,7 +541,7 @@ Espo.define('crm:views/calendar/timeline', ['view', 'lib!vis'], function (Dep, V
},
getGroupEditableOptions: function () {
if (this.calendarType === 'single') {
if (this.calendarType === 'single' || this.options.userList) {
return {
add: false,
remove: false,
@@ -591,29 +587,39 @@ Espo.define('crm:views/calendar/timeline', ['view', 'lib!vis'], function (Dep, V
},
initUserList: function () {
this.userList = [];
if (this.calendarType === 'single') {
if (this.options.userId) {
this.userList.push({
id: this.options.userId,
name: this.options.userName || this.options.userId
});
} else {
if (this.options.userList) {
this.userList = Espo.Utils.clone(this.options.userList);
if (!this.userList.length) {
this.userList.push({
id: this.getUser().id,
name: this.getUser().get('name')
});
}
}
} else {
this.userList = [];
if (this.calendarType === 'shared') {
this.getSharedCalenderUserList().forEach(function (item) {
this.userList.push({
id: item.id,
name: item.name
});
}, this);
if (this.calendarType === 'single') {
if (this.options.userId) {
this.userList.push({
id: this.options.userId,
name: this.options.userName || this.options.userId
});
} else {
this.userList.push({
id: this.getUser().id,
name: this.getUser().get('name')
});
}
}
if (this.calendarType === 'shared') {
this.getSharedCalenderUserList().forEach(function (item) {
this.userList.push({
id: item.id,
name: item.name
});
}, this);
}
}
},
@@ -720,16 +726,10 @@ Espo.define('crm:views/calendar/timeline', ['view', 'lib!vis'], function (Dep, V
}
var html = '<span data-id="'+id+'" class="group-title">' + name + '</span>';
html += ' <a class="glyphicon glyphicon-remove small" data-action="removeGroup" data-id="'+id+'"></a>';
if (!this.options.userList) {
html += ' <a class="glyphicon glyphicon-remove small" data-action="removeGroup" data-id="'+id+'"></a>';
}
/*html += '<span class="dropdown email-address-create-dropdown">';
html += '<button class="dropdown-toggle btn btn-link btn-sm" data-toggle="dropdown" aria-expanded="false"><span class="caret text-muted"></span></button>';
html +=
'<ul class="dropdown-menu" role="menu">' +
'<li><a href="#User/view/'+id+'">'+this.translate('View')+'</a></li>' +
'<li><a href="javascript:" data-action="removeGroup" data-id="'+id+'">'+this.translate('Remove')+'</a></li>' +
'</ul>';
html += '</span>';*/
return html;
},
@@ -42,20 +42,42 @@ Espo.define('crm:views/dashlets/calendar', 'views/dashlets/abstract/base', funct
},
afterRender: function () {
this.createView('calendar', 'crm:views/calendar/calendar', {
mode: this.getOption('mode'),
el: this.options.el + ' > .calendar-container',
header: false,
enabledScopeList: this.getOption('enabledScopeList'),
containerSelector: this.options.el
}, function (view) {
view.render();
this.on('resize', function () {
setTimeout(function() {
view.adjustSize();
}, 50);
});
}, this);
var mode = this.getOption('mode');
if (mode === 'timeline') {
var userList = [];
var userIdList = this.getOption('usersIds') || [];
var userNames = this.getOption('usersNames') || {};
userIdList.forEach(function (id) {
userList.push({
id: id,
name: userNames[id] || id
});
}, this);
this.createView('calendar', 'crm:views/calendar/timeline', {
el: this.options.el + ' > .calendar-container',
header: false,
calendarType: 'shared',
userList: userList
}, function (view) {
view.render();
}, this);
} else {
this.createView('calendar', 'crm:views/calendar/calendar', {
mode: mode,
el: this.options.el + ' > .calendar-container',
header: false,
enabledScopeList: this.getOption('enabledScopeList'),
containerSelector: this.options.el
}, function (view) {
view.render();
this.on('resize', function () {
setTimeout(function() {
view.adjustSize();
}, 50);
});
}, this);
}
}
});
});
@@ -0,0 +1,51 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 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.
************************************************************************/
Espo.define('crm:views/dashlets/options/calendar', 'views/dashlets/options/base', function (Dep) {
return Dep.extend({
setup: function () {
Dep.prototype.setup.call(this);
this.manageUsersField();
this.listenTo(this.model, 'change:mode', this.manageUsersField, this);
},
manageUsersField: function () {
if (this.model.get('mode') === 'timeline') {
this.showField('users');
} else {
this.hideField('users');
}
}
});
});
+88
View File
@@ -146,6 +146,94 @@ Espo.define('views/dashlets/options/base', ['views/modal', 'views/record/detail'
this.trigger('save', attributes);
},
getFieldViews: function (withHidden) {
if (this.hasView('record')) {
return this.getView('record').getFieldViews(withHidden) || {};
}
return {};
},
getFieldView: function () {
return (this.getFieldViews(true) || {})[name] || null;
},
hideField: function (name, locked) {
this.recordHelper.setFieldStateParam(name, 'hidden', true);
if (locked) {
this.recordHelper.setFieldStateParam(name, 'hiddenLocked', true);
}
var processHtml = function () {
var fieldView = this.getFieldView(name);
if (fieldView) {
var $field = fieldView.$el;
var $cell = $field.closest('.cell[data-name="' + name + '"]');
var $label = $cell.find('label.control-label[data-name="' + name + '"]');
$field.addClass('hidden');
$label.addClass('hidden');
$cell.addClass('hidden-cell');
} else {
this.$el.find('.cell[data-name="' + name + '"]').addClass('hidden-cell');
this.$el.find('.field[data-name="' + name + '"]').addClass('hidden');
this.$el.find('label.control-label[data-name="' + name + '"]').addClass('hidden');
}
}.bind(this);
if (this.isRendered()) {
processHtml();
} else {
this.once('after:render', function () {
processHtml();
}, this);
}
var view = this.getFieldView(name);
if (view) {
view.setDisabled(locked);
}
},
showField: function (name) {
if (this.recordHelper.getFieldStateParam(name, 'hiddenLocked')) {
return;
}
this.recordHelper.setFieldStateParam(name, 'hidden', false);
var processHtml = function () {
var fieldView = this.getFieldView(name);
if (fieldView) {
var $field = fieldView.$el;
var $cell = $field.closest('.cell[data-name="' + name + '"]');
var $label = $cell.find('label.control-label[data-name="' + name + '"]');
$field.removeClass('hidden');
$label.removeClass('hidden');
$cell.removeClass('hidden-cell');
} else {
this.$el.find('.cell[data-name="' + name + '"]').removeClass('hidden-cell');
this.$el.find('.field[data-name="' + name + '"]').removeClass('hidden');
this.$el.find('label.control-label[data-name="' + name + '"]').removeClass('hidden');
}
}.bind(this);
if (this.isRendered()) {
processHtml();
} else {
this.once('after:render', function () {
processHtml();
}, this);
}
var view = this.getFieldView(name);
if (view) {
if (!view.disabledLocked) {
view.setNotDisabled();
}
}
}
});
});
+1 -1
View File
@@ -83,7 +83,7 @@ Espo.define('views/fields/link-multiple', 'views/fields/base', function (Dep) {
this.nameHashName = this.name + 'Names';
this.idsName = this.name + 'Ids';
this.foreignScope = this.options.foreignScope || this.foreignScope || this.model.defs.links[this.name].entity;
this.foreignScope = this.options.foreignScope || this.foreignScope || this.model.getFieldParam(this.name, 'entity') || this.model.getLinkParam(this.name, 'entity');
if ('createDisabled' in this.options) {
this.createDisabled = this.options.createDisabled;
+1 -1
View File
@@ -81,7 +81,7 @@ Espo.define('views/fields/link', 'views/fields/base', function (Dep) {
this.idName = this.name + 'Id';
this.foreignScope = this.options.foreignScope || this.foreignScope;
this.foreignScope = this.foreignScope || this.model.getFieldParam(this.name, 'entity') || this.model.defs.links[this.name].entity;
this.foreignScope = this.foreignScope || this.model.getFieldParam(this.name, 'entity') || this.model.getLinkParam(this.name, 'entity');
if ('createDisabled' in this.options) {
this.createDisabled = this.options.createDisabled;