define(['modules/templates/template', 'modules/templates/addtemplate'], function (Template, AddTemplate) { var tps = {}; tps.title = GetTextByKey("P_TEMPLATES", 'Templates'); tps.description = GetTextByKey("P_TEMPLATES", 'Templates'); tps.version = '1.0'; var datacontent = null; var searchinputcontrol = undefined; var makeinputcontrol = undefined; var modelinputcontrol = undefined; var typeinputcontrol = undefined; tps.createContent = function (args) { sectiontype = 1;//sectiontype:0 - global,1 - normal if (args && args.length > 0) templatestatus = eval(args[0]);//templatestatus:0 - draft,1 - published //templatereadonly = !IsAdmin; var content = $('
'); function createHeader() { var header = $('
'); var title = tps.title + " - " + (templatestatus == 0 ? GetTextByKey("P_DRAFT", 'Draft') : GetTextByKey("P_PUBLISHED", 'Published')) header.append($('
').text(title)); setPageTitle(title, true); var search_bar = $(''); header.append(search_bar); search_bar.append(''); if (!teamintelligence) { search_bar.append('' + GetTextByKey("P_IPT_MAKE_COLON", "Make:") + ''); makeinputcontrol = $(''); search_bar.append(modelinputcontrol) search_bar.append('' + GetTextByKey("P_IPT_TYPE_COLON", "Type:") + ''); typeinputcontrol = $(''); search_bar.append(searchinputcontrol); searchinputcontrol.keydown(function (e) { if (e.keyCode == 13 || e.keyCode == 9) tps.refresh(); }); var btnRefresh = $(''); search_bar.append(btnRefresh); btnRefresh.click(function () { tps.refresh(); }); var func = $('
'); if (!templatereadonly) { var iconAdd = $('' + GetTextByKey("P_IPT_ADD", "Add") + '').click(function () { editable = true; tps.addTemplate(); }); func.append(iconAdd); } var iconRefresh = $('' + GetTextByKey("P_IPT_REFRESH", "Refresh") + '').click(function () { tps.refresh(); }); func.append(iconRefresh); header.append(func) return header; } content.append(createHeader()); var dataheader = $('
'); dataheader.append('
'); dataheader.append('
' + GetTextByKey("P_IPT_NAME", "Name") + '
'); //dataheader.append('
Display Text
'); dataheader.append('
' + GetTextByKey("P_IPT_NOTES", "Notes") + '
'); dataheader.append('
' + GetTextByKey("P_IPT_CREATEDBY", "Created By") + '
'); dataheader.append('
'); content.append(dataheader); datacontent = $('
'); content.append(datacontent); this.refresh(); return content; } tps.addTemplate = function () { var s = new AddTemplate(tps); $('#right_popup').empty().append(s.createContent()); showRightPopup(true); } tps.refresh = function () { datacontent.empty(); var searchtxt = searchinputcontrol.val(); searchtxt = htmlencode(searchtxt); var makeid = -1; var modelid = -1; var typeid = -1; if (!teamintelligence) { makeid = makeinputcontrol.val(); modelid = modelinputcontrol.val(); typeid = typeinputcontrol.val(); } var p = JSON.stringify([teamintelligence, templatestatus, searchtxt, makeid, modelid, typeid]); inspectionrequest("GetTemplates", htmlencode(p), function (data) { datacontent.empty(); if (data) { for (var i = 0; i < data.length; i++) { var s = new Template(tps, data[i], i); datacontent.append(s.createContent()); } } }, function (err) { }); } var makesdata = undefined; var modelsdata = undefined; var typesdata = undefined; function getAssetMakes() { inspectionrequest("GetAssetMakes", "", function (data) { if (data && data.length > 0) { makesdata = data; showAssetMakes(); } }, function (err) { }); } function getAssetModels() { var ps = [-1, ""]; inspectionrequest("GetAssetModels", JSON.stringify(ps), function (data) { if (data && data.length > 0) { modelsdata = data; showAssetModels(); } }, function (err) { }); } function getAssetTypes() { inspectionrequest("GetAssetTypes", "", function (data) { if (data && data.length > 0) { typesdata = data; showAssetTypes(); } }, function (err) { }); } function showAssetMakes() { makeinputcontrol.append(''); if (makesdata && makesdata.length > 0) { for (var i = 0; i < makesdata.length; i++) { var item = makesdata[i]; makeinputcontrol.append(''); } showAssetModels(); } } function showAssetModels() { modelinputcontrol.empty(); var makeid = makeinputcontrol.val(); modelinputcontrol.append(''); if (!makeid || makeid == "-1") modelinputcontrol.prop('disabled', true); else modelinputcontrol.prop('disabled', false); if (modelsdata && modelsdata.length > 0 && makeid != "-1") { for (var i = 0; i < modelsdata.length; i++) { var item = modelsdata[i]; if (item.MakeID == parseInt(makeid)) { modelinputcontrol.append(''); } } } } function showAssetTypes() { typeinputcontrol.append(''); if (typesdata && typesdata.length > 0) { for (var i = 0; i < typesdata.length; i++) { var item = typesdata[i]; typeinputcontrol.append(''); } } } return tps; });