/* * Session details view model */ function SessionViewModel(data) { //Ensure data is not null data = data || new Object(); this.SessionID = getValue(data.SessionID, null); this.UserName = getValue(data.UserName, null); this.SessionCreateDT = getValue(data.SessionCreateDT, null); this.CurrentRevisionID = getValue(data.CurrentRevisionID, null); this.Name = getValue(data.Name, null); this.CurrentRevision = getValue(data.CurrentRevision, null); this.RevisionCreateDT = getValue(data.RevisionCreateDT, null); this.ResultID = getValue(data.ResultID, null); this.StatusCode = getValue(data.StatusCode, null); this.StatusSuffix = getValue(data.StatusSuffix, null); this.StatusUpdateDT = getValue(data.StatusUpdateDT, null); this.Criteria = new SearchCriteria(data.Criteria); } /* * Search filter critia view model */ function SearchCriteria(data) { //Ensure data is not null data = data || new Object(); this.FilterByPartNumber = getValue(data.FilterByPartNumber, false); this.PartNumbers = new Array(); this.LotNumbers = new Array(); this.MinimumDT = getValue(data.MinimumDT, null); this.MaximumDT = getValue(data.MaximumDT, null); this.WorkCenters = new Array(); this.OperatorIDs = new Array(); this.ProfitCenters = new Array(); this.ComponentLotNumbers = new Array(); if (getValue(data.FilterByLotNumber)) { } } /* * Code/description tuple */ function CodedItem(data) { //Ensure data is not null data = data || new Object(); this.Code = getValue(data.Code, null); this.Description = getValue(data.Description, null); } /* * Helper method to extract value from data or set default value */ function getValue(obj, defaultValue) { if (typeof obj === "undefined") { return defaultValue; } return obj || defaultValue; } /* * Helper string formatting function */ String.prototype.formatUnicorn = String.prototype.formatUnicorn || function () { "use strict"; var str = this.toString(); if (arguments.length) { var t = typeof arguments[0]; var key; var args = ("string" === t || "number" === t) ? Array.prototype.slice.call(arguments) : arguments[0]; for (key in args) { str = str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]); } } return str; }; /* * Valid combination of input criteria */ function ValidCombination(id, name, timespan, workOrder, itemNumber, profitCenter, workCenter, componentLot, operator, itemOperationMis, extractMis) { this.ID = id; this.Name = name; this.Timespan = timespan; this.WorkOrder = workOrder; this.ItemNumber = itemNumber; this.ProfitCenter = profitCenter; this.WorkCenter = workCenter; this.ComponentLot = componentLot; this.Operator = operator; this.ItemOperationMis = itemOperationMis; this.ExtractMis = extractMis; } ValidCombination.prototype = { ID: -1, Name: "", Timespan: false, WorkOrder: false, ItemNumber: false, ProfitCenter: false, WorkCenter: false, ComponentLot: false, Operator: false, ItemOperationMis: false, ExtractMis: false }; /* * Checks if the filter flags given match those in the valid combination */ ValidCombination.prototype.matches = function (timespan, workOrder, itemNumber, profitCenter, workCenter, componentLot, operator, itemOperationMis, extractMis) { return this.Timespan === timespan && this.WorkOrder === workOrder && this.ItemNumber === itemNumber && this.ProfitCenter === profitCenter && this.WorkCenter === workCenter && this.ComponentLot === componentLot && this.Operator === operator && this.ItemOperationMis === itemOperationMis && this.ExtractMis === extractMis; } /* * Helper toString override for logging valid combination */ ValidCombination.prototype.toString = function validationCombinationToString() { return "{Name}: [Time Span={TimeSpan}, Work Order={WorkOrder}, Item Number={ItemNumber}, Profit Center={ProfitCenter}, Work Center={WorkCenter}, Component Lot={ComponentLot}, Operator={Operator}, Item/Operation/MIS={ItemOperationMis}, Extract MIS={ExtractMis}]".formatUnicorn(this); } //Define valid combinations var validCombinations = [ new ValidCombination(10, "Work Order", false, true, false, false, false, false, false, false, false), new ValidCombination(20, "Component Lot", false, false, false, false, false, true, false, false, false), new ValidCombination(30, "Time Span + Profit Center", true, false, false, true, false, false, false, false, false), new ValidCombination(40, "Time Span + Work Center", true, false, false, false, true, false, false, false, false), new ValidCombination(50, "Time Span + Operator", true, false, false, false, false, false, true, false, false), new ValidCombination(60, "Time Span + Profit Center + Item Number", true, false, true, true, false, false, false, false, false), new ValidCombination(70, "Time Span + Profit Center + Item/Operation/MIS", true, false, false, true, false, false, false, true, false), new ValidCombination(80, "Time Span + Profit Center + Work Order + Item/Operation/MIS", true, true, false, true, false, false, false, true, false), new ValidCombination(90, "Time Span + Profit Center + Extract MIS", true, false, false, true, false, false, false, false, true), new ValidCombination(100, "Time Span + Work Center + Item Number", true, false, true, false, true, false, false, false, false), new ValidCombination(110, "Time Span + Work Center + Extract MIS", true, false, false, false, true, false, false, false, true), new ValidCombination(120, "Time Span + Work Center + Item/Operation/MIS", true, false, false, false, true, false, false, true, false), new ValidCombination(130, "Time Span + Work Center + Work Order + Item/Operation/MIS", true, true, false, false, true, false, false, true, false), new ValidCombination(140, "Time Span + Item Number", true, false, true, false, false, false, false, false, false), new ValidCombination(150, "Time Span + Work Center + Operator", true, false, false, false, true, false, true, false, false), new ValidCombination(160, "Time Span + Profit Center + Operator", true, false, false, true, false, false, true, false, false) ];