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].Values; if (it.Selected) { items.push({ Values: { 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.innerSource.concat(items)); if (ids.length > 0) assignAssets(ids); $('#mask_bg').hide(); }; }); function getAssignData() { _selectedMachines = []; grid_dtassets.setData([]); if (custid && custid != "") { GetSelectedAssets(); } } //**************************************Asset(s)****************************************************// var grid_dtassets; function InitGridSelectedMachines() { grid_dtassets = new GridView('#selectedmachinelist'); grid_dtassets.lang = { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset") }; 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: 30, 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.canMultiSelect = true; grid_dtassets.columns = columns; grid_dtassets.init(); grid_dtassets.selectedrowchanged = function (rowindex) { var rowdata = grid_dtassets.source[rowindex]; if (rowdata) { } } } function showSelectedMachine(data) { var rows = []; for (var i = 0; i < data.length; i++) { var r = data[i]; var fr = { Values: r }; rows.push(fr); } 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.innerSource.map(function (s) { return s.Values.ID; }); dialogAUAssets.showSelector(); $('#mask_bg').css('height', '100%'); } 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 = []; for (var i = grid_dtassets.innerSource.length - 1; i >= 0; i--) { var s = grid_dtassets.innerSource[i].Values; if (s.selected) { grid_dtassets.innerSource.splice(i, 1); ids.push(s.ID); } } if (grid_dtassets.source != null) { for (var j = grid_dtassets.source.length - 1; j >= 0; j--) { var l = grid_dtassets.source[j].Values; if (l.selected) { grid_dtassets.source.splice(j, 1); } } } grid_dtassets.reset(); 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 = new GridView('#salespersonlist'); grid_dtsp.lang = { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset") }; 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.canMultiSelect = false; grid_dtsp.columns = columns; grid_dtsp.init(); } function showSalespersons(data) { var rows = []; for (var i = 0; i < data.length; i++) { var r = data[i]; for (var j in r) { } var fr = { Values: r }; rows.push(fr); } grid_dtsp.setData(rows); } 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); $('#mask_bg').show(); $('#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].Values; $('#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********************************************//