define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'modules/templates/picture'], function (AddQuestion, Option, Common, Picture) { var q = function (sm, question, index) { this.sectionmodule = sm; this.section = sm.section; this.question = question; this.holder = null; this.questionholder = null; this.index = index; this.txtName = null; this.txtDisplayText = null; this.selQuestionType = null; this.chkIsRequired = null; this.chkCanComment = null; this.chkIsImportant = null; this.chkCustomerVisible = null; this.selSeverityLevel = null; this.txtNotes = null; this.chkMultipleSelect = null; this.selLookupSource = null; this.selSubType = null; this.txtTransactionDate = null; this.selState = null; this.selFuelType = null; this.selDistributedBy = null; this.txtBarCodeValidate = null; this.optionholder = undefined; this.optiondiv = undefined; this.btnoption = undefined; this.optiontr = undefined; this.optiontd = undefined; this.multipleselectdiv = null; this.lookupsourcespan = null; this.additemspan = null; this.optionmodules = []; this.saving = false; this.datachanged = false; }; q.prototype.moduletype = "question"; q.prototype.description = "Question Module"; q.prototype.version = "1.0.0.0"; q.prototype.ondelete = null; q.prototype.createContent = function () { var _this = this; if (sectiontype === 0) { if (!_this.question.IssueId || _this.question.IssueId == "") editable = true; else editable = false; } var holder = $('
'); _this.holder = holder; var qholder = $('
');//question holder holder.append(qholder); _this.questionholder = qholder; var oholder = $('
');//option holder holder.append(oholder); _this.optionholder = oholder; if (this.index % 2 == 1) qholder.addClass('holder-even'); var drag = $('
'); qholder.append(drag); if (!_this.section.IsLink && sectiontype == 1) { drag.attr('draggable', true); holder.bind('dragstart', function (e) { //var data = e.originalEvent.dataTransfer; draggingobj = _this; }); holder.bind('dragend', function (e) { draggingobj = null; }); holder.bind('dragover', function (e) { e.originalEvent.preventDefault() }); holder.bind('drop', function (e) { if (!draggingobj || _this === draggingobj) return; if (draggingobj.moduletype == "question") { var t = $(this); var after = e.originalEvent.clientY > t.offset().top + t.height() / 2; if (after) t.after(draggingobj.holder); else t.before(draggingobj.holder); draggingobj.sectionmodule.dragOutQuestion(draggingobj); _this.sectionmodule.dragInQuestion(_this.question, draggingobj, after); } else {//section dragging if (_this.sectionmodule === draggingobj) return; else _this.sectionmodule.dragInSection(); } }); } else drag.children().remove(); if (templatereadonly || !editable) drag.hide(); qholder.append('
'); _this.txtName = $(''); var addiText = $(''); addiText.click(function () { Common.createMultiTextDialog(_this.txtName, _this.question); }); qholder.append($('
').append(this.txtName).append(addiText)); _this.txtDisplayText = $(''); addiText = $(''); addiText.click(function () { Common.createMultiTextDialog(_this.txtDisplayText, _this.question); }); var imgicon = $(''); imgicon.click(function (e) { var picturemodule = new Picture(false, _this.question, function () { _this.onsave() }); picturemodule.createContent(); //Common.createImageDialog(_this.txtDisplayText, _this.question); }); qholder.append($('
').append(this.txtDisplayText).append(addiText).append(imgicon)); //this.selQuestionTypeÔÚcreateQuestionTypeCtrlÖи³Öµ var qt = createQuestionTypeCtrl().css('width', 140); qholder.append($('
').append(qt)); createOptions(); _this.chkIsRequired = $(''); qholder.append($('
').append(this.chkIsRequired)); _this.chkCanComment = $(''); qholder.append($('
').append(this.chkCanComment)); _this.chkIsImportant = $(''); qholder.append($('
').append(this.chkIsImportant)); _this.chkCustomerVisible = $(''); qholder.append($('
').append(this.chkCustomerVisible)); _this.selSeverityLevel = createSeverityLevel().addClass('question-input').css('width', 70); qholder.append($('
').append(this.selSeverityLevel)); _this.txtNotes = $(''); qholder.append($('
').append(this.txtNotes)); var funcs = $('
'); qholder.append(funcs); //qholder.find('.question-name span').click(function () { // _this.onedit(); //}); //qholder.find('.question-display span').click(function () { // _this.onedit(); //}); if (_this.question.IsLink) { qholder.find('.question-name input').before(''); qholder.find('input').prop('disabled', true); qholder.find('select').prop('disabled', true); qholder.find('textarea').prop('disabled', true); qholder.find('.iconmultitext').remove(); qholder.find('.iconimage').remove(); } if (!templatereadonly && editable) { if (!_this.section.IsLink && sectiontype == 1 /*&& !_this.question.IsLink*/) { funcs.append($('').click(function () { if (_this.oncopy) _this.oncopy(_this.getQuestionValue(true, true)); }).attr('title', GetTextByKey("P_IPT_COPYQUESTION", 'Copy Question'))); } //if (!_this.question.IsLink) { // funcs.append($('').click(function () { // _this.onedit(); // }).attr('title', 'Edit Question')); //} if (!_this.section.IsLink) { funcs.append($('').click(function () { if (sectiontype == 0) { _this.delete(); } else { showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISQUESTION", 'Are you sure you want to delete this question?'), GetTextByKey("P_IPT_DELETEQUESTION", 'Delete Question'), function () { if (_this.ondelete) { _this.holder.remove(); _this.ondelete(_this); } }); } }).attr('title', GetTextByKey("P_IPT_DELETEQUESTION", 'Delete Question'))); } } if (_this.question != null) { _this.updateContent(_this.question); } if (templatereadonly || !editable) setDisabled(); function createQuestionTypeCtrl() { var tb = $('
'); var tr = $(''); tb.append(tr); var td = $(''); tr.append(td); _this.selQuestionType = createQuestionType().addClass('question-input'); td.append(_this.selQuestionType); _this.selQuestionType.change(function () { _this.questionTypeChange(true); }); td = $(''); tr.append(td); _this.btnoption = $(''); td.append(_this.btnoption); _this.btnoption.click(function () { var icon = $(this); var type = _this.selQuestionType.val(); if (icon.hasClass('iconangleleft')) { icon.removeClass('iconangleleft').addClass('iconangledown'); _this.optionholder.show(); if (type === "8" || type === "9") _this.multipleselectdiv.show(); else _this.multipleselectdiv.hide(); } else { icon.removeClass('iconangledown').addClass('iconangleleft'); _this.optionholder.hide(); } }); td = $(''); tr.append(td); _this.selSubType = createSubType().addClass('question-input').css({ 'width': 128, 'margin-left': '3px' }); _this.selSubType.change(function () { _this.subTypeChange(true); }); td.append(_this.selSubType); td = $(''); tr.append(td); _this.txtTransactionDate = $('').css({ 'width': 100, 'margin-left': '3px' }); _this.txtTransactionDate.hide(); _this.txtTransactionDate.datetimepicker({ timepicker: false, format: 'm/d/Y', enterLikeTab: false }); _this.txtTransactionDate.change(function () { _this.transactionDateChange(true); }); td.append(_this.txtTransactionDate); _this.selState = createState().addClass('question-input').css({ 'width': 116, 'margin-left': '3px' }); _this.selState.hide(); _this.selState.change(function () { _this.stateChange(true); }); td.append(_this.selState); _this.selFuelType = createFuelType().addClass('question-input').css({ 'width': 116, 'margin-left': '3px' }); _this.selFuelType.hide(); _this.selFuelType.change(function () { _this.fuelTypeChange(true); }); td.append(_this.selFuelType); _this.selDistributedBy = createDistributedBy().addClass('question-input').css({ 'width': 116, 'margin-left': '3px' }); _this.selDistributedBy.hide(); _this.selDistributedBy.change(function () { _this.distributedByChange(true); }); td.append(_this.selDistributedBy); td = $(''); tr.append(td); _this.txtBarCodeValidate = $(''); _this.txtBarCodeValidate.focus(function () { if (_this.txtBarCodeValidate.attr("isValue") === "0") { _this.txtBarCodeValidate.val(""); _this.txtBarCodeValidate.removeClass("prompttext"); } }); _this.txtBarCodeValidate.blur(function () { if (_this.txtBarCodeValidate.val() == "") { _this.txtBarCodeValidate.attr("isValue", "0"); _this.txtBarCodeValidate.val(_this.txtBarCodeValidate.attr("promptText")); _this.txtBarCodeValidate.addClass("prompttext"); } }); td.append(_this.txtBarCodeValidate); if (_this.question.IsLink) _this.btnoption.remove(); //tb = $('
'); //_this.multipleselectdiv = $(''); //_this.chkMultipleSelect = $(''); //_this.multipleselectdiv.append(_this.chkMultipleSelect); //_this.optiontr = $(''); //tb.append(_this.optiontr); //var btn_additem = $('Add Item').click(function () { // _this.addOption(); //}); //_this.optiontd = $(''); //_this.optiontd.append('Options'); //_this.optiontd.append(btn_additem); //_this.optiontd.append(_this.multipleselectdiv); //_this.optiontr.append(_this.optiontd); return tb; } function createOptions() { _this.optiondiv = $('
'); _this.optionholder.append(_this.optiondiv); _this.multipleselectdiv = $(''); _this.chkMultipleSelect = $(''); _this.multipleselectdiv.append(_this.chkMultipleSelect); _this.additemspan = $('' + GetTextByKey("P_IPT_ADDITEM", "Add Item") + '').click(function () { _this.addOption(); }); _this.lookupsourcespan = $(''); _this.selLookupSource = createLookupSource().addClass('question-input').css({ 'width': 150, 'margin-left': '5px' }); _this.selLookupSource.change(function () { _this.lookupSourcesChange(true); }); _this.lookupsourcespan.append(_this.selLookupSource); _this.optiondiv.append('' + GetTextByKey("P_IPT_OPTIONS", "Options") + ''); _this.optiondiv.append(_this.additemspan); _this.optiondiv.append(_this.multipleselectdiv); _this.optiondiv.append(_this.lookupsourcespan); } function createQuestionType() { var items = []; items.push({ 'Key': 0, "Value": GetTextByKey("P_IPT_QT_SINGLELINETEXT", "Single Line Text") }); items.push({ 'Key': 1, "Value": GetTextByKey("P_IPT_QT_MULTIPLELINETEXT", "Multiple Line Text") }); items.push({ 'Key': 2, "Value": GetTextByKey("P_IPT_QT_EMAILMANUAL", "Email (Manual)") }); items.push({ 'Key': 14, "Value": GetTextByKey("P_IPT_QT_EMAILDROPDOWN", "Email (Drop Down)") }); items.push({ 'Key': 3, "Value": GetTextByKey("P_IPT_QT_NUMBER", "Number") }); items.push({ 'Key': 4, "Value": GetTextByKey("P_IPT_QT_INTEGER", "Integer") }); items.push({ 'Key': 5, "Value": GetTextByKey("P_IPT_QT_YESORNO", "Yes Or No") }); items.push({ 'Key': 6, "Value": GetTextByKey("P_IPT_QT_DATE", "Date") }); items.push({ 'Key': 7, "Value": GetTextByKey("P_IPT_QT_DATEANDTIME", "Date And Time") }); items.push({ 'Key': 8, "Value": GetTextByKey("P_IPT_QT_DROPDOWN", "Drop Down") }); items.push({ 'Key': 9, "Value": GetTextByKey("P_IPT_QT_LIST", "List") }); items.push({ 'Key': 10, "Value": GetTextByKey("P_IPT_QT_PICTURE", "Picture") }); if (!teamintelligence) { items.push({ 'Key': 11, "Value": GetTextByKey("P_IPT_QT_ODOMETER", "Odometer") }); items.push({ 'Key': 12, "Value": GetTextByKey("P_IPT_QT_ENGINEHOURS", "Engine Hours") }); items.push({ 'Key': 13, "Value": GetTextByKey("P_IPT_QT_FUELREMAINING", "Fuel Remaining") }); items.push({ 'Key': 15, "Value": GetTextByKey("P_IPT_QT_FUELRECORDS", "Fuel Records") }); } items.push({ 'Key': 16, "Value": GetTextByKey("P_IPT_QT_BARCODE", "Bar Code") }); items.push({ 'Key': 17, "Value": GetTextByKey("P_IPT_QT_BARCODEVALIDATE", "Bar Code Validate") }); items.push({ 'Key': 18, "Value": GetTextByKey("P_IPT_QT_FUELUSED", "Fuel Used") }); items.push({ 'Key': 19, "Value": GetTextByKey("P_IPT_QT_XXX", "Asset Status") }); var sel = $(''); for (var i = 0; i < items.length; i++) { var item = items[i]; sel.append(''); } return sel; } function createSubType() { var items = []; items.push({ 'Key': 0, "Value": GetTextByKey("P_IPT_ST_TRANSACTIONDATE", "Transaction Date") }); items.push({ 'Key': 1, "Value": GetTextByKey("P_IPT_ST_TICKETRECEIPTNUMBER", "Ticket/Receipt Number") }); items.push({ 'Key': 2, "Value": GetTextByKey("P_IPT_ST_DRIVERNAME", "Driver Name") }); items.push({ 'Key': 3, "Value": GetTextByKey("P_IPT_ST_RETAILERNAME", "Retailer Name") }); items.push({ 'Key': 4, "Value": GetTextByKey("P_IPT_ST_RETAILERADDRESS", "Retailer Address") }); items.push({ 'Key': 5, "Value": GetTextByKey("P_IPT_ST_CITY", "City") }); items.push({ 'Key': 6, "Value": GetTextByKey("P_IPT_ST_STATE", "State") }); items.push({ 'Key': 7, "Value": GetTextByKey("P_IPT_ST_ZIP", "Zip") }); items.push({ 'Key': 8, "Value": GetTextByKey("P_IPT_ST_ODOMETER", "Odometer") }); items.push({ 'Key': 9, "Value": GetTextByKey("P_IPT_ST_FUELTYPE", "Fuel Type") }); items.push({ 'Key': 10, "Value": GetTextByKey("P_IPT_ST_QUANTITY", "Quantity") }); items.push({ 'Key': 11, "Value": GetTextByKey("P_IPT_ST_UOMCOST", "Unit Cost") }); items.push({ 'Key': 12, "Value": GetTextByKey("P_IPT_ST_TOTALCOST", "Total Cost") }); items.push({ 'Key': 13, "Value": GetTextByKey("P_IPT_ST_BRANDNAME", "Brand Name") }); items.push({ 'Key': 14, "Value": GetTextByKey("P_IPT_ST_NOTES", "Notes") }); items.push({ 'Key': 15, "Value": GetTextByKey("P_IPT_ST_PICTURE", "Picture") }); items.push({ 'Key': 16, "Value": GetTextByKey("P_IPT_ST_DISTRIBUTEDBY", "Distributed By") }); var sel = $(''); for (var i = 0; i < items.length; i++) { var item = items[i]; sel.append(''); } return sel; } function createDistributedBy() { var items = []; items.push({ 'Key': "", "Value": "" }); items.push({ 'Key': "0", "Value": GetTextByKey("P_FR_FUELINGSTATION", "Fueling Station") }); items.push({ 'Key': "1", "Value": GetTextByKey("P_FR_FUELINGASSET", "Fueling Asset") }); var sel = $(''); for (var i = 0; i < items.length; i++) { var item = items[i]; sel.append(''); } return sel; } function createState() { var items = []; items.push("", "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"); var sel = $(''); for (var i = 0; i < items.length; i++) { var item = items[i]; sel.append(''); } return sel; } function createFuelType() { var sel = $(''); sel.append(''); if (typeof fuelTypes !== 'undefined') { if (fuelTypes && fuelTypes.length > 0) { for (var i = 0; i < fuelTypes.length; i++) { var item = fuelTypes[i]; sel.append(''); } } if (_this.question && _this.question.QuestionType === 15 && _this.question.SubType === 9) sel.val(_this.question.DefaultValue); return sel; } inspectionrequest("GetFuelTypes", '', function (data) { if (typeof (data) === "string") return sel; if (data && data.length > 0) { for (var i = 0; i < data.length; i++) { var item = data[i]; sel.append(''); } } if (_this.question && _this.question.QuestionType === 15 && _this.question.SubType === 9) sel.val(_this.question.DefaultValue); }, function (err) { }); return sel; } function createSeverityLevel() { var items = []; items.push({ 'Key': 0, "Value": GetTextByKey("P_IPT_SL_NONE", "None") }); items.push({ 'Key': 1, "Value": GetTextByKey("P_IPT_SL_LOW", "Low") }); items.push({ 'Key': 2, "Value": GetTextByKey("P_IPT_SL_MEDIUM", "Medium") }); items.push({ 'Key': 3, "Value": GetTextByKey("P_IPT_SL_HIGH", "High") }); var sel = $(''); for (var i = 0; i < items.length; i++) { var item = items[i]; sel.append(''); } return sel; } function createLookupSource() { var items = []; items.push({ 'Key': 0, "Value": GetTextByKey("P_IPT_LS_MANUALINPUT", "Manual Input") }); items.push({ 'Key': 1, "Value": GetTextByKey("P_IPT_LS_JOBSITES", "Jobsites") }); items.push({ 'Key': 2, "Value": GetTextByKey("P_IPT_LS_ASSETS", "Assets") }); items.push({ 'Key': 4, "Value": GetTextByKey("P_IPT_LS_ASSETNAMECUSTOM", "Asset Name Custom") }); items.push({ 'Key': 3, "Value": GetTextByKey("P_IPT_LS_EMPLOYEES", "Employees") }); var sel = $(''); for (var i = 0; i < items.length; i++) { var item = items[i]; sel.append(''); } return sel; } function controlSaveEvent() { _this.txtName.change(function () { _this.onsave(); }); _this.txtDisplayText.change(function () { _this.onsave(); }); _this.chkIsRequired.click(function () { _this.onsave(); }); _this.chkCanComment.click(function () { _this.onsave(); }); _this.chkIsImportant.click(function () { _this.onsave(); }); _this.chkCustomerVisible.click(function () { _this.onsave(); }); _this.selSeverityLevel.change(function () { _this.onsave(); }); _this.txtNotes.blur(function () { _this.onsave(); }); _this.chkMultipleSelect.click(function () { _this.onsave(); }); _this.txtBarCodeValidate.change(function () { if (_this.txtBarCodeValidate.val() == "") { _this.txtBarCodeValidate.attr("isValue", "0"); _this.txtBarCodeValidate.val(_this.txtBarCodeValidate.attr("promptText")); _this.txtBarCodeValidate.addClass("prompttext"); } else { _this.txtBarCodeValidate.attr("isValue", "1"); } _this.onsave(); }); } function setDisabled() { _this.txtName.prop('disabled', true); _this.txtDisplayText.prop('disabled', true); _this.chkIsRequired.prop('disabled', true); _this.chkCanComment.prop('disabled', true); _this.chkIsImportant.prop('disabled', true); _this.chkCustomerVisible.prop('disabled', true); _this.selSeverityLevel.prop('disabled', true); _this.txtNotes.prop('disabled', true); _this.chkMultipleSelect.prop('disabled', true); _this.selQuestionType.prop('disabled', true); _this.selLookupSource.prop('disabled', true); _this.selSubType.prop('disabled', true); _this.selDistributedBy.prop('disabled', true); _this.selFuelType.prop('disabled', true); _this.txtTransactionDate.prop('disabled', true); _this.selState.prop('disabled', true); _this.txtBarCodeValidate.prop('disabled', true); _this.additemspan.hide(); _this.holder.find(".iconmultitext").hide(); _this.holder.find(".iconimage").hide(); _this.holder.find(".iconangleleft").hide(); } controlSaveEvent(); return holder; }; q.prototype.questionTypeChange = function (needsave) { var _this = this; _this.optionmodules = []; //_this.optiontd.find('table').remove(); _this.optionholder.find('table').remove(); var type = _this.selQuestionType.val(); questiontype = type; if (['5', '8', '9'].indexOf(type) >= 0) { _this.btnoption.show(); if (_this.btnoption.hasClass('iconangledown')) { if (type === "8" || type === "9") _this.multipleselectdiv.show(); else _this.multipleselectdiv.hide(); //_this.optiontr.show(); _this.optionholder.show(); } if (type === "5") { var ynops = [{ 'Text': GetTextByKey("P_IPT_YES", 'Yes'), 'BackgroundColor': '#0F0', 'Value': 'Yes', 'SeverityLevel': 0 }, { 'Text': GetTextByKey("P_IPT_NO", 'No'), 'BackgroundColor': '#F00', 'Value': 'No', 'SeverityLevel': 0 }]; for (var i = 0; i < ynops.length; i++) { var op = ynops[i]; if (_this.question) { if (i < _this.question.SelectItems.length) { op.BackgroundColor = _this.question.SelectItems[i].BackgroundColor; op.SeverityLevel = _this.question.SelectItems[i].SeverityLevel; op.LocalTexts = _this.question.SelectItems[i].LocalTexts; } } op.removable = false; _this.addOption(op, false); } //_this.optiontr.find('.sbutton').hide(); _this.optionholder.find('.sbutton').hide(); } else { //_this.optiontr.find('.sbutton').show(); _this.optionholder.find('.sbutton').show(); if (_this.question) { for (var i = 0; i < _this.question.SelectItems.length; i++) { _this.addOption(_this.question.SelectItems[i]); } } else _this.addOption(); } if (type === "8") { _this.lookupsourcespan.show(); } else { _this.lookupsourcespan.hide(); } } else { _this.btnoption.hide(); //_this.optiontr.hide(); _this.optionholder.hide() //_this.multipleselectdiv.hide(); } _this.txtTransactionDate.hide(); _this.selState.hide(); _this.selFuelType.hide(); _this.selDistributedBy.hide(); if (type === "15" || type === "17") { if (type === "15") { _this.selSubType.show(); _this.questionholder.attr('title', GetTextByKey("P_IPT_THESEQUESTIONSCREATEFUELRECORDSINASSETHEALTH", 'These questions create Fuel Records in Asset Health')); _this.txtBarCodeValidate.hide(); var subtype = _this.selSubType.val(); //if (subtype === "0") // _this.txtTransactionDate.show(); if (subtype === "6") _this.selState.show(); else if (subtype === "9") _this.selFuelType.show(); else if (subtype === "16") _this.selDistributedBy.show() } else { _this.selSubType.hide(); _this.questionholder.removeAttr('title'); _this.txtBarCodeValidate.show(); } } else { _this.selSubType.hide(); _this.txtBarCodeValidate.hide(); if (!this.question.IsLink) _this.chkIsRequired.prop('disabled', false); _this.questionholder.removeAttr('title'); } if (needsave) _this.onsave(); } q.prototype.lookupSourcesChange = function (needsave) { var _this = this; var type = _this.selQuestionType.val(); var source = _this.selLookupSource.val(); if (type === "8" && source !== "0") { _this.additemspan.hide(); _this.optionholder.find('table').remove(); _this.optionmodules = []; } else { _this.additemspan.show(); } if (needsave) _this.onsave(); } q.prototype.subTypeChange = function (needsave) { var _this = this; _this.txtTransactionDate.hide(); _this.selState.hide(); _this.selFuelType.hide(); _this.selDistributedBy.hide(); var subtype = _this.selSubType.val(); //if (subtype === "0") // _this.txtTransactionDate.show(); if (subtype === "6") _this.selState.show(); else if (subtype === "9") _this.selFuelType.show(); else if (subtype === "16") _this.selDistributedBy.show() if (needsave) _this.onsave(); } q.prototype.distributedByChange = function (needsave) { var _this = this; if (needsave) _this.onsave(); } q.prototype.stateChange = function (needsave) { var _this = this; if (needsave) _this.onsave(); } q.prototype.transactionDateChange = function (needsave) { var _this = this; if (needsave) _this.onsave(); } q.prototype.fuelTypeChange = function (needsave) { var _this = this; if (needsave) _this.onsave(); } q.prototype.addOption = function (item, texteditable) { var _this = this; var op = new Option(_this, item); op.onremove = function (item) { _this.optionmodules.splice(_this.optionmodules.indexOf(item), 1); } if (texteditable != undefined || texteditable != null) op.texteditable = texteditable; _this.optionmodules.push(op); //_this.optiontd.append(op.createContent()); _this.optiondiv.append(op.createContent()); } q.prototype.onedit = function () { var _this = this; var aq = new AddQuestion(_this.sectionmodule, _this.section.Id, _this.question); if (sectiontype == 0) { $('#right_popup').empty().append(aq.createContent()); showRightPopup(true); } else { aq.onsave = function (question) { _this.question.Name = question.Name; _this.question.DisplayText = question.DisplayText; _this.question.Notes = question.Notes; _this.question.LocalNames = question.LocalNames; _this.question.LocalDisplayTexts = question.LocalDisplayTexts; _this.question.QuestionType = question.QuestionType; _this.question.IsRequired = question.IsRequired; _this.question.CanComment = question.CanComment; _this.question.IsImportant = question.IsImportant; _this.question.SeverityLevel = question.SeverityLevel; _this.question.SelectItems = question.SelectItems; _this.updateContent(_this.question); } $('#right_popup1').empty().append(aq.createContent()).show(); } } q.prototype.updateContent = function (question) { if (this.question != question) { this.question = question; } this.txtName.val(question.Name).data("texts", question.LocalNames); this.txtDisplayText.val(question.DisplayText).data("texts", question.LocalDisplayTexts); this.selQuestionType.val(question.QuestionType); this.questionTypeChange(false); this.chkIsRequired.attr('checked', question.IsRequired); this.chkCanComment.attr('checked', question.CanComment); this.chkIsImportant.attr('checked', question.IsImportant); this.chkCustomerVisible.attr('checked', question.VisibleToCustomer); this.selSeverityLevel.val(question.SeverityLevel); this.txtNotes.val(question.Notes); this.chkMultipleSelect.attr('checked', question.MultipleSelect); this.selLookupSource.val(question.LookupSource); this.lookupSourcesChange(false); if (question.QuestionType == 15) { this.selSubType.val(question.SubType); //if (question.SubType === 0) // this.txtTransactionDate.val(question.DefaultValue); if (question.SubType === 6) this.selState.val(question.DefaultValue); else if (question.SubType === 9) this.selFuelType.val(question.DefaultValue); else if (question.SubType === 16) this.selDistributedBy.val(question.DefaultValue); this.subTypeChange(false); } this.txtBarCodeValidate.val(question.TextToCompare); if (this.txtBarCodeValidate.val() == "") { this.txtBarCodeValidate.attr("isValue", "0"); this.txtBarCodeValidate.val(this.txtBarCodeValidate.attr("promptText")); this.txtBarCodeValidate.addClass("prompttext"); } else { this.txtBarCodeValidate.attr("isValue", "1"); this.txtBarCodeValidate.removeClass("prompttext"); } }; q.prototype.getQuestionValue = function (noalert, nocheck) { var question = this.question; question.Name = this.txtName.val(); question.DisplayText = this.txtDisplayText.val(); var texts = this.txtName.data("texts"); if (texts) { question.LocalNames = texts; } texts = this.txtDisplayText.data("texts"); if (texts) { question.LocalDisplayTexts = texts; } question.QuestionType = this.selQuestionType.val(); question.IsRequired = this.chkIsRequired.prop('checked'); question.CanComment = this.chkCanComment.prop('checked'); question.IsImportant = this.chkIsImportant.prop('checked'); question.VisibleToCustomer = this.chkCustomerVisible.prop('checked'); question.SeverityLevel = this.selSeverityLevel.val(); question.Notes = this.txtNotes.val(); if (question.QuestionType === "8" || question.QuestionType === "9") question.MultipleSelect = this.chkMultipleSelect.prop('checked'); else question.MultipleSelect = false; question.LookupSource = this.selLookupSource.val(); question.SubType = this.selSubType.val(); //if (question.SubType === "0") // question.DefaultValue = this.txtTransactionDate.val(); if (question.SubType === "6") question.DefaultValue = this.selState.val(); else if (question.SubType === "9") question.DefaultValue = this.selFuelType.val(); else if (question.SubType === "16") question.DefaultValue = this.selDistributedBy.val(); question.TextToCompare = this.txtBarCodeValidate.val(); if (this.txtBarCodeValidate.attr("isValue") === "0") { question.TextToCompare = ""; } question.SelectItems = []; var alerttitle = GetTextByKey("P_IPT_QUESTION", "Question"); if (!nocheck) { if (!question.Name || question.Name.length == 0) { if (!noalert) showAlert(GetTextByKey("P_IPT_QUESTIONNAMENOTBEEMPTY", 'Question Name cannot be empty.'), alerttitle); return false; } if (!question.DisplayText || question.DisplayText.length == 0) { if (!noalert) showAlert(GetTextByKey("P_IPT_QUESTIONDISPLAYTEXTNOTBEEMPTY", 'Question Display Text cannot be empty.'), alerttitle); return false; } if (question.QuestionType == "17" && question.IsRequired == true && (!question.TextToCompare || question.TextToCompare.length == 0)) { if (!noalert) showAlert(GetTextByKey("P_IPT_TEXTTPCOMPARENOTBEEMPTY", 'Text to compare cannot be empty.'), alerttitle); return false; } } if (this.optionmodules.length > 0) { for (var i = 0; i < this.optionmodules.length; i++) { var selectitem = this.optionmodules[i].getOptionValue(); if (!nocheck) { if (!selectitem.Text || selectitem.Text.length == 0) { if (!noalert) showAlert(GetTextByKey("P_IPT_OPTIONNAMECANNOTBEEMPTY", 'Option name cannot be empty.'), alerttitle); return false; } } question.SelectItems.push(selectitem) } } //if (!nocheck && !noalert) { // if (!noalert) { // if ((question.QuestionType === "8" || question.QuestionType === "9") && question.SelectItems.length == 0) { // showAlert('There must be at least one choice.', alerttitle); // return false; // } // } //} return question; }; q.prototype.delete = function () { var _this = this; showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISQUESTION", 'Are you sure you want to delete this question?'), GetTextByKey("P_IPT_DELETEQUESTION", "Delete Question"), function () { if (!_this.question.Id) { _this.holder.remove(); return; } var p = JSON.stringify([teamintelligence, htmlencode(_this.question.Id)]); inspectionrequest("DeleteGlobalQuestion", p, function (data) { if (data !== 'OK') showAlert(data, GetTextByKey("P_IPT_DELETEQUESTION", "Delete Question")); else if (_this.sectionmodule && typeof _this.sectionmodule.refresh === "function") _this.sectionmodule.refresh(); }, function (err) { showAlert(GetTextByKey("P_IPT_FAILEDTODELETEQUESTION", 'Failed to delete question.'), GetTextByKey("P_IPT_DELETEQUESTION", "Delete Question")); }); }); }; q.prototype.onsave = function () { var _this = this; if (sectiontype == 1) return; var item = _this.getQuestionValue(true); if (!item) return; if (_this.saving) { _this.datachanged = true; return; } var param = JSON.stringify(item); param = htmlencode(param); _this.saving = true; var p = JSON.stringify([teamintelligence, _this.section.Id, param]); inspectionrequest("SaveGlobalQuestion", p, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_IPT_SAVEQUESTION", 'Save Question')); } else { if (!_this.question) _this.question = {}; _this.question.Id = data[0]; } _this.saving = false; if (_this.datachanged) _this.onsave(); }, function (err) { showAlert(GetTextByKey("P_IPT_FAILEDTOSAVEQUESTION", 'Failed to save question.'), GetTextByKey("P_IPT_SAVEQUESTION", 'Save Question')); _this.saving = false; if (_this.datachanged) _this.onsave(); }); } return q; });