Skip to content

Instantly share code, notes, and snippets.

@DmitryDmitrienko
Created May 17, 2017 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DmitryDmitrienko/1d173758008f8ef99cbd8a545dfeb090 to your computer and use it in GitHub Desktop.
Save DmitryDmitrienko/1d173758008f8ef99cbd8a545dfeb090 to your computer and use it in GitHub Desktop.
;BX.ready(function () {
var dlg = null;
var dealId = 0, matches = null;
var halfName = '-ivddeal';
var nameSection = '5-spisok-kreditorov-pri-rabote-s-dannym-klientom-';
var find = null;
if (matches = window.location.href.match(/\/crm\/deal\/edit\/([\d]+)\//i)) {
dealId = parseInt(matches[1]);
} else if (matches = window.location.href.match(/\/crm\/deal\/show\/([\d]+)\//i)) {
dealId = parseInt(matches[1]);
}
var nameDlg = 'ivSendInvite';
if (window[nameDlg]) {
dlg = window[nameDlg];
} else {
dlg = window[nameDlg] = new BX.PopupWindow(nameDlg, null, {
closeIcon: {right: "20px", top: "10px"},//Иконка закрытия
titleBar: {
content: BX.create(
"span",
{
html: '<h2>Пригласить клиента</h2>',
'props': {'className': 'title-bar'}
}
)
},//Название окна
offsetLeft: 0,
offsetTop: 0,
draggable: {restrict: true},//Окно можно перетаскивать на странице
overlay: {backgroundColor: 'black', opacity: '80'}, /* затемнение фона */
buttons: [
new BX.PopupWindowButton({
text: 'Отправить',
className: 'webform-small-button-accept',
events: {
'click': function (event) {
BX.ajax({
url: '/ajax/ajax_iv_officebtn_invite_office.php',
method: 'POST',
data: {'id': dealId},
dataType: 'json',
async: false,
processData: false,
onsuccess: function (e) {
e = JSON.parse(e);
console.log(e);
}
});
}
}
}),
new BX.PopupWindowButton({
text: 'Закрыть',
events: {
'click': function (event) {
this.popupWindow.close();
}
}
})
]
});
}
if (dealId > 0) {
find = nameSection + dealId + halfName;
var firthSection = BX.findChild(BX('workarea-content'), {
'tag': 'tr',
'class': 'tr-tab-name',
'attribute': {'data-codesection': find}
}, true)
if (firthSection) {
var bodyAdd = BX.findParent(BX(firthSection), {'tag': 'tbody'});
BX.append(BX.create('tr', {
attrs: {
'class': 'crm-offer-row',
'data-section': find
},
style: {
'display': 'none'
},
children: [
BX.create('td', {
attrs: {'class': 'crm-offer-info-right'},
children: [
BX.create(
'span', {
attrs: {'class': 'webform-button webform-button-create'},
children: [
BX.create('input',
{
attrs: {
'class': 'webform-button-text',
'value': 'Пригласить клиента',
'type': 'button'
}
}
)
],
style: {'float': 'right', 'margin-right': '25%'},
events: {
click: BX.proxy(function () {
BX.ajax({
url: '/ajax/ajax_iv_officebtn_check_invite.php',
method: 'POST',
data: {'id': dealId},
dataType: 'json',
async: false,
processData: false,
onsuccess: function (e) {
e = JSON.parse(e);
BX.cleanNode(BX('popup-window-content' + nameDlg), false);
if (e.ok) {
// подставляем контет для ввода даты
dlg.setContent(BX.create(
'input',
{
attrs: {
'class': 'field datetime',
'type': 'text',
'name': 'invite-date'
},
events: {
click: BX.proxy(function () {
console.log(BX.proxy_context);
var calendar = BX.calendar({
node: BX.proxy_context,
field: 'invite-date',
bTime: true,
bHideTime: false,
});
}, this)
}
})
);
} else {
dlg.setContent('<p style="color:red">' + e.message + '</p>');
}
if (dlg && !dlg.isShown()) {
dlg.show();
}
},
onfailure: function (e) {
}
});
}, this)
}
}
)
]
})
]
}), bodyAdd);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment