/************************************* * SPDX-FileCopyrightText: 2009-2020 Vtenext S.r.l. * SPDX-License-Identifier: AGPL-3.0-only ************************************/ /* crmv@43864 - functions used by the new Link/Create Popup */ /* crmv@82831 crmv@121616 */ // Object which contains methods used by the new Popup var LPOP = { module: '', /* * take some global vars from the parent window */ setGlobalVars: function() { var vars = ['userDateFormat', 'SDKValidate', 'alert_arr', 'decimal_separator','thousands_separator','decimals_num']; // crmv@196061 for (var i=0; i 0 ? '&'+extraInputs : ''), type: 'POST', complete: function() { me.hideActivity(); }, success: function(data) { if (!data) return alert(alert_arr.ERROR+': '+data); try { var ret = jQuery.parseJSON(data); } catch (e) { return alert(alert_arr.ERROR+': '+data); } var activityid = ret.activityid; if (!activityid) return alert(alert_arr.ERROR+': '+data); // call callback (don't close popup if return false) if (typeof callback == 'function') { var r = callback(ret); if (r === false) return } parent.reloadTurboLift(parent_module, parentid, 'Activities'); //crmv@52561 me.close_popup(true, parent_module, parentid); }, error: function() { alert(alert_arr.ERROR); } }); } }, /* * Params: * recordid : the starting record to link the selected entity * mode : a string indicating the operating mode * extraParams : object (key/values) passed in the request * opener : the window that opens the popup (current window if omitted) * TODO: callback */ openPopup: function(module,id, mode, extraParams, opener) { if (!extraParams) extraParams = {}; if (mode == 'addsender' || mode == 'addrecipient') { extraParams['show_only'] = 'create'; extraParams['onlypeople'] = 'true'; } else if (mode == 'onlycreate') { extraParams['show_only'] = 'create'; } else if (mode == 'compose') { // get ids of recipients var idlist = []; jQuery('#autosuggest_to .addrBubble').each(function(index, item) { var parts = item.id.split('_'); idlist.push(parts[1]); }); extraParams['idlist'] = idlist.join(';'); } else if (mode == 'linkrecord' && !id) { extraParams['show_only'] = 'link'; } var params = { 'module': 'Popup', 'action' : 'PopupAjax', 'file' : 'index', 'from_module': module, 'from_crmid' : id, 'mode': mode, }; // GLOBAL VAR: ugly trick to have a reference to the opener window popup_opener = opener || window; if (extraParams['file'] != undefined) { params['file'] = extraParams['file']; } if (extraParams && !jQuery.isEmptyObject(extraParams)) { jQuery.extend(params, extraParams); } openPopup('index.php?'+jQuery.param(params),"Popup","width=750,height=602,menubar=no,toolbar=no,location=no,status=no,resizable=no,scrollbars=yes"); }, // crmv@56603 clickLinkModule: function(module, clickaction, relation_id) { var me = LPOP, file, action = (clickaction ? clickaction : jQuery('#default_link_action').val()), listCont = jQuery('#linkMsgListCont'), editCont = jQuery('#linkMsgEditCont'); if (typeof(gVTModule) != 'undefined' && gVTModule != module) jQuery('#sdk_view_all').val(''); //crmv@48964 gVTModule = module; // sset the class jQuery('#linkMsgModTab .linkMsgModTdSelected').removeClass('linkMsgModTdSelected'); jQuery('#linkMsgModTab #linkMsgMod_'+module).addClass('linkMsgModTdSelected'); if (action == 'create') { return me.showCreatePanel(0, module); //crmv@43942 } else if (action == 'list') { file = 'LinkList'; } else { file = action; } //crmv@43942e var params = { 'module': 'Popup', 'action' : 'PopupAjax', 'file' : file, //crmv@43942 'mod' : module, 'relation_id' : parseInt(relation_id), }; me.showActivity(); jQuery.ajax({ url: 'index.php', type: 'POST', data: jQuery.param(params) + '&' + jQuery('#extraInputs').serialize(), complete: function() { me.hideActivity(); }, success: function(data) { listCont.hide(); jQuery('#linkMsgDescrCont').hide(); destroySlimscroll('linkMsgDetailCont'); destroySlimscroll('linkMsgEditCont'); jQuery('#linkMsgDetailCont').hide(); editCont.hide(); listCont.html(data).fadeIn('fast'); } }); }, showCreatePanel: function(listid, mod, relation_id) { var me = LPOP, module = (mod ? mod : SLV.get_module(listid)), show_create_note = (mod ? 'yes' : 'no'), //crmv@46678 descrCont = jQuery('#linkMsgDescrCont'), listCont = jQuery('#linkMsgListCont'), editCont = jQuery('#linkMsgEditCont'), attachCont = jQuery('#linkMsgAttachCont'); var params = { 'module': 'Popup', 'action' : 'PopupAjax', 'file' : 'CreateForm', 'mod' : module, 'show_create_note' : show_create_note, //crmv@46678 'relation_id' : parseInt(relation_id), }; me.showActivity(); descrCont.hide(); listCont.hide(); jQuery.ajax({ url: 'index.php', type: 'POST', data: jQuery.param(params) + '&' + jQuery('#extraInputs').serialize(), success: function(data) { editCont.height(jQuery('#linkMsgRightPaneTop').height()); editCont.html(data); // set magic scrolling jQuery('#linkMsgEditCont').slimScroll({ wheelStep: 10, height: editCont.height()+'px', width: '100%' }); editCont.fadeIn('fast'); attachCont.fadeIn('fast'); }, complete: function() { me.hideActivity(); } }); }, // crmv@56603e select: function(listid, module, crmid, entityname) { var me = LPOP, parent_mod = jQuery('#parent_module').val(), callback_link = jQuery('#callback_link').val(), descrCont = jQuery('#linkMsgDescrCont'), listCont = jQuery('#linkMsgListCont'), detailCont = jQuery('#linkMsgDetailCont'), editCont = jQuery('#linkMsgEditCont'), attachCont = jQuery('#linkMsgAttachCont'); var params = { 'module': 'Popup', 'action' : 'PopupAjax', 'file' : 'DetailForm', 'mod' : module, 'record' : crmid, }; me.showActivity(); descrCont.hide(); listCont.hide(); jQuery.ajax({ url: 'index.php', type: 'POST', data: jQuery.param(params) + '&' + jQuery('#extraInputs').serialize(), complete: function() { me.hideActivity(); }, success: function(data) { detailCont.height(jQuery('#linkMsgRightPaneTop').height()); detailCont.html(data); // set magic scrolling jQuery('#linkMsgDetailCont').slimScroll({ wheelStep: 10, height: detailCont.height()+'px', width: '100%' }); detailCont.fadeIn('fast'); attachCont.fadeIn('fast'); } }); }, // crmid can be an array of ids link: function(module, crmid, entityname) { var me = LPOP, parent_module = jQuery('#from_module').val(), parentid = jQuery('#from_crmid').val(), mode = jQuery('#popup_mode').val(); // crmv@202577 var selectedTargets = null; if (parent_module === 'Campaigns' && module === 'Targets') { selectedTargets = crmid; } if (selectedTargets !== null) { jQuery.ajax({ url: 'index.php?module=Targets&action=TargetsAjax&ajax=true&file=GetData', data: { 'parent_id': parentid, 'parent_module': parent_module, 'ids': selectedTargets, 'get_tm_total_count': '1', }, type: 'GET', success: function(res) { if (res.length > 0) { var parts = res.split('###'); var limit = Number(parts[1]); var count = Number(parts[0]); if (limit < count) { vtealert(alert_arr.LBL_MASS_CREATE_ENQUEUE_TELEMARKETING.replace('{max_records}', limit), function() { linkValidationCallback(); }); } else { linkValidationCallback(); } } else { linkValidationCallback(); } } }); } else { linkValidationCallback(); } // crmv@202577e function linkValidationCallback() { me.showActivity(); if (mode == 'compose') { // TOODO!!! jQuery.ajax({ url: 'index.php?module=Utilities&action=UtilitiesAjax&file=Card', // crmv@137471 data: '&idlist='+crmid, type: 'POST', success: function(data, status, xhr) { //if (!data.match(/error/i)) { //alert(alert_arr.LBL_MESSAGE_LINKED); window.parent.jQuery('#ComposeLinks').append(data); if (crmid.length > 0) crmid = crmid.join('|'); //crmv@86304 window.parent.jQuery('#relation').val(window.parent.jQuery('#relation').val()+'|'+crmid); me.close_popup(false); //} }, complete: function() { me.hideActivity(); } }); } else { // crmv@43050 linkModules(parent_module, parentid, module, crmid, { 'mode' : mode }, function(data) { if (!data.substr(0,100).match(/error/i)) { //alert(alert_arr.LBL_MESSAGE_LINKED); //crmv@55506 if (parent_module == 'ModComments') { commentsLinkModule(module, crmid); //crmv@55506e } else if (parent_module == 'PBXManager') { parent.location.reload(); } else if (parent_module == 'Messages') { var attList = getAttachmentsToLink(); window.parent.jQuery('#flag_'+parentid+'_relations').show(); if (mode == 'linkdocument') { window.parent.saveDocument(parentid,jQuery('#contentid').val(),crmid,module); } else if (attList.length > 0) { for (var i=0; i').attr({ type: 'hidden', name: 'am_I_in_popup', value: 'yes' }).appendTo('form[name="EditView"]'); if (isInventoryModule(module)) { settotalnoofrows();calcTotal(); //crmv@72922 var valid = validateInventory(module); } else { var valid = formValidate(document.EditView); } if (module == 'Accounts'){ if (isdefined('external_code')){ var ext = getObj('external_code').value; var exttype = getObj('external_code').type; if ( (trim(ext) != '') && (exttype != "hidden") ) { if (!AjaxDuplicateValidateEXT_CODE(module,'external_code','','editview')) valid = false; } } } if (!valid) return; me.showActivity(); me.module = module; jQuery('form[name="EditView"]').ajaxSubmit( { success: me.successCreate, error: me.successCreate } ); //crmv@45933 }, successCreate: function(data, status, xhr, $form) { var me = LPOP; if (!data || status != 'success') { me.hideActivity(); return alert(alert_arr.ERROR+': '+data); } // AARRRGHH! the only way to get the recordid is to parse all the response var searchStr = '