BX.namespace("BX.Crm");if (typeof(BX.W4aDebtList) === "undefined") {
BX.W4aDebtList = function () {
this._id = "";
this._settings = {};
this._serviceUrl = "";
this._flagExportExcelByMonth = false;
this._year = 0;
this._month = 0;
};
BX.W4aDebtList.prototype = {
/** Common methods */
initialize: function (id, config) {
this._id = id;
this._settings = config ? config : {};
this._serviceUrl = this.getSetting('serviceUrl', '');
if (!BX.type.isNotEmptyString(this._serviceUrl)) {
throw 'W4aDebtList: could not find service URL.';
}
},
getSetting: function (name, defaultval) {
return typeof (this._settings[name]) != 'undefined' ? this._settings[name] : defaultval;
},
setSetting:function(name, value){
this._settings[name] = value;
},
_onActionRequestSuccess:function(data) {
if(data.ERROR) {
this.error(data);
return;
}
switch (data['POST']['MODE'])
{
case 'SET_COMMENT':
let item = data['RESULT']['UPD ATED_ITEM'];
let itemId = parseInt(item.ID);
let itemComment = item.COMMENT;
let itemCommentDatePay = item.COMMENT_DATE_PAY;
this.setComment2(itemId, itemComment, itemCommentDatePay);
if(data['RESULT']['IS_COMPLETED_MSG'])
alert(BX.message("JS_W4A_COMMENT_COMPLETED"));
break;
default:
data.ERROR = BX.message("JS_MODE_NOT_FOUND");
this.error(data);
break;
}
this.reload();
},
_onActionRequestFailure:function(data) {
console.log('dataFailure');
console.log(data);
},
reload: function(){
let reloadAjax = true;
if(reloadAjax)
{
let gridId = this.getSetting('gridId', '');
this.reloadTable(gridId);
}
else
this.reloadWindow();
},
reloadTable(gridId){
let objNavPanel = $('#' + gridId + '_bottom_panels');
let currentPage = "1";
if(typeof objNavPanel.find('.modern-page-current')!== 'undefined')
currentPage = objNavPanel.find('.modern-page-current').html();
let reloadParams = { apply_filter: 'N', clear_nav: 'Y', page: currentPage };
let gridObject = BX.Main.gridManager.getById(gridId);
if (gridObject.hasOwnProperty('instance')){
gridObject.instance.reloadTable('POST', reloadParams);
}
},
reloadWindow: function (){
top.window.location.reload();
},
error: function (data){
alert(BX.message("JS_W4A_ACTION_ERROR_TITLE") + data.ERROR);
},
/** Custom methods */
setComment: function (itemId, itemComment){
let items = this.getSetting('items', {});
let item = {
'ID' : String(itemId),
'COMMENT' : itemComment,
};
items[Number(itemId)] = item;
this.setSetting('items', items);
},
setComment2: function (itemId, itemComment, itemCommentDatePay){
let items = this.getSetting('items', {});
let item = {
'ID' : String(itemId),
'COMMENT' : itemComment,
'COMMENT_DATE_PAY' : itemCommentDatePay,
};
items[Number(itemId)] = item;
this.setSetting('items', items);
},
getComment: function (debtId){
let comment = '';
debtId = parseInt(debtId);
let items = this.getSetting('items', {});
let itemKeys = Object.keys(items);
for (let i=0; i<itemKeys.length; i++)
{
let id = parseInt( itemKeys[i]);
let item = items[id];
if(id === debtId)
{
comment = item['COMMENT'];
return comment;
}
}
// если не нет нужного items[debtId], то достаем из таблицы
let gridId = this.getSetting('gridId', '');
let objComment = BX(gridId + '_comment_' + (debtId));
if($(objComment).data('empty') === 'true')
return '';
if(objComment !== null && typeof objComment !== 'undefined')
comment = BX.html(BX(gridId + '_comment_' + (debtId)));
return comment;
},
getCommentDatePay: function (debtId){
let commentDatePay = '';
debtId = parseInt(debtId);
let items = this.getSetting('items', {});
let itemKeys = Object.keys(items);
for (let i=0; i<itemKeys.length; i++)
{
let id = parseInt( itemKeys[i]);
let item = items[id];
if(id === debtId)
{
commentDatePay = item['COMMENT_DATE_PAY'];
return commentDatePay;
}
}
// если не нет нужного items[debtId], то достаем из таблицы
let gridId = this.getSetting('gridId', '');
// CRMDEBTS_LIST_comment_date_pay_535
let objCommentDatePay = BX(gridId + '_comment_date_pay_' + (debtId));
if(objCommentDatePay !== null && typeof objCommentDatePay !== 'undefined')
commentDatePay = BX(gridId + '_comment_date_pay_' + (debtId)).value;
return commentDatePay;
},
saveComment: function(debtId){
if(typeof parseInt(debtId) == 'undefined' || parseInt(debtId) === 0)
{
this.error({'ERROR': BX.message('JS_W4A_ACTION_DEBT_ID_IS_EMPTY')});
return;
}
let self = this;
let comment = this.getComment(debtId);
let commentDatePay = this.getCommentDatePay(debtId);
let title = BX.message('JS_W4A_COMMENT_TITLE');
let commentFieldLabel = BX.message('JS_W4A_COMMENT_FIELD_LABEL');
let commentDatePayFieldLabel = BX.message('JS_W4A_COMMENT_DATE_PAY_FIELD_LABEL');
let uniqPrefix = 'w4a-se t-comment';
let content = `
<div style="padding: 5px;" id="`+uniqPrefix+`-container">
<div data-name="w4a-edit" class="">
<span class="w4a-field-label">`+commentDatePayFieldLabel+`</span>
<div class="ui-ctl ui-ctl-textbox">
<input id="`+uniqPrefix+`-item-comment-date-pay" type="date" value="`+commentDatePay+`" class="ui-ctl-element" placeholder="" autocomplete="off">
</div>
<span class="w4a-field-label">`+commentFieldLabel+`</span>
<div class="ui-ctl ui-ctl-textarea">
<textarea id="`+uniqPrefix+`-item-comment" class="ui-ctl-element">`+comment+`</textarea>
</div>
</div>
</div>`;
BX.UI.Dialogs.MessageBox.show(
{
message: content,
title: title,
minWidth: 600,
maxWidth: 860,
buttons: BX.UI.Dialogs.MessageBoxButtons.OK_CANCEL,
onOk: function(messageBox)
{
let comment = BX(uniqPrefix+'-item-comment').value;
let commentDatePay = BX(uniqPrefix+'-item-comment-date-pay').value;
let postData = {
'MODE': 'SET_COMMENT',
'OWNER_TYPE': self.getSetting('ownerType', ''),
'PERMISSION_ENTITY_TYPE': self.getSetting('permissionEntityType', ''),
'SITE_ID': self.getSetting('siteId', ''),
'sessId': self.getSetting('sessId', ''),
'DEBT_ID': debtId,
'COMMENT': comment,
'COMMENT_DATE_PAY': commentDatePay,
};
BX.ajax({
'url': self._serviceUrl,
'method': "POST",
'dataType': "json",
'data': postData,
onsuccess: BX.delegate(self._onActionRequestSuccess, self),
onfailure: BX.delegate(self._onActionRequestFailure, self)
});
messageBox.close();
},
}
);
},
actionExportExcelByMonth: function()
{
if(this._flagExportExcelByMonth)
{
// приводим в первоначальные состояния
this.setSelectorsDefault();
}
else{
this._flagExportExcelByMonth = true;
}
BX.show(BX("CRMDEBTS_TOOLBAR_actionsMenu2"));
BX.show(BX("CRMDEBTS_TOOLBAR_actionsMenu3"));
},
actionSelectYear: function(y)
{
let obj = BX("CRMDEBTS_TOOLBAR_actionsMenu2");
$(obj).html('' + y);
this._year = parseInt(y);
if(this._month > 0)
this.setSelectExport();
},
actionSelectMonth: function(mon)
{
let obj = BX("CRMDEBTS_TOOLBAR_actionsMenu3");
if(mon<10)
$(obj).html('0' + mon);
else
$(obj).html('' + mon);
this._month = parseInt(mon);
if(this._year > 0)
this.setSelectExport();
},
setSelectExport: function()
{
// alert('tutut')
let byMon = '';
let y = this._year;
let mon = this._month;
if(y === 0 || mon === 0)
return false;
if(mon<10)
byMon = y + '-0' + mon;
else
byMon = y + '-' + mon;
let obj = $('#popup-window-content-menu-popup-CRMDEBTS_TOOLBAR_actionsMenu4_menu .menu-popup-items');
let items = $(obj).find('.menu-popup-item');
let isNoData = true;
for (let i=0; i<items.length; i++)
{
// alert('tutut-' + i)
let item = items[i];
let title = $(item).attr('title')
if(title === byMon) {
$(item).css('display', 'block');
isNoData = false;
}else if(title === '0000-00' && isNoData)
{
$(item).css('display', 'block');
}
else {
$(item).css('display', 'none');
}
}
if(isNoData)
{
}
BX.show(BX("CRMDEBTS_TOOLBAR_actionsMenu4"));
},
setSelectorsDefault: function()
{
this._year = 0;
this._month = 0;
$(BX("CRMDEBTS_TOOLBAR_actionsMenu2")).html(BX.message("CRMDEBTS_ACTIONS_NAME_2"));
$(BX("CRMDEBTS_TOOLBAR_actionsMenu3")).html(BX.message("CRMDEBTS_ACTIONS_NAME_3"));
BX.hide(BX("CRMDEBTS_TOOLBAR_actionsMenu4"));
},
/** Test methods */
getTest: function(){
alert('BX.W4aDebtList.getTest();');
},
};
BX.W4aDebtList.create = function (id, config)
{
let self = new BX.W4aDebtList();
self.initialize(id, config);
return self;
};
}
$(document).ready(function(){
let items = ['a','c','d','s','summary'];
$('tr.w4a-filter-1').click(function(){
let chartId = 'w4a-chart-debt';
let companyId = $(this).data('company');
for (let i=0; i < items.length; i++)
{
let objChart = BX(chartId + '-' + items[i]);
let objTr = $('.w4a-filter-1[data-company="'+items[i]+'"]');
if(items[i] === companyId) {
$(objChart).closest('.w4a-chart').removeClass('w4a-hidden');
$(objTr).addClass('active');
}
else {
$(objChart).closest('.w4a-chart').addClass('w4a-hidden');
if($(objTr).hasClass('active'))
$(objTr).removeClass('active');
}
}
});
$('#select-chart-2').change(function(){
let chartId = 'w4a-chart-delay';
let companyId = $(this).val();
if(companyId === 0)
return false;
for (let i=0; i < items.length; i++)
{
let objChart = BX(chartId + '-' + items[i]);
let objTable = $('#w4a-chart-delay-table-'+items[i]);
if(items[i] === companyId) {
$(objChart).closest('.w4a-chart').removeClass('w4a-hidden');
$(objTable).removeClass('w4a-hidden');
}
else {
$(objChart).closest('.w4a-chart').addClass('w4a-hidden');
$(objTable).addClass('w4a-hidden');
}
}
});
$('#w4a-show-losers').click(function(){
BX.show(BX('w4a-losers-table'));
})
}) |