function applyInputFilters() { applyMoneyInputs(); applyPercentInputs(); ApplyDatePickers(); applyValueHook(); } function applyValueHook() { $.valHooks.input = { get: function( elem ) { if( $(elem).hasClass('moneyInput')) { return Number(String(elem.value).replace('$','').replace(/[,]/g,'')); } else { if( $(elem).hasClass('percentInput')) { return Number(String(elem.value).replace('%','').replace(/[,]/g,'')); } else { return elem.value; } } }, set: function(elm,value) { if( $(elm).hasClass('moneyInput')) { if(value) { elm.value = formatCurrency(value); } else { elm.value = '$0.00'; } } else { if( $(elm).hasClass('percentInput')) { if(value) { elm.value = String(value).replace('%','') + '%'; } else { elm.value = '0%'; } } else { elm.value=value; } } return true; } } }; function applyMoneyInputs() { $('.moneyInput').autoNumeric('init',{aSign: '$', wEmpty: 'zero', lZero: 'deny'}); $('.moneyInput').not('[placeholder]').attr('placeholder','$0.00'); $('.moneyInput').off('focusout'); applyValueHook(); } function applyPercentInputs() { $('.percentInput').autoNumeric('init',{mDec: '2', aPad: true, aDec: '.',eDec: true , aSign: '%',pSign: '%', wEmpty: 'zero', lZero: 'deny', vMax: 100, vMin:0}); $('.percentInput').not('[placeholder]').attr('placeholder','0%'); $('.percentInput').off('focusout'); applyValueHook(); } var datePickerOptions = {}; function ApplyDatePickers() { if(window.top.checkDateInput() == false){$( "input[type=date]" ).datepicker(datePickerOptions);} $('.datepicker').datepicker(datePickerOptions).on('changeDate', function() { $(this).val( $(this).datepicker('getFormattedDate')); }); } function showFileUpload(obj,callback) { if(callback){window.top.FileUploadedEvent = callback}; var t = window.top.$('#FileUploadIFrame').contents(); if ( $(obj).attr('endpoint') == undefined ){ $(obj).attr('endpoint','/STP/UploadFile') }; if ( $(obj).attr('data-successMsg') == undefined ){ $(obj).attr('data-successMsg','File(s) uploaded') }; if ( $(obj).attr('data-successFail') == undefined ){ $(obj).attr('data-successFail','There was an error while uploading the file(s), err:') }; if( $(obj).attr('endpoint') != undefined && typeof($(obj).attr('endpoint')) != 'undefined') {t.find('#UploadFileForm').attr('endpoint',$(obj).attr('endpoint'));t.find('#UploadFileForm').attr('action',window.top.myEndPoint +$(obj).attr('endpoint') + window.top.Beta + '?OrionSessionKey=' + window.top.MainApp.OrionSessionKey );}; if( $(obj).attr('data-successMsg') != undefined && typeof($(obj).attr('data-successMsg')) != 'undefined') {t.find('#successMsg').attr('value',$(obj).attr('data-successMsg'))}; if( $(obj).attr('data-successFail') != undefined && typeof($(obj).attr('data-successMsg')) != 'undefined') {t.find('#successFail').attr('value',$(obj).attr('data-successFail'))}; if( $(obj).attr('data-showmsg') != undefined && typeof($(obj).attr('data-showmsg')) != 'undefined') {t.find('#hideMsg').attr('value',$(obj).attr('data-showmsg'))}; if( $(obj).attr('data-accepts') != undefined && typeof($(obj).attr('data-accepts')) != 'undefined') {t.find('#FileUploadInput').attr('accept',$(obj).attr('data-accepts'))}else{t.find('#FileUploadInput').attr('accept','')}; $(obj).addClass('waitingFileUpload'); if( $(obj).is('input') == false ) { //we are not an input //find out input if( $(obj).attr('for') != undefined ) { $('input[name="' + $(obj).attr('for') + '"]').addClass('waitingFileUpload'); $('#' + $(obj).attr('for') ).addClass('waitingFileUpload'); } else { //let's find the nearest input with .fileinput $(obj).closest('div, tr').find('.fileupload').addClass('waitingFileUpload'); } } t.find('#FileUploadInput').trigger('click'); } function ApplyFileUploadListener(id) { if(!id){var id = '.FileUpload'}; $(id).on('click',function() { showFileUpload(this); }); } //formatCurrency(value) - returns $0.00 formatted or if value is blank will update all .currency nodes //isJSON(str) - returns true/false if string is json function formatPercent(value) { if(value) { return numeral(Number(value)).format('0.00%'); } else { $('.percent').each(function() { var f = $(this).attr('data-format'); if(!f){f = '0.00%'}; $(this).html(numeral( Number($(this).html()) ).format(f)); }); } } function formatNumbers(value) { $('.two-decimals').each(function() { var n = Number($(this).html()).toFixed(2); if( $(this).hasClass('percentage') == true) { n = n + '%'; } $(this).html(n); }); } function formatCurrency(value,f) { try { if(typeof value !== 'undefined') { if(!f){var f = '$0,0.00'}; return numeral(value).format(f); } else { $('.currency').each(function() { if(!f){var f = $(this).attr('data-format')}; if(!f){f = '$0,0.00'}; $(this).html(numeral($(this).html()).format(f)); $(this).val(numeral($(this).val()).format(f)); }); } } catch(err) { //ignore //console.log('error'); } } function formatCurrencyShort(value,f) { if(value) { if(!f) { var suffix = ''; switch (true) { case (value > 99999 && value < 999999): suffix = 'K'; value = value / 1000; break; case (value > 999999 && value < 999999999 ): suffix = 'M'; value = value / 1000000 break; case (value > 999999999 ): suffix = 'B'; value = value / 1000000000 break; } return numeral(value).format('$0,0.0').replace('.0','') + suffix; } else { return numeral(value).format(f); } } else { $('.currencyShort').not('.updated').each(function() { var f = $(this).attr('data-format'); var value = cNumber( $(this).html()); if(!f) { var suffix = ''; switch (true) { case (value > 99999 && value < 999999): suffix = 'K'; value = value / 1000; break; case (value > 999999 && value < 999999999 ): suffix = 'M'; value = value / 1000000 break; case (value > 999999999 ): suffix = 'B'; value = value / 1000000000 break; } $(this).html( numeral(value).format('$0,0.0').replace('.0','') + suffix); } else { $(this).html( numeral(value).format(f)); } $(this).addClass('updated'); }); } } function formatDate(i) { if(i) { var y = new Date(i); return y.toDateString(); } else { $('.formatDate').each(function() { if( $(this).is('input,select')) { var x = $(this).val(); var y = new Date(x); if( x != '') { $(this).val( y.toDateString()); } } else { var x = $(this).html(); var y = new Date(x); if( x != '') { $(this).html(y.toDateString()); } } }); } } function isJson(str) { if( String(str).length == 0 || str == 'null' || str == null){return false;} try { JSON.parse(str); return true; } catch (e) { return false; } } // Returns a function, that, as long as it continues to be invoked, will not // be triggered. The function will be called after it stops being called for // N milliseconds. If `immediate` is passed, trigger the function on the // leading edge, instead of the trailing. function debounce(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }; /* const debounce = (func, wait) => { let timeout; return function executedFunction(arg1,arg2,arg3,arg4,arg5,arg6) { const later = () => { clearTimeout(timeout); func(arg1,arg2,arg3,arg4,arg5,arg6); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; }; */ function doEventsOnYield(generator) { return new Promise((resolve, reject) => { let g = generator(); let advance = () => { try { let r = g.next(); if (r.done) resolve(); } catch (ex) { reject(ex); } setTimeout(advance, 0); }; advance(); }); } function obj2URI(obj) { var URI = ''; var keys = Object.keys(obj); for(var i = 0; i < keys.length; i++) { URI = URI + '&' + keys[i] + '=' + escape(obj[keys[i]]); } return URI; } function ArrayToExcel(data,filename) { var rows = []; var keys = Object.keys(data[0]); var row = []; for(i in keys) { row.push({value: keys[i]}); } rows.push({cells: row}); for(i in data) { var row = []; for(ii in keys) { row.push({value: data[i][keys[ii]]}); } rows.push({cells: row}); } //console.log(rows); var workbook = new kendo.ooxml.Workbook({sheets: [{rows: rows}] }); kendo.saveAs({dataURI: workbook.toDataURL(), fileName: filename}); } function createDownload(content,header,filename) { var element = document.getElementById('downloadPDFLink'); element.setAttribute('href', header + encodeURI(content)); element.setAttribute('download', filename); element.click(); } function uuidv4() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } function showHelp(oAdminVideoLink,oVideoLink) { if(!oAdminVideoLink){oAdminVideoLink = window.AdminVideoLink}; if(!oVideoLink){oVideoLink= window.VideoLink}; var VideoLink = oVideoLink; if(window.top.MainApp.isAdmin==true) { if(oAdminVideoLink) { //we are good if(oAdminVideoLink != '') { VideoLink = oAdminVideoLink; } } } if(window.VideoLink) { if(window.VideoLink != '') { //window.top.swal.fire({html:'
Still have questions? Click to chat with a member of our team
',height: '50%',width:'50%',showConfirmButton:false}) window.top.swal.fire({html:'

Still have questions? Call: ' + window.top.Firm.SupportPhone + '

',height: '50%',width:'50%',showConfirmButton:false}) } else { window.top.Alert('Please call: ' + window.top.Firm.SupportPhone +' for support.'); //window.top.startChat(); } } else { window.top.Alert('Please call: ' + window.top.Firm.SupportPhone +' for support.'); //window.top.startChat(); } } //this is our local storage module var lStorage = { getEpoch: function() { var d = new Date(); return d.getDate(); }, getItem: function(key) { //see if the item is in local storage //if it is see if it has expired var r = { results: false}; if(window.localStorage) { var i i = localStorage.getItem(key); if( isJSON(i) == true) { //we are json i = JSON.parse(i); if(i.ttl) { //we have an expiration if(i.ttl > lStorage.getEpoch()) { //we are still valid return { results: true, data: LZString.decompress(i.data) } } else { //data has expired return { results: false }; } } else { return { results: false }; } } else { return { results: false }; } } else { return { results: false }; } }, addItem: function(key,item,ttl) { if(!ttl){var ttl = lStorage.getEpoch() + 86400000}else{ttl = ttl + lStorage.getEpoch()}; if(window.localStorage) { //we exists var r = { ttl: ttl, data: LZString.compress(item) }; localStorage.setItem(key, JSON.stringify(r)); return true; } else { return false; } } } function CreateLink(msg,find,type) { switch(type) { case 'ticket': return String(msg).replace(find,'' + find + ''); break; } } function dialog(title,placeholder,callback,height) { if(!placeholder){var placeholder = ''}; return new Promise((resolve, reject) => { var d ={title: title,input: 'text', showCancelButton: true, reverseButtons: true, inputValue: placeholder, defaultValue: placeholder, inputValidator: (value) => { if (!value) { return 'Please enter in a value!' }}}; if(height) { if(height != '3em' && height != '2em' && height != '') { d.input = 'textarea' } } window.top.pCallback = callback; window.top.swal.fire(d).then(function(results) { if(results.isConfirmed) { if(window.top.pCallback) { window.top.$('#confirm .confirmtext').val(results.value) window.top.pCallback(results.value); } resolve(results.value); } else { reject(results); } }); }); } //version 2.0 5.20.2021 bruce redone var kendoGridFunctions = { recordsInViewDS: {}, fullRecordLookup: {}, applySelectFunction: function(grid) { $(grid).on('click', 'td', kendoGridFunctions.selectFn); $(grid).on("filter", kendoGridFunctions.filterFunc); $(grid).on("sort", kendoGridFunctions.sortFunc); $(grid).attr('data-e-uid',uuidv4()); }, // When the user either filters or sorts, clear all the caches data structures // filterFunc: function(e) { kendoGridFunctions.recordsInViewDS[UID] = null; kendoGridFunctions.fullRecordLookup[UID] = null; e.sender.dataSource.lastActive = false; }, sortFunc: function(e) { kendoGridFunctions.recordsInViewDS[UID] = null; kendoGridFunctions.fullRecordLookup[UID] = null; e.sender.dataSource.lastActive = false; }, selectFn: function(e) { let startTime = Date.now(); if($(this).closest('.k-grid').hasClass('dontListen')) { return false; } let dataSource = $(this).closest('.k-grid').data('kendoGrid').dataSource; let curRow = dataSource.getByUid( $(this).closest('tr').attr('data-uid')); let grid = $(this).closest('.k-grid').data('kendoGrid'); let UID = $(this).closest('.k-grid').attr('data-e-uid'); // If we are selecting and we don't have a cache for the view or full records // then buid this structure if (!kendoGridFunctions.recordsInViewDS[UID]) { let allRecords = dataSource.data(); kendoGridFunctions.recordsInViewDS[UID] = new kendo.data.DataSource.create({data: allRecords, filter: dataSource.filter(), sort: dataSource.sort(), schema: dataSource.options.schema}); kendoGridFunctions.recordsInViewDS[UID].pageSize(allRecords.length) recordsInView = kendoGridFunctions.recordsInViewDS[UID].view(); kendoGridFunctions.fullRecordLookup[UID] = {}; let rec = null; for (let i=0; i total) { end = total } grid.clearSelection(); // Loop through each record in our recordsInView // and we are going to add the id for the record // to our selection for(let RecordNumber = start; RecordNumber < end; RecordNumber++) { let curRow = recordsInView[RecordNumber]; if(curRow) { // Add to the grids selected list grid._selectedIds[curRow.id]=true; // Find the record in the full list of records let originalRecord = kendoGridFunctions.fullRecordLookup[UID][curRow.id]; if(originalRecord.uid) { $('tr[data-uid="' + originalRecord.uid + '"]').addClass('k-state-selected'); } } else { // We are a phantom, just ignore } } } else { // No shift key. Could be start of multi select or just a single selection dataSource.lastActive= recordsInView.indexOf(curRow); if (!e.originalEvent.ctrlKey && !e.originalEvent.shiftKey && $(this).find('.k-checkbox').length == 0) { //console.log('resetting'); grid._selectedIds = {}; grid.clearSelection(); } grid.select( $(this).closest('tr') ); } } } $.fn.autocomplete = function(param) { //add loader icon //this.replaceWith('
' + $(this)[0].outerHTML + '
'); var el = $(this); if(el.is('input')==false){el = el.find('input')}; if( param.html) { el.attr('data-html',true) } else { el.attr('data-html',false) } //  $(el).autoComplete({ resolver: 'custom', events: { typed: function(newValue, origJQElement) { if(param.search) { param.search(newValue.replace(/ /g,' ')); } return newValue; }, freevalue: function(e,qry) { if(param.search) { param.search(qry.replace(/ /g,' ')); } }, search: debounce(function(qry,callback) { var $this=$(this); //sow loader icon //this.closest('div').find('.loadingIcon').show(); if(param.search) { param.search(qry.replace(/ /g,' ')); } //do search var s = param.source; if(typeof(s) == 'function'){s = s()}; $.ajax( { url: s + '&term=' + escape(qry), dataType: 'json', method: 'GET', qry: qry, obj: el }).done(function (res) { //convert and return //we will get a [{label,value}] var output = []; for(i in res) { if(param['html'] == true) { output.push({value: res[i].value, text: res[i].label ,record: res[i]}); } else { output.push({value: res[i].value, text: res[i].label.replace(/ /g,' '),record: res[i]}); } } $(this.obj).closest('div').find('.loadingIcon').hide(); callback(output); }).fail(function() { $(this.obj).closest('div').find('.loadingIcon').hide(); }); },300) } }).on('autocomplete.select',function(e,i) { i.text = i.text.replace(/ /g,' '); $(el).val(i.text); $(el).closest('div').find('.loadingIcon').hide(); if(param.select) { param.select(i) } }).addClass('loaded'); }; function ApplyImpersonateUserSearch(id) { if(!id){id='".ImpersonateUserSearch"'}; //load all the users //and show jQuery.ajax({ url: window.top.myEndPoint + '/Firm/ListUsers' + parent.Beta + '?Filters=advisors&OrionSessionKey=' + window.top.MainApp.OrionSessionKey, dataType: 'json', method: 'GET', obj: id }).then(function(data) { if(data.results) { //we have data //show it var i=''; if($(this.obj).attr('placeholder')) { i = i +'placeholder="' + $(this.obj).attr('placeholder') +'"' } if($(this.obj).attr('style')) { i =i + ' style="' + $(this.obj).attr('style') + '"' } $(this.obj).replaceWith( Mustache.render('',data)) $(this.obj).select2({placeholder:'Select an Advisor'}).on('select',function(e) { //console.log('selected'); //console.log(e); }); jQuery.ajax({ url: window.top.myEndPoint.replace('v1','v2') + '/User/GetImpersonateSessionKey' + parent.Beta + '?TargetUser=' + escape(ui.item.value) + '&OrionSessionKey=' + window.top.MainApp.OrionSessionKey, dataType: 'json', error: function(jqXHR, textStatus, errorThrown){parent.ProcessError(jqXHR,textStatus,errorThrown);}, method: 'GET', obj: $(this.obj), success: function(data) { if(data.results) { //we are good $(this.obj).attr('data-sessionkey', OrionSessionKey); $(this.obj).trigger('keyloaded'); } else { window.top.Alert(Title,'There was an error while logging in as the user, please try again. ' + data.msg); } window.top.HideLoading('ImpersonateUser'); } }); return false; } else { } }).fail(function(jqXHR, textStatus) { //request failed if(jqXHR.status == 401) { window.top.ProcessError(jqXHR, textStatus) } else { $(this.obj).remove(); //window.top.Alert('Fusion Elements','There was a system error while saving the profile. If the problem persists please contact support.'); } }); } function UpdateAccount(AccountNumber,ValuesToUpdate) { return jQuery.ajax({ url: window.top.Firm.myEndPoint + '/PM/Sync/Account' + window.top.Firm.Beta + '?AccountNumber=' + escape(AccountNumber) + '&ValuesToUpdate=' + ValuesToUpdate +'&OrionSessionKey=' +window.top.MainApp.SessionKey, dataType: 'json', error: window.top.ProcessError, method: 'GET' }); } function selectAnAdvisor(options) { if(!options){var options = {}}; if(!options.Title){options.Title = 'Create for an Advisor'}; if(!options.Title){options.Prefix = 'Creating for '}; if(!options.DefaultText ){options.DefaultText = 'Create for Advisor'}; window.top.pmSearch.showSearch({Filters:['Users'],ButtonText:'Select',Title:options.Title,autoClose:true,close: function(){ $('#CreateForAdvisor').html(options.DefaultText).removeAttr('data-sessionkey').removeAttr('data-email').trigger('cancel'); },then: function(level,display,email,record){ if(email !='') { //get $('#CreateForAdvisor').html(''); $('#CreateForAdvisor').attr('data-email',email).attr('data-name',display); jQuery.ajax({ url: window.top.myEndPoint.replace('v1','v2') + '/User/GetImpersonateSessionKey' + parent.Beta + '?TargetUser=' + escape(email) + '&OrionSessionKey=' + window.top.MainApp.OrionSessionKey, dataType: 'json', method: 'GET', displayName: display, options: options }).done(function(data) { if(data.results) { $('#CreateForAdvisor').html(this.options.Prefix + this.displayName).attr('data-sessionkey', data.OrionSessionKey).trigger('userloaded'); } else { window.top.Alert('Fusion Elements','There was a system error while logging in as the advisor, error: ' + data.msg); } }).fail(function(jqXHR, textStatus) { //request failed if(jqXHR.status == 401) { window.top.ProcessError(jqXHR, textStatus) } else { window.top.Alert('Fusion Elements','There was a system error while logging in as the advisor, error: ' + textStatus); } }); //console.log(a,b,c,d); } }}); } //see https://jsfiddle.net/ynsbiz/pw6o0unL/11/ //v1.0 1.12.2021 var dDate = { getMonthName: function(d) { if(!d){var d = new Date()}; if(typeof d == 'object'){d = d.getMonth()+ 1}; var Months = ['January','February','March','April','May','June','July','August','September','October','November','December']; return Months[ Number(d)- 1]; }, getFirstDayOfMonthAsDate: function(d) { if(!d){var d = new Date()}; return new Date(d.getFullYear(), d.getMonth(), 1); }, getLastDayOfMonthAsDate: function(d) { if(!d){var d = new Date()}; var lastDay = dDate.getLastDayOfMonth(d); return new Date(d.getFullYear(), d.getMonth(), lastDay); }, getLastDayOfMonth: function (y,m){ if(typeof(y) == 'object'){m = y.getMonth()+1;y = y.getFullYear()} if(!y){var y = dDate.getYear()} if(!m){var m = dDate.getMonth()} m = m -1; return new Date(y, m +1, 0).getDate(); }, getYear: function() { return new Date().getFullYear(); }, getMonth: function() { return new Date().getMonth()+1; }, dateAdd: function(fn,amount,d) { if(!d){var d = new Date();} switch(fn) { case 'MM','M','m','mm': return new Date(d.getFullYear(), d.getMonth() + amount,d.getDate()); } } } function parseForm(selector) { var record = {}; $(selector).find('input,select,textarea').each(function() { record[ $(this).attr('name')] = $(this).val(); }); return record; } function ListAdHocRecords(SecondaryKey,Simple) { if(typeof(Simple) == 'function') { ListAdHocRecords(SecondaryKey,false).then(function(data) { Simple(data) }); return false; } if(Simple === undefined){Simple='true'}; return new Promise((resolve, reject) => { jQuery.ajax({ url: window.top.Firm.myEndPoint.replace('v1','v2') + '/Plugins/AdHocRecord' + window.top.Firm.Beta + '?Simple=' + Simple + '&OrionSessionKey=' +window.top.MainApp.OrionSessionKey + '&SecondaryKey=' + escape(SecondaryKey), dataType: 'json', method: 'GET', SecondaryKey: SecondaryKey, resolve: resolve, reject: reject }).done(function(data) { if(data.results) { this.resolve(data); } else { this.reject(data.msg); } }).fail(function(a,b,c) { window.top.ProcessError(a,b,c); this.reject(b); }); }); } function SaveAdHocRecord(ID,DisplayName,SecondaryKey, Record) { var method = 'POST'; if(ID != ''){ method = 'PUT'}; return new Promise((resolve,reject) => { jQuery.ajax({ url: window.top.Firm.myEndPoint.replace('v1','v2') + '/Plugins/AdHocRecord' + window.top.Firm.Beta + '?ID=' + ID + '&DisplayName=' + escape(DisplayName) +'&OrionSessionKey=' + window.top.MainApp.OrionSessionKey + '&OrionUsername=&OrionPassword=&SecondaryKey=' + escape(SecondaryKey), dataType: 'json', data: JSON.stringify(Record), contentType: 'application/json', method: method, SecondaryKey: SecondaryKey, resolve: resolve, reject: reject }).done(function(data) { if(data.results) { this.resolve(data); } else { this.reject(data.msg); } }).fail(function(a,b,c) { window.top.ProcessError(a,b,c); this.reject(b); }); }); } function GetAdHocRecord(ID,SecondaryKey) { return new Promise((resolve,reject) => { jQuery.ajax({ url: window.top.Firm.myEndPoint.replace('v1','v2') + '/Plugins/AdHocRecord' + window.top.Firm.Beta + '?ID=' + ID + '&OrionSessionKey=' +window.top.MainApp.OrionSessionKey + '&SecondaryKey=' + escape(SecondaryKey), dataType: 'json', method: 'GET', resolve: resolve, reject: reject }).done(function(data) { if(data.results) { if( isJson(data.Record.RAW)) { this.resolve(JSON.parse(data.Record.RAW)); } else { this.resolve({}); } } else { this.reject(data.msg); } }).fail(function(a,b,c) { window.top.ProcessError(a,b,c); this.reject(b); }); }); } if(window.jQuery) { jQuery.fn.CloudStorageLookup = function(options) { //$(this).replaceWith('
' + $(this)[0].outerHTML + '
'); if(!options){var options = {}}; if(!options.Path){options.Path = $(this).find('input').attr('data-path')}; if(!options.Path){options.Path = '/Shared/'}; $(this).autocomplete({ source: window.top.Firm.myEndPoint + '/FileSystem/Autocomplete/ListFolders' + window.top.Firm.Beta + '?Path=' + escape(options.Path) + '&OrionSessionKey=' + window.top.MainApp.OrionSessionKey, select: function(d) { console.log('folder selected'); console.log(d); } }); return this; } } function ApplyCloudStorageFilter(SourceObj, Path,DestObj) { $(DestObj).closest('div').find('.fa-spinner').show(); $(DestObj).closest('div').find('.fa-spinner').addClass('fa-spin') //Path = String(Path).replace(/[\/]/ig,'/'); jQuery.ajax({ url: window.top.Firm.myEndPoint + '/FileSystem/Autocomplete/ListFolders' + window.top.Firm.Beta + '?Path=' + escape(Path) + '&OrionSessionKey=' + window.top.MainApp.OrionSessionKey, dataType: 'json', data: '', error: function(jqXHR, textStatus, errorThrown){parent.ProcessError(jqXHR,textStatus,errorThrown)}, method: 'GET', SourceObj: SourceObj, DestObj: DestObj, success: function(data) { $(this.SourceObj).attr('data-list', JSON.stringify(data)); $(this.SourceObj).attr('title', data.Results.length); $(this.DestObj).closest('div').find('.fa-spinner').hide(); $(this.SourceObj).autocomplete({ source: data.Results, select: function(event,ui) { //alert(ui.item.value); if($(this).attr('data-applyfilterto')) { console.log(Path + '/' +ui.item.value + $('#' + $(this).attr('data-applyfilterto')).attr('data-path')) ApplyEgynteFilter( $('#' + $(this).attr('data-applyfilterto')) , Path + ui.item.value + $('#' + $(this).attr('data-applyfilterto')).attr('data-path'),$('#' +$(this).attr('data-applyfilterto') )); } } }); } }); } function ListenForChanges(RecordType,RecordID, callback) { jQuery.ajax({ url: window.top.myEndPoint.replace('v1','v2') + '/Utilities/Listeners/Listen' + window.top.Beta + '?RecordType=' + escape(RecordType) + '&RecordID=' + escape(RecordID) +'&OrionSessionKey=' + window.top.MainApp.OrionSessionKey, dataType: 'json', timeout: 0, RecordType: RecordType, RecordID: RecordID, Callback: callback, method: 'GET' }).done(function(data) { if(data.results) { this.Callback(); } else { //timeout ListenForChanges(this.RecordType,this.RecordID, this.Callback); } }).fail(function(a,b,c) { window.top.ProcessError(a,b,c); }); } var kendoFunctions = { Plugins: { templates: {} }, nonEditor: function(container, options) { if(options.format) { container.text(kendo.format(options.format, options.model[options.field])); } else { container.text(options.model[options.field]); } container.removeClass("k-edit-cell"); }, generateModel: function(gridData) { var model = {}; model.id = "ID"; var fields = {}; var dateFields = []; for (var property in gridData) { var propType = typeof gridData[property]; if (propType == "number") { fields[property] = { type: "number", editable: false }; } else if (propType == "boolean") { fields[property] = { type: "boolean" , editable: false }; } else if (propType == "string") { var parsedDate = kendo.parseDate(gridData[property]); if (parsedDate) { fields[property] = { type: "date", editable: false }; dateFields.push(property); } else { fields[property] = { editable: false }; } } else { fields[property] = { editable: false }; } } model.fields = fields; return model; }, createFieldDefinitions: function(data,firstRecord,isEditable,buildEditor) { addDisplayTemplate = function(ColumnDefinition,FieldRecord) { var i = 0; var displayClass = String(FieldRecord.displayClasses); for(i in kendoFunctions.Plugins.templates) { ColumnDefinition = kendoFunctions.Plugins.templates[i](displayClass,ColumnDefinition,FieldRecord) } return ColumnDefinition; } if(!buildEditor){var buildEditor = true}; FieldDefinitions = {}; var PrimaryKey; var aggsToApply = {}; var cols = []; for(i in data.FieldsInUse) { //see if we are the primary key if(data.FieldsInUse[i].RelationshipID == 0) { PrimaryKey = data.FieldsInUse[i].Record.PrimaryKeyFieldName }; if(firstRecord.hasOwnProperty(data.FieldsInUse[i].Record.FieldName)==true) { FieldDefinitions[data.FieldsInUse[i].Record.FieldName] = { type: data.FieldsInUse[i].Record.FieldType.replace('datetime','date').replace('unsupported','string'), isEditable: (data.FieldsInUse[i].Record.FieldReadOnly == false && data.FieldsInUse[i].Record.TableReadOnly == 0 && isEditable == true && data.FieldsInUse[i].Record.canEdit == true), record: data.FieldsInUse[i].Record }; var fieldName =data.FieldsInUse[i].Record.FieldName; if(data.FieldsInUse[i].Record.DisplayName) { if( String(data.FieldsInUse[i].Record.DisplayName).length > 0) { fieldName = data.FieldsInUse[i].Record.DisplayName } } var temp = { field: data.FieldsInUse[i].Record.FieldName, title: fieldName, headerTemplate: '' + fieldName + '', editable: isEditable, filterable: { multi: true, search: true }, attributes: { "class": String( data.FieldsInUse[i].Record.displayClasses) }, hidden: ( String(data.FieldsInUse[i].Record.displayClasses).toLowerCase() == 'hidden'), lockable: true, locked: false, type: data.FieldsInUse[i].Record.FieldType.replace('datetime','date').replace('unsupported','string') }; if(temp.field.indexOf('.') > 0) { temp.field = "['" + temp.field + "']"; } //apply custom formatting if(data.FieldsInUse[i].Record.displayClasses) { switch(data.FieldsInUse[i].Record.FieldType) { case 'date': case 'datetime': if(data.FieldsInUse[i].Record.displayClasses.indexOf('f:') == 0) { temp.type = 'date'; temp['format'] = "{0:" + data.FieldsInUse[i].Record.displayClasses.replace('f:','') + "}"; delete temp['attributes']; } break; } if(data.FieldsInUse[i].Record.displayClasses.indexOf('f:') == 0) { temp['format'] = "{0:" + data.FieldsInUse[i].Record.displayClasses.replace('f:','') + "}"; delete temp['attributes']; } if(data.FieldsInUse[i].Record.displayClasses.indexOf('g:') == 0) { Group = { field: temp.field, aggregates: [] } temp['groupFooterColumnTemplate'] = ''; temp['aggregates'] = []; var gFn = JSON.parse(data.FieldsInUse[i].Record.displayClasses.replace('g:','')); for(fn in gFn) { var fnName = Object.keys(gFn[fn])[0]; var fieldId = gFn[fn][fnName]; var fieldName = ''; for(curField in data.FieldsInUse) { if(data.FieldsInUse[curField].Record.ID == fieldId) { //we got a match fieldName = data.FieldsInUse[curField].Record.FieldName if(fieldName.indexOf('.') > 0) { fieldName = "['" + fieldName + "']"; } break; } } Group.aggregates.push({field: fieldName, aggregate: fnName}); aggsToApply[fieldName] = fnName; } } //add support for formatting dates switch( data.FieldsInUse[i].Record.displayClasses) { case 'reformatDate': temp['type'] = 'date'; temp['format'] ="{0:MM/dd/YYYY HH:mm tt}"; break; case 'currency': case 'money': temp['format'] = "{0:c}"; break; case 'percent': temp['format'] = "{0:p}"; break; case 'html': HTMLField = temp.field; temp.encoded = false; temp.template = function(dataItem) { return $('
' + dataItem[HTMLField].replace(/]+.[^>]+>/igm,'').replace(/]+.[^>]+>/mig,'') + '
').text().replace(/\\r\\n/g,'
') + '' }; break; } } //add foriegnKey if(data.FieldsInUse[i].Record.hasOwnProperty('ForeignKeyValues') && data.FieldsInUse[i].Record.canEdit == true) { if( Array.isArray(data.FieldsInUse[i].Record.ForeignKeyValues) == false){data.FieldsInUse[i].Record.ForeignKeyValues = []}; temp['nullable'] = true; switch(data.FieldsInUse[i].Record.FieldType) { case 'number': data.FieldsInUse[i].Record.ForeignKeyValues.unshift({value:0,text:'Select a value'}); FieldDefinitions[data.FieldsInUse[i].Record.FieldName]['defaultValue'] = 0; break; case 'string': data.FieldsInUse[i].Record.ForeignKeyValues.unshift({value:'',text:'Select a value'}); FieldDefinitions[data.FieldsInUse[i].Record.FieldName]['defaultValue'] = 'Select a value'; break; } } else { temp['editor'] = buildEditor; } if(data.FieldsInUse[i].Record.hasOwnProperty('ForeignKeyValues')) { temp['values'] = data.FieldsInUse[i].Record.ForeignKeyValues; } //add templates temp = addDisplayTemplate(temp,data.FieldsInUse[i].Record); if(temp.hasOwnProperty('template')) { FieldDefinitions[data.FieldsInUse[i].Record.FieldName]['record']['template'] = temp.template; } cols.push(temp); } } if(PrimaryKey===null) { if( FieldDefinitions.hasOwnProperty('ID')==true && PrimaryKey===null){PrimaryKey = 'ID'}; if( FieldDefinitions.hasOwnProperty('id')==true && PrimaryKey===null){PrimaryKey = 'id'}; if( FieldDefinitions.hasOwnProperty('AccountNumber')==true && PrimaryKey===null){PrimaryKey = 'AccountNumber'}; } return { primaryKey: PrimaryKey, cols: cols, FieldDefinitions: FieldDefinitions, schema: { model: { id: PrimaryKey, fields: FieldDefinitions } } }; }, getActionItems: function(data) { var ActionItemsGrouped = []; var singles = []; for(i in data.ActionItems) { var curItem = data.ActionItems[i]; curItem['spriteCssClass'] = curItem.icon + ' id' + curItem.ID; if(curItem.MenuGroup == 'Default' || curItem.hasOwnProperty('MenuGroup') == false) { singles.push(curItem); //ActionItemsGrouped.push(curItem); } else { var inserted = false; for(ii in ActionItemsGrouped) { if( ActionItemsGrouped[ii].text == curItem.MenuGroup ) { //match if(ActionItemsGrouped[ii].hasOwnProperty('items')) { ActionItemsGrouped[ii].items.push(curItem); inserted = true; break; } else { //we don't exist var n = { spriteCssClass: 'fa fa-folder-open', text: curItem.MenuGroup, items: [] }; n.items.push(ActionItemsGrouped[ii]); n.items.push(curItem); ActionItemsGrouped.splice(ii,1,n); inserted = true; break; } } } if(inserted ==false) { var n = { spriteCssClass: 'fa fa-folder-open', text: curItem.MenuGroup, items: [curItem] }; ActionItemsGrouped.push(n); } } } ActionItemsGrouped = ActionItemsGrouped.concat(singles); return ActionItemsGrouped; } }