add site
This commit is contained in:
418
Site/js/assetselector.js
Normal file
418
Site/js/assetselector.js
Normal file
@@ -0,0 +1,418 @@
|
||||
var $assetselector = function (id) {
|
||||
this.containerId = id;
|
||||
this.title = GetTextByKey("P_SELECTASSETS", 'Select Assets');
|
||||
this.companyId = null;
|
||||
this.jobsiteId = null;
|
||||
this.forceSingle = false;
|
||||
this.exceptSource = null;
|
||||
this.exceptShareAsset = false;
|
||||
this.onOK = null;
|
||||
this.onDialogClosed = null;
|
||||
this.includechild = true;
|
||||
this.allowhidden = true;
|
||||
this.allowotherfilter = true;
|
||||
this.uid = null;
|
||||
};
|
||||
|
||||
(function () {
|
||||
var __proto = $assetselector.prototype;
|
||||
|
||||
function initMachinesGrid(parent) {
|
||||
var grid = new GridView(parent);
|
||||
grid.lang = {
|
||||
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
||||
ok: GetTextByKey("P_GRID_OK", "OK"),
|
||||
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
||||
};
|
||||
var styleFilter = function (item) {
|
||||
if (item.Suggested) {
|
||||
return {
|
||||
//'background-color': 'yellow',
|
||||
'display': 'block',
|
||||
'margin': 0,
|
||||
'box-sizing': 'border-box',
|
||||
'padding': '0 4px',
|
||||
'height': '27px',
|
||||
'line-height': '27px',
|
||||
'overflow': 'hidden',
|
||||
'text-overflow': 'ellipsis'
|
||||
};
|
||||
}
|
||||
};
|
||||
var bgFilter = function (item) {
|
||||
if (item.Suggested)
|
||||
return 'yellow';
|
||||
};
|
||||
var columns = [];
|
||||
if (!this.forceSingle) {
|
||||
columns.push({
|
||||
// checkbox
|
||||
name: 'check',
|
||||
key: 'Selected',
|
||||
width: 30,
|
||||
align: 'center',
|
||||
sortable: false,
|
||||
allcheck: true,
|
||||
type: 3
|
||||
});
|
||||
}
|
||||
columns.push({
|
||||
key: 'VIN',
|
||||
caption: GetTextByKey("P_SELECTASSETS_VIN", 'VIN'),
|
||||
width: 160,
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter
|
||||
},
|
||||
{
|
||||
key: 'Name',
|
||||
caption: GetTextByKey("P_SELECTASSETS_NAME", 'Name'),
|
||||
width: 160,
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter
|
||||
});
|
||||
if (this.jobsiteId != null) {
|
||||
columns.push(
|
||||
{
|
||||
key: 'Suggested',
|
||||
caption: GetTextByKey("P_SELECTASSETS_CURRENTSTATE", 'Current State'),
|
||||
width: 110,
|
||||
allowFilter: true,
|
||||
filter: function (item) {
|
||||
return item.Suggested ? GetTextByKey("P_SELECTASSETS_SUGGESTED", 'SUGGESTED') : GetTextByKey("P_SELECTASSETS_UNASSIGNED", 'UNASSIGNED');
|
||||
},
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter
|
||||
},
|
||||
{
|
||||
key: 'DistanceFromSite',
|
||||
caption: GetTextByKey("P_SELECTASSETS_DISTANCEFROMSITE", 'Distance From Site'),
|
||||
align: 'right',
|
||||
width: 130,
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter
|
||||
},
|
||||
{
|
||||
key: 'DistanceUnits',
|
||||
caption: GetTextByKey("P_SELECTASSETS_UNITS", 'Units'),
|
||||
width: 80,
|
||||
allowFilter: true,
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter
|
||||
}
|
||||
);
|
||||
}
|
||||
columns.push(
|
||||
{
|
||||
key: 'MakeName',
|
||||
caption: GetTextByKey("P_SELECTASSETS_MAKE", 'Make'),
|
||||
width: 120,
|
||||
allowFilter: true,
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter
|
||||
},
|
||||
{
|
||||
key: 'ModelName',
|
||||
caption: GetTextByKey("P_SELECTASSETS_MODEL", 'Model'),
|
||||
width: 120,
|
||||
allowFilter: true,
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter
|
||||
},
|
||||
{
|
||||
key: 'TypeName',
|
||||
caption: GetTextByKey("P_SELECTASSETS_TYPE", 'Type'),
|
||||
width: 120,
|
||||
allowFilter: true,
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter
|
||||
},
|
||||
{
|
||||
key: 'AcquisitionType',
|
||||
caption: GetTextByKey("P_MA_ACQUISITIONTYPE", "Acquisition Type"),
|
||||
width: 120,
|
||||
allowFilter: true,
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter
|
||||
},
|
||||
{
|
||||
key: 'AssetGroups',
|
||||
caption: GetTextByKey("P_JS_ASSETGROUP", "Asset Group"),
|
||||
width: 160,
|
||||
allowFilter: false,
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter,
|
||||
filter: function (item) {
|
||||
if (item.AssetGroups)
|
||||
return item.AssetGroups.join(", ");
|
||||
else
|
||||
return "";
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'Jobsites',
|
||||
caption: GetTextByKey("P_JOBSITE", "Jobsite"),
|
||||
width: 160,
|
||||
allowFilter: false,
|
||||
styleFilter: styleFilter,
|
||||
bgFilter: bgFilter,
|
||||
filter: function (item) {
|
||||
if (item.Jobsites && item.Jobsites.length > 0) {
|
||||
var r = "";
|
||||
for (var i = 0; i < item.Jobsites.length; i++) {
|
||||
r += item.Jobsites[i].Key;
|
||||
if (item.Jobsites[i].Value && item.Jobsites[i].Value != "")
|
||||
r += "(" + item.Jobsites[i].Value + ")";
|
||||
r += ", ";
|
||||
}
|
||||
r = r.substring(0, r.length - 2);
|
||||
return r;
|
||||
}
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
);
|
||||
//grid.canMultiSelect = true;
|
||||
grid.columns = columns;
|
||||
grid.init();
|
||||
|
||||
this.gridAssets = grid;
|
||||
}
|
||||
|
||||
function createDialog() {
|
||||
var dialog = $('<div class="dialog" style="display: none; width: 1210px; height: 520px">').attr('id', this.containerId);
|
||||
|
||||
var title = $('<div class="dialog-title"></div>').appendTo(dialog);
|
||||
title.append($('<span class="title"></span>').text(this.title));
|
||||
title.append('<em class="dialog-close"></em>');
|
||||
|
||||
var content = $('<div class="dialog-content"></div>').appendTo(dialog);
|
||||
var searchdiv = $('<div style="position: relative; width: 280px; margin-top: 4px; float: left"></div>').appendTo(content);
|
||||
this.machineSearch = $('<input type="text" placeholder="' + GetTextByKey("P_SELECTASSETS_SEARCH", "Search") + '" />')
|
||||
.css({
|
||||
width: '100%',
|
||||
paddingRight: 28,
|
||||
height: 25,
|
||||
lineHeight: '25px',
|
||||
boxSizing: 'border-box',
|
||||
textIndent: '4px'
|
||||
})
|
||||
.keypress(onKeyPress.bind(this)).appendTo(searchdiv);
|
||||
$('<div></div>').css({
|
||||
position: 'absolute',
|
||||
top: 0, right: 0, height: 25, width: 28,
|
||||
textAlign: 'center',
|
||||
lineHeight: '25px',
|
||||
fontSize: '1.2em',
|
||||
fontFamily: 'FontAwesome',
|
||||
fontWeight: 900,
|
||||
color: 'rgb(123,28,33)',
|
||||
cursor: 'pointer'
|
||||
}).click(onSearch.bind(this)).appendTo(searchdiv);
|
||||
|
||||
var labeldiv = $('<div style="margin: 4px 0 0 10px; float: left; line-height: 25px"></div>').appendTo(content);
|
||||
if (this.jobsiteId == null && this.allowhidden) {
|
||||
this.showHidden = $('<input type="checkbox" id="checkShowHidden"/>').click(onSearch.bind(this)).appendTo(labeldiv);
|
||||
$('<label for="checkShowHidden"></label>').text(GetTextByKey("P_SELECTASSETS_SHOWHIDDEN", 'Show Hidden')).appendTo(labeldiv);
|
||||
}
|
||||
|
||||
if (this.allowotherfilter) {
|
||||
var filterdiv = $('<div style="margin: 4px 0 0 10px; float: left; line-height: 25px"></div>').appendTo(content);
|
||||
$('<label style="margin-left:5px;margin-right:5px;"></label>').text(GetTextByKey("P_JS_ASSETGROUP", 'Asset Group')).appendTo(filterdiv);
|
||||
this.selgroup = $('<select style="width:120px;height:22px;"></select>').change(onSearch.bind(this)).appendTo(filterdiv);
|
||||
getAssetGroups(this.selgroup);
|
||||
$('<label style="margin-left:5px;margin-right:5px;"></label>').text(GetTextByKey("P_XXXXXX", 'Jobsite')).appendTo(filterdiv);
|
||||
this.seljs = $('<select style="width:120px;height:22px;"></select>').change(onSearch.bind(this)).appendTo(filterdiv);
|
||||
$('<label style="margin-left:5px;margin-right:5px;"></label>').text(GetTextByKey("P_XXXXXX", 'Jobsite Code')).appendTo(filterdiv);
|
||||
this.seljscode = $('<select style="width:120px;height:22px;"></select>').change(onSearch.bind(this)).appendTo(filterdiv);
|
||||
getJobSites(this.seljs, this.seljscode);
|
||||
}
|
||||
|
||||
$('<div style="clear: both"></div>').appendTo(content);
|
||||
|
||||
this.machineList = $('<div style="width: 1188px; height: 400px; margin: 10px 0 4px"></div>').appendTo(content);
|
||||
|
||||
var dialogFunction = $('<div class="dialog-func"></div>').appendTo(dialog);
|
||||
$('<input type="button" value="' + GetTextByKey("P_SELECTASSETS_CANCEL", "Cancel") + '" class="dialog-close" />').appendTo(dialogFunction).css("height", 26);//height与Workspace.css冲突
|
||||
$('<input type="button" value="' + GetTextByKey("P_SELECTASSETS_OK", "OK") + '" />').click(onOKClick.bind(this)).appendTo(dialogFunction);
|
||||
$('<div class="clear"></div>').appendTo(dialogFunction);
|
||||
|
||||
$('<div class="maskbg" style="display: none"><div class="loading_icon icon c-spin"></div></div>').appendTo(dialog);
|
||||
|
||||
// init
|
||||
initMachinesGrid.call(this, this.machineList);
|
||||
$(document.body).append(dialog);
|
||||
|
||||
dialog.dialog(this.onDialogClosed);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
__proto.showSelector = function (topRatio, force) {
|
||||
var dialog;
|
||||
if (force) {
|
||||
$('#' + this.containerId).remove();
|
||||
dialog = createDialog.call(this);
|
||||
} else {
|
||||
dialog = $('#' + this.containerId);
|
||||
if (!dialog.length) {
|
||||
dialog = createDialog.call(this);
|
||||
}
|
||||
}
|
||||
this.dialog = dialog;
|
||||
this.machineSearch.val('');
|
||||
if (this.jobsiteId == null && this.allowhidden) {
|
||||
this.showHidden.prop('checked', false);
|
||||
}
|
||||
dialog.attr('init', '1').showDialog().css({
|
||||
'top': (document.documentElement.clientHeight - $('#dialog_machines').height()) / (topRatio || 3),
|
||||
'left': (document.documentElement.clientWidth - $('#dialog_machines').width()) / 2
|
||||
});
|
||||
this.gridAssets.setData([]);
|
||||
onSearch.call(this);
|
||||
};
|
||||
|
||||
function onKeyPress(e) {
|
||||
if (e.keyCode === 13) {
|
||||
onSearch.call(this);
|
||||
}
|
||||
};
|
||||
|
||||
function devicerequest(method, param, callback, error) {
|
||||
var path = "";
|
||||
if (_network.root != null && _network.root.length > 0) {
|
||||
path = "MachineDeviceManagement/";
|
||||
}
|
||||
_network.request(path + "ManageMachines.aspx", -1, method, param, callback, error || function (e) {
|
||||
console.log(e);
|
||||
});
|
||||
}
|
||||
|
||||
function jobsiterequest(method, param, callback, error) {
|
||||
var path = "";
|
||||
if (_network.root != null && _network.root.length > 0) {
|
||||
path = "JobSite/";
|
||||
}
|
||||
_network.request(path + "JobSite.aspx", -1, method, param, callback, error || function (e) {
|
||||
console.log(e);
|
||||
});
|
||||
}
|
||||
|
||||
function hasMachine(id, source) {
|
||||
for (var i = 0; i < source.length; i++) {
|
||||
if (source[i] === id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
var maskbg = this.dialog.find('.maskbg');
|
||||
maskbg.show();
|
||||
var search = this.machineSearch;
|
||||
search.blur();
|
||||
var excepts = this.exceptSource;
|
||||
var exceptShareAsset = this.exceptShareAsset;
|
||||
var gridAssets = this.gridAssets;
|
||||
var title = this.title;
|
||||
var companyId = this.companyId || '';
|
||||
|
||||
var assetgroup = this.selgroup && this.selgroup.val();
|
||||
if (!assetgroup) assetgroup = "-1";
|
||||
var js = this.seljs && this.seljs.val();
|
||||
if (!js) js = "-1";
|
||||
var jscode = this.seljscode && this.seljscode.val();
|
||||
if (!jscode) jscode = "-1";
|
||||
|
||||
var params = [
|
||||
companyId,
|
||||
search.val(),
|
||||
this.jobsiteId || !this.allowhidden || (this.showHidden.prop('checked') ? '1' : '0'),
|
||||
this.includechild ? '1' : '0',
|
||||
assetgroup,
|
||||
js,
|
||||
jscode,
|
||||
this.uid
|
||||
];
|
||||
|
||||
var method = "GetAssetList";
|
||||
if (this.jobsiteId != null)
|
||||
method = "GetJobsiteAssetList";
|
||||
else if (this.uid != null)
|
||||
method = "GetUserAssignedAssets";
|
||||
|
||||
devicerequest(method, params.join(String.fromCharCode(170)), function (data) {
|
||||
if (typeof data === 'string') {
|
||||
showAlert(GetTextByKey("P_SELECTASSETS_FAILEDGETLIST", 'Failed to get the machine list: ') + data, title);
|
||||
maskbg.hide();
|
||||
return;
|
||||
}
|
||||
var items = [];
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var it = data[i];
|
||||
if (exceptShareAsset && it.ShareStatus == 2)
|
||||
continue;
|
||||
if (excepts == null || !hasMachine(it.Id, excepts)) {
|
||||
items.push({ Values: it });
|
||||
}
|
||||
}
|
||||
gridAssets.setData(items);
|
||||
maskbg.hide();
|
||||
search.focus();
|
||||
}, function () {
|
||||
showAlert(GetTextByKey("P_SELECTASSETS_FAILEDGETLIST1", 'Failed to get the machine list.'), title);
|
||||
maskbg.hide();
|
||||
});
|
||||
}
|
||||
|
||||
function onOKClick() {
|
||||
var index = this.gridAssets.selectedIndex;
|
||||
if (this.forceSingle && index < 0) {
|
||||
showAlert(GetTextByKey("P_SELECTASSETS_SELECTASSET", 'Please select an asset.'), this.title);
|
||||
return;
|
||||
}
|
||||
this.onOK && this.onOK(this.gridAssets.source, index);
|
||||
this.dialog.hideDialog();
|
||||
}
|
||||
|
||||
function getAssetGroups(ctrl) {
|
||||
devicerequest('GetMachineGroups', '' + String.fromCharCode(170) + '', function (data) {
|
||||
if (typeof data === 'string') {
|
||||
return;
|
||||
}
|
||||
ctrl.empty();
|
||||
ctrl.append($("<option value='-1'> </option>"));
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var it = data[i];
|
||||
ctrl.append($("<option></option>").val(it.GroupID).text(it.GroupName));
|
||||
}
|
||||
}, function () {
|
||||
});
|
||||
}
|
||||
|
||||
function getJobSites(ctrl, ctrl1) {
|
||||
jobsiterequest('GetJobSiteDataSource', '', function (data) {
|
||||
if (typeof data === 'string') {
|
||||
return;
|
||||
}
|
||||
ctrl.empty();
|
||||
ctrl.append($("<option value='-1'> </option>"));
|
||||
if (data.Jobsites) {
|
||||
for (var i = 0; i < data.Jobsites.length; i++) {
|
||||
var it = data.Jobsites[i];
|
||||
ctrl.append($("<option></option>").val(it.ID).text(it.Name));
|
||||
}
|
||||
}
|
||||
|
||||
ctrl1.empty();
|
||||
ctrl1.append($("<option value='-1'> </option>"));
|
||||
if (data.Codes) {
|
||||
for (var i = 0; i < data.Codes.length; i++) {
|
||||
var it = data.Codes[i];
|
||||
ctrl1.append($("<option></option>").val(it).text(it));
|
||||
}
|
||||
}
|
||||
}, function () {
|
||||
});
|
||||
}
|
||||
})();
|
Reference in New Issue
Block a user