var dialogAUAssets; $(function () { InitGridSelectedMachines(); dialogAUAssets = new $assetselector('dialog_machines'); dialogAUAssets.onDialogClosed = function () { showmaskbg(false); }; dialogAUAssets.onOK = function (source) { var items = []; var ids = []; for (var i = 0; i < source.length; i++) { var it = source[i]; if (it.Selected) { items.push({ ID: it.Id, VIN: it.VIN, Name: it.Name, MakeName: it.MakeName, ModelName: it.ModelName, TypeName: it.TypeName }); ids.push(it.Id); } } grid_dtassets.setData(grid_dtassets.source.concat(items)); if (ids.length > 0) assignAssets(ids); showmaskbg(false); }; }); function getAssignData() { _selectedMachines = []; grid_dtassets.setData([]); if (custid && custid != "") { GetSelectedAssets(); } } //**************************************Asset(s)****************************************************// var grid_dtassets; function InitGridSelectedMachines() { grid_dtassets = createGridView('#selectedmachinelist'); var list_columns = [ { name: 'VIN', caption: GetTextByKey("P_UM_SN", "SN"), valueIndex: 'VIN', css: { 'width': 200, 'text-align': 'left' } }, { name: 'Name', caption: GetTextByKey("P_UM_NAME", "Name"), valueIndex: 'Name', css: { 'width': 200, 'text-align': 'left' } }, { name: 'MakeName', caption: GetTextByKey("P_UM_MAKE", "Make"), valueIndex: 'MakeName', css: { 'width': 150, 'text-align': 'left' } }, { name: 'ModelName', caption: GetTextByKey("P_UM_MODEL", "Model"), valueIndex: 'ModelName', css: { 'width': 150, 'text-align': 'left' } }, { name: 'TypeName', caption: GetTextByKey("P_UM_ASSETSTYPE", "Type"), valueIndex: 'TypeName', css: { 'width': 170, 'text-align': 'left' } } ]; var columns = [ { // checkbox name: 'check', key: 'selected', width: 45, align: 'center', sortable: false, allcheck: true, type: 3 } ]; // head for (var hd in list_columns) { var col = {}; col.name = list_columns[hd].name; col.caption = list_columns[hd].caption; col.visible = true; col.sortable = true; col.width = list_columns[hd].css.width; col.align = list_columns[hd].css["text-align"] col.key = list_columns[hd].valueIndex; col.allowFilter = col.name === 'TypeName'; col.styleFilter = function (item) { if (item.Highlight) return { 'background-color': 'yellow' }; } columns.push(col); } grid_dtassets.multiSelect = true; grid_dtassets.columns = columns; grid_dtassets.init(); } function showSelectedMachine(data) { var rows = []; for (var i = 0; i < data.length; i++) { var r = data[i]; rows.push(r); } grid_dtassets.setData(rows); } // 获取已选中的Assets function GetSelectedAssets() { _selectedMachines = []; $("#dialogmask").show(); crrequest('GetAssignedMachines', custid, function (data) { if (typeof data === "string") { showAlert(data, GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment")); return; } _selectedMachines = data; showSelectedMachine(_selectedMachines); $("#dialogmask").hide(); }, function (e) { $("#dialogmask").hide(); }); } function assignAssets(ids, next) { var p = [ custid, JSON.stringify(ids) ]; $("#dialogmask").show(); crrequest('AssignMachines', htmlencode(JSON.stringify(p)), function (r) { $("#dialogmask").hide(); if (r !== 'OK') { showAlert(r, GetTextByKey("P_UM_ASSETASSIGNMENT", 'Asset Assignment')); } if (next) next(); }, function () { $("#dialogmask").hide(); }); } function OnAssetAdd() { showmaskbg(true); dialogAUAssets.exceptSource = grid_dtassets.source.map(function (s) { return s.ID; }); dialogAUAssets.showSelector(); } function OnMachineDelete() { showConfirm(GetTextByKey("P_UM_DELETESELECTEDASSET", 'Are you sure you want to delete these selected assets?'), GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment"), function () { var ids = []; var tmp = grid_dtassets.source; if (tmp != null) { for (var j = tmp.length - 1; j >= 0; j--) { var l = tmp[j]; if (l.selected) { tmp.splice(j, 1); } } } grid_dtassets.setData(tmp); grid_dtassets.reload(true); var params = [ custid, JSON.stringify(ids) ]; $("#dialogmask").show(); crrequest('RemoveAssignedMachines', htmlencode(JSON.stringify(params)), function (r) { $("#dialogmask").hide(); if (r !== 'OK') { showAlert(r, GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment")); } }, function () { $("#dialogmask").show(); }); }); } //***********************************Begin Salesperson********************************************// function showsalespersonmask(flag) { if (flag) { $('#salespersonmask').fadeIn(100); } else { $('#salespersonmask').fadeOut(100); } } var grid_dtsp; function InitSPGridData() { grid_dtsp = createGridView('#salespersonlist'); var list_columns = [ { name: 'ID', caption: GetTextByKey("P_UM_USERIDOREMAIL", "User ID/Email"), valueIndex: 'ID', css: { 'width': 180, 'text-align': 'left' } }, { name: 'DisplayName', caption: GetTextByKey("P_UM_USERNAME", "User Name"), valueIndex: 'DisplayName', css: { 'width': 200, 'text-align': 'left' } }, { name: 'FOB', caption: GetTextByKey("P_UM_EMPLOYEEIDORFOB", "Employee ID or FOB"), valueIndex: 'FOB', css: { 'width': 200, 'text-align': 'left' } } ]; var columns = []; // head for (var hd in list_columns) { var col = {}; col.name = list_columns[hd].name; col.caption = list_columns[hd].caption; col.visible = true; col.sortable = true; col.width = list_columns[hd].css.width; col.align = list_columns[hd].css["text-align"] col.key = list_columns[hd].valueIndex; col.allowFilter = list_columns[hd].allowFilter; columns.push(col); } grid_dtsp.multiSelect = false; grid_dtsp.columns = columns; grid_dtsp.init(); } function showSalespersons(data) { grid_dtsp.setData(data); } function GetSalespersons() { var searchtxt = $.trim($('#sp_searchinputtxt').val()); crrequest('GetSalespersons', searchtxt, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showcontatcmask(false); return; } showSalespersons(data); }, function (err) { }); } function onOpenSalesperson() { var alerttitle = GetTextByKey("P_CR_SELECTSALESPERSON", 'Select Salesperson'); $('#sp_searchinputtxt').val(''); GetSalespersons(); $('#dialog_salesperson .dialog-title span.title').text(alerttitle); showmaskbg(true); $('#dialog_salesperson') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_salesperson').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_salesperson').width()) / 2 }).showDialogfixed(); setTimeout(function () { grid_dtsp && grid_dtsp.resize(); }); } function searchSalespersonEnter(e) { if (e.keyCode == 13 || e.keyCode == 9) { GetSalespersons(); } } function onSetSalesperson() { var index = grid_dtsp.selectedIndex; if (index < 0) { $('#dialog_salesperson').hideDialog(); showmaskbg(false); return; } var salesperson = grid_dtsp.source[index]; $('#dialog_salespersoncode').data('spiid', salesperson.IID); $('#dialog_salespersoncode').val(salesperson.FOB); $('#dialog_salespersonname').val(salesperson.DisplayName); $('#dialog_salesperson').hideDialog(); showmaskbg(false); } function onDeleteSalesperson() { $('#dialog_salespersoncode').data('spiid', ''); $('#dialog_salespersoncode').val(''); $('#dialog_salespersonname').val(''); } //***********************************End Salesperson********************************************//