202 lines
		
	
	
		
			8.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			202 lines
		
	
	
		
			8.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
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 = $('<div></div>');
 | 
						|
 | 
						|
        function createHeader() {
 | 
						|
            var header = $('<div></div>');
 | 
						|
            var title = tps.title + " - " + (templatestatus == 0 ? GetTextByKey("P_DRAFT", 'Draft') : GetTextByKey("P_PUBLISHED", 'Published'))
 | 
						|
            header.append($('<div class="page_title"></div>').text(title));
 | 
						|
            setPageTitle(title, true);
 | 
						|
            var search_bar = $('<div class="search_bar"></div>');
 | 
						|
            header.append(search_bar);
 | 
						|
            search_bar.append('<input type="password" autocomplete="new-password" style="display: none" />');
 | 
						|
            if (!teamintelligence) {
 | 
						|
                search_bar.append('<span style="margin-left:10px;">' + GetTextByKey("P_IPT_MAKE_COLON", "Make:") + '</span>');
 | 
						|
                makeinputcontrol = $('<select type="text" style="margin-left: 5px; width:160px;height:22px;" autocomplete="off" />');
 | 
						|
                makeinputcontrol.change(function () {
 | 
						|
                    showAssetModels();
 | 
						|
                });
 | 
						|
                search_bar.append(makeinputcontrol);
 | 
						|
                search_bar.append('<span style="margin-left:10px;">' + GetTextByKey("P_IPT_MODEL_COLON", "Model:") + '</span>');
 | 
						|
                modelinputcontrol = $('<select type="text" style="margin-left: 5px; width:160px;height:22px;" autocomplete="off" />');
 | 
						|
                search_bar.append(modelinputcontrol)
 | 
						|
                search_bar.append('<span style="margin-left:10px;">' + GetTextByKey("P_IPT_TYPE_COLON", "Type:") + '</span>');
 | 
						|
                typeinputcontrol = $('<select type="text" style="margin-left: 5px; width:160px;height:22px;" autocomplete="off" />');
 | 
						|
                search_bar.append(typeinputcontrol)
 | 
						|
 | 
						|
                getAssetMakes();
 | 
						|
                getAssetModels();
 | 
						|
                getAssetTypes();
 | 
						|
            }
 | 
						|
 | 
						|
            searchinputcontrol = $('<input type="text" autocomplete="off" style="margin-left:10px;" />');
 | 
						|
            search_bar.append(searchinputcontrol);
 | 
						|
            searchinputcontrol.keydown(function (e) {
 | 
						|
                if (e.keyCode == 13 || e.keyCode == 9)
 | 
						|
                    tps.refresh();
 | 
						|
            });
 | 
						|
            var btnRefresh = $('<input class="search" type="button" value="' + GetTextByKey("P_IPT_SEARCH", "Search") + '" style="margin-left:10px;"/>');
 | 
						|
            search_bar.append(btnRefresh);
 | 
						|
            btnRefresh.click(function () {
 | 
						|
                tps.refresh();
 | 
						|
            });
 | 
						|
 | 
						|
            var func = $('<div class="function_title"></div>');
 | 
						|
            if (!templatereadonly) {
 | 
						|
                var iconAdd = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADD", "Add") + '</span>').click(function () {
 | 
						|
                    editable = true;
 | 
						|
                    tps.addTemplate();
 | 
						|
                });
 | 
						|
                func.append(iconAdd);
 | 
						|
            }
 | 
						|
            var iconRefresh = $('<span class="sbutton iconrefresh">' + GetTextByKey("P_IPT_REFRESH", "Refresh") + '</span>').click(function () {
 | 
						|
                tps.refresh();
 | 
						|
            });
 | 
						|
            func.append(iconRefresh);
 | 
						|
            header.append(func)
 | 
						|
 | 
						|
            return header;
 | 
						|
        }
 | 
						|
 | 
						|
        content.append(createHeader());
 | 
						|
 | 
						|
        var dataheader = $('<div class="question-holder no-hover" style="font-weight: bold;font-size:14px;margin-left:8px;"></div>');
 | 
						|
        dataheader.append('<div style="width:30px;flex-shrink:0;"></div>');
 | 
						|
        dataheader.append('<div class="question-cell" style="width:400px">' + GetTextByKey("P_IPT_NAME", "Name") + '</div>');
 | 
						|
        //dataheader.append('<div class="question-cell" style="width: 200px">Display Text</div>');
 | 
						|
        dataheader.append('<div class="question-cell" style="width:400px">' + GetTextByKey("P_IPT_NOTES", "Notes") + '</div>');
 | 
						|
        dataheader.append('<div class="question-cell" style="width:200px">' + GetTextByKey("P_IPT_CREATEDBY", "Created By") + '</div>');
 | 
						|
        dataheader.append('<div class="question-cell" style="width:90px;padding-right:20px;"></div>');
 | 
						|
        content.append(dataheader);
 | 
						|
 | 
						|
        datacontent = $('<div></div>');
 | 
						|
        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('<option value="-1">*</option>');
 | 
						|
        if (makesdata && makesdata.length > 0) {
 | 
						|
            for (var i = 0; i < makesdata.length; i++) {
 | 
						|
                var item = makesdata[i];
 | 
						|
                makeinputcontrol.append('<option value="' + item.ID + '">' + item.Name + '</option>');
 | 
						|
            }
 | 
						|
            showAssetModels();
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    function showAssetModels() {
 | 
						|
        modelinputcontrol.empty();
 | 
						|
        var makeid = makeinputcontrol.val();
 | 
						|
        modelinputcontrol.append('<option value="-1">*</option>');
 | 
						|
        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('<option value="' + item.ID + '">' + item.Name + '</option>');
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    function showAssetTypes() {
 | 
						|
        typeinputcontrol.append('<option value="-1">*</option>');
 | 
						|
        if (typesdata && typesdata.length > 0) {
 | 
						|
            for (var i = 0; i < typesdata.length; i++) {
 | 
						|
                var item = typesdata[i];
 | 
						|
                typeinputcontrol.append('<option value="' + item.Key + '">' + item.Value + '</option>');
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    return tps;
 | 
						|
}); |