BX.namespace("BX");
if (typeof(BX.TaskColorizeKanban) === "undefined") {
BX.TaskColorizeKanban = function () {
this._id = 0;
this._settings = {};
this._serviceUrl = "";
this._tasksIDs = [];
this._isFirstLoad = true;
this._isKanbanGridReload = false;
this._tasksPiorities = {};
this._htmlClassKanbanItem = 'main-kanban-item';
this._htmlClassKanbanItemChecked = 'guo-checked'
this._htmlClassKanbanItemMarked = 'guo-task-high-priority';
this._htmlClassKanbanItemTitle = 'tasks-kanban-item-title';
this._htmlClassKanbanItemTitleHot = 'tasks-kanban-item-title-hot'
};
BX.TaskColorizeKanban.prototype = {
initialize: function (id, config){
this._id = id;
this._settings = config ? config : {};
this._serviceUrl = this.getSetting('serviceUrl', '');
if (!BX.type.isNotEmptyString(this._serviceUrl)) {
throw 'BX.TaskColorizeKanban: could not find service URL.';
}
if(this._isFirstLoad)
{
this.kanbanOnFirstLoad();
}
// перехват события: Kanban.Grid:addItem
BX.addCustomEvent(
'Kanban.Grid:addItem', // событие вызывается при: фильтре|добавлении быстр. задачи|
BX.delegate(this.kanbanGridAddItem, this)
);
// событие вызывается при: окончании формирования всех элементов: Завершение формирования всех гридов
BX.addCustomEvent(
'onAjaxSuccessFinish',
BX.delegate(this.kanbanGridOnRender, this)
);
// SidePanel.Slider:onMessage
BX.addCustomEvent(
'SidePanel.Slider:onMessage',
BX.delegate(this.SliderOnMessage, this)
);
},
getSetting: function (name, defaultval){
return typeof (this._settings[name]) != 'undefined' ? this._settings[name] : defaultval;
},
setSetting: function (name, value){
this._settings[name] = value;
},
SliderOnMessage: function(){
this.setTasksPriorities();
},
SliderOnCloseComplete: function()
{
this.setTasksPriorities();
},
kanbanOnFirstLoad: function(){
this.setTasksPriorities();
this._isFirstLoad = false;
},
getTasksIDs: function(){
let tasksIDs = [];
let kanbanItems = BX.findChildrenByClassName(document, this._htmlClassKanbanItem, true);
for (let cardIndex in kanbanItems) {
let obj = kanbanItems[cardIndex];
let taskId = parseInt(BX.data(obj,'id'));
if(taskId>0)
tasksIDs.push(taskId);
}
return tasksIDs;
},
setTasksPriorities: function (){
let taskIDs = [];
if(this._tasksIDs.length >0)
{
taskIDs = this._tasksIDs;
}
else{
taskIDs = this.getTasksIDs();
this._tasksIDs = taskIDs;
}
let postData = {
'MODE': 'CHECK_PRIORITY',
'OWNER_TYPE': this.getSetting('ownerType', ''),
'PERMISSION_ENTITY_TYPE': this.getSetting('permissionEntityType', ''),
'sessId': this.getSetting('sessId', ''),
'taskIDs': taskIDs,
};
BX.ajax({
'url': this._serviceUrl,
'method': "POST",
'dataType': "json",
'data': postData,
onsuccess: BX.delegate(this._onActionRequestSuccess, this),
onfailure: BX.delegate(this._onActionRequestFailure, this)
});
},
markTasksByHighPriority: function(data){
if(data === false)
return;
let tasksH = data;
this._tasksPiorities = tasksH;
let kanbanItems = BX.findChildrenByClassName(document, this._htmlClassKanbanItem, true);
for (let cardIndex in kanbanItems) {
let obj = kanbanItems[cardIndex];
let objTitle = BX.findChildrenByClassName(obj, this._htmlClassKanbanItemTitle, true);
let taskId = parseInt(BX.data(obj,'id'));
BX.addClass(kanbanItems[cardIndex], this._htmlClassKanbanItemChecked);
if(tasksH[taskId] === 'H') {
BX.addClass(kanbanItems[cardIndex], this._htmlClassKanbanItemMarked);
// добавляем иконку: "огонек" к названию
for(let i=0; i<=objTitle.length; i++)
{
BX.addClass(objTitle[i], this._htmlClassKanbanItemTitleHot);
}
}
else {
BX.removeClass(kanbanItems[cardIndex], this._htmlClassKanbanItemMarked);
// удаляем иконку: "огонек" из названия
for(let i=0; i<=objTitle.length; i++)
{
BX.removeClass(objTitle[i], this._htmlClassKanbanItemTitleHot);
}
}
}
},
kanbanGridAddItem:function(obj){
this._isKanbanGridReload = true;
let taskId = parseInt(obj.data.id);
let tasksPriorities = this._tasksPiorities;
if(typeof (tasksPriorities[taskId]) !== 'undefined')
return;
this._tasksIDs.push(taskId);
tasksPriorities[taskId] = 'H';
this._tasksPiorities = tasksPriorities;
},
kanbanGridOnRender: function(obj){
if(this._isKanbanGridReload === false)
return;
this._isKanbanGridReload = false;
let self = this;
setTimeout(function(){
self.setTasksPriorities();
}, 100);
},
_onActionRequestSuccess:function(data){
if (data.ERROR) {
this.error(data);
return;
}
switch (data['POST']['MODE'])
{
case 'CHECK_PRIORITY':
this.markTasksByHighPriority(data['RESULT']['PRIORITY_H']);
break;
default:
data.ERROR = "JS_MODE_NOT_FOUND" + ' ' + data['POST']['MODE'];
this.error(data);
break;
}
},
_onActionRequestFailure:function(data) {
console.log('dataFailure');
console.log(data);
},
error: function (data){
console.log('Error');
console.log(data);
},
};
BX.TaskColorizeKanban.create = function (sessId){
let id = 0;
let config = {
'sessId': sessId,
'serviceUrl': '/local/classes/Tasks/ajax/TaskColorKanban.php?sessid=' + sessId,
'ownerType': 'KANBAN',
'viewMode': 'KANBAN',
'viewType': 'VIEW_MODE_KANBAN',
};
let self = new BX.TaskColorizeKanban();
self.initialize(id, config);
return self;
};
}
if (typeof(BX.GuoTaskSlider) === "undefined") {
BX.GuoTaskSlider = function () {
this._id = 0;
this._settings = {};
this._serviceUrl = "";
this._htmlTaskContanerId = 'tasks-iframe-popup-scope';
this._htmlClassPriorityBox = 'task-info-panel-important';
this._htmlClassTaskSaveBtn = 'ui-btn-success';
this.isSetEventPriorityOnChange = false;
};
BX.GuoTaskSlider.prototype = {
initialize: function (id, config) {
this._id = id;
this._settings = config ? config : {};
this._serviceUrl = this.getSetting('serviceUrl', '');
if (!BX.type.isNotEmptyString(this._serviceUrl)) {
throw 'BX.GuoTaskSlider: could not find service URL.';
}
BX.addCustomEvent(
'SidePanel.Slider:onLoad',
BX.delegate(this.handleSliderSendMessage, this)
);
BX.addCustomEvent(
'SidePanel.Slider:onClose',
BX.delegate(this.handleSliderSendMessage, this)
);
},
getSetting: function (name, defaultval){
return typeof (this._settings[name]) != 'undefined' ? this._settings[name] : defaultval;
},
setSetting: function (name, value){
this._settings[name] = value;
},
handleSliderSendMessage: function (){
BX.SidePanel.Instance.postMessage(window, "priority", { isChanged: true });
},
};
BX.GuoTaskSlider.create = function (sessId){
let id = 0;
let config = {
'sessId': sessId,
'serviceUrl': '/local/classes/Tasks/ajax/TaskColorKanban.php?sessid=' + sessId,
'ownerType': 'KANBAN_SLIDER',
'viewMode': 'KANBAN_TASK_SLIDER',
'viewType': 'VIEW_MODE_TASK_SLIDER',
};
let self = new BX.GuoTaskSlider();
self.initialize(id, config);
return self;
};
}
|