add site
This commit is contained in:
		
							
								
								
									
										449
									
								
								Site/Inspection/js/common.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										449
									
								
								Site/Inspection/js/common.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,449 @@ | ||||
| define(function () { | ||||
|     //define([], function () {//ʹ<><CAB9><EFBFBD>ⲿ<EFBFBD><E2B2BF>$<24><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dialog,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ||||
|     var gs = {}; | ||||
|     gs.title = 'Common'; | ||||
|     gs.description = 'Common'; | ||||
|     gs.version = '1.0'; | ||||
|  | ||||
|     (function () { | ||||
|         'use strict'; | ||||
|  | ||||
|         var iX, iY; | ||||
|  | ||||
|         function dragTitle(ev) { | ||||
|             if (ev.target && ev.target.nodeName === 'EM') | ||||
|                 return false; | ||||
|  | ||||
|             var dialog = ev.data; | ||||
|  | ||||
|             window.draggingDialog = dialog; | ||||
|             var o = getInnerOffset(dialog); | ||||
|             iX = ev.clientX - o.left; | ||||
|             iY = ev.clientY - o.top; | ||||
|             $(document).mousemove(dragmove); | ||||
|             $(document).mouseup(dragup); | ||||
|             var _this = this; | ||||
|             _this.setCapture && _this.setCapture(); | ||||
|  | ||||
|             var window_width = $(window).width(); | ||||
|             var window_height = $(window).height(); | ||||
|             var dragging_width = dialog.width(); | ||||
|             var dragging_height = dialog.height(); | ||||
|             function dragmove(e) { | ||||
|                 var e = e || window.event; | ||||
|                 var left, top; | ||||
|                 left = Math.max(Math.min((e.clientX - iX), window_width - dragging_width - 2), 0); | ||||
|                 top = Math.max(Math.min((e.clientY - iY), window_height - dragging_height - 2), 0); | ||||
|                 window.draggingDialog.css({ | ||||
|                     'left': left, | ||||
|                     'top': top | ||||
|                 }); | ||||
|             }; | ||||
|             function dragup(e) { | ||||
|                 $(document).unbind('mousemove', dragmove); | ||||
|                 $(document).unbind('mouseup', dragup); | ||||
|                 delete window.draggingDialog; | ||||
|                 _this.releaseCapture && _this.releaseCapture(); | ||||
|                 e.cancelBubble = true; | ||||
|             }; | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         $.fn.dialog = function (closefunc, removable) { | ||||
|             this.children('.dialog-title').mousedown(this, dragTitle); | ||||
|             this.find('.dialog-close').click(this, function (e) { | ||||
|                 if (removable) { | ||||
|                     e.data.remove(); | ||||
|                 } else { | ||||
|                     e.data.hideDialog(); | ||||
|                 } | ||||
|                 if (typeof closefunc === 'function') { | ||||
|                     closefunc(e); | ||||
|                 } | ||||
|             }); | ||||
|  | ||||
|             this.find('input.dialog-close').keydown(resettab); | ||||
|             var _this = this; | ||||
|             function resettab(e) { | ||||
|                 if (e.keyCode == 9) { | ||||
|                     var input = _this.find("input:not(:disabled),select:not(:disabled)").eq(0); | ||||
|                     input.focus(); | ||||
|                     return false; | ||||
|                 } | ||||
|             } | ||||
|             this.css({ | ||||
|                 'top': (document.documentElement.clientHeight - this.height()) / 2, | ||||
|                 'left': (document.documentElement.clientWidth - this.width()) / 2 | ||||
|             }); | ||||
|  | ||||
|             return this; | ||||
|         }; | ||||
|  | ||||
|         $.fn.showDialog = function (selfmask) { | ||||
|             //$('#mask_bg').height($(document).outerHeight(false)).width($(document).outerWidth(false)); | ||||
|             if (this.attr("init") !== "1") { | ||||
|                 this.attr("init", "1"); | ||||
|                 var _this = this; | ||||
|  | ||||
|                 if (selfmask !== false) { | ||||
|                     var mask = $('<div class="maskbg"></div>'); | ||||
|                     this.mask = mask; | ||||
|                     this.before(mask); | ||||
|                 } | ||||
|                 $(window).resize(function () { | ||||
|                     //_this.height(_this.parent().outerHeight(false) - 64).width(_this.parent().outerWidth(false) - left - 2); | ||||
|                     if (_this.mask) | ||||
|                         _this.mask.height($(document).outerHeight(false) - 64).width($(document).outerWidth(false)); | ||||
|                 }); | ||||
|             } | ||||
|  | ||||
|             if (this.mask) | ||||
|                 this.mask.show(); | ||||
|             this.show(); | ||||
|  | ||||
|             var top = (document.documentElement.clientHeight - this.height()) / 2; | ||||
|             if (top < 0) top = 0; | ||||
|             var left = (document.documentElement.clientWidth - this.width()) / 2; | ||||
|             if (left < 0) left = 0; | ||||
|             this.css({ | ||||
|                 'top': top, 'left': left | ||||
|             }); | ||||
|  | ||||
|             var input = this.find("input:not(:disabled),select:not(:disabled)").eq(0); | ||||
|             input.focus(); | ||||
|             return this; | ||||
|         }; | ||||
|  | ||||
|         $.fn.showDialogfixed = function (selfmask) { | ||||
|             if (this.attr("init") !== "1") { | ||||
|                 this.attr("init", "1"); | ||||
|                 var _this = this; | ||||
|  | ||||
|                 if (selfmask !== false) { | ||||
|                     var mask = $('<div class="maskbg"></div>'); | ||||
|                     this.mask = mask; | ||||
|                     this.before(mask); | ||||
|                 } | ||||
|             } | ||||
|             var top = (document.documentElement.clientHeight - this.height()) / 3; | ||||
|             if (top < 0) top = 0; | ||||
|             var left = (document.documentElement.clientWidth - this.width()) / 2; | ||||
|             if (left < 0) left = 0; | ||||
|             this.css({ | ||||
|                 'top': top, 'left': left | ||||
|             }); | ||||
|  | ||||
|             if (this.mask) | ||||
|                 this.mask.show(); | ||||
|             this.show(); | ||||
|             var input = this.find("input:not(:disabled),select:not(:disabled)").eq(0); | ||||
|             input.focus(); | ||||
|         }; | ||||
|  | ||||
|         $.fn.hideDialog = function () { | ||||
|             this.hide(); | ||||
|             if (this.mask) | ||||
|                 this.mask.hide(); | ||||
|         }; | ||||
|     })(); | ||||
|  | ||||
|     gs.createDialog = function (title, content, onok, ispicture) { | ||||
|         var d = $('<div class="dialog" style="width: 360px;display:none;"></div>'); | ||||
|         var t = $('<div class="dialog-title"><span class="title"></span><em class="dialog-close"></em></div>'); | ||||
|         t.find('.title').text(title); | ||||
|         d.append(t); | ||||
|  | ||||
|         var c = $('<div class="dialog-content"></div>'); | ||||
|         c.append(content); | ||||
|         d.append(c); | ||||
|  | ||||
|         var funcs = $('<div class="dialog-func"></div>'); | ||||
|         if (!ispicture) | ||||
|             funcs.append($('<input type="button" value="' + GetTextByKey("P_IPT_CANCEL", "Cancel") + '" class="dialog-close" tabindex="9999" />')); | ||||
|         if (!ispicture || (ispicture && !templatereadonly && editable)) | ||||
|             funcs.append($('<input type="button" value="' + GetTextByKey("P_IPT_OK", "OK") + '" tabindex="9998" />').click(onok)); | ||||
|         funcs.append('<div class="clear"></div>'); | ||||
|         d.append(funcs); | ||||
|  | ||||
|         d.dialog(function () { | ||||
|             d.hide(); | ||||
|         }); | ||||
|  | ||||
|         $(document.body).append(d); | ||||
|  | ||||
|         return d; | ||||
|     } | ||||
|  | ||||
|     gs.createMultiTextDialog = function (textbox, pageele) { | ||||
|         if (pageele) { | ||||
|             if (!pageele.IssueId || pageele.IssueId == "") | ||||
|                 editable = true; | ||||
|             else | ||||
|                 editable = false; | ||||
|         } | ||||
|  | ||||
|         var languages = [{ Key: 'fr-fr', Label: GetTextByKey("P_IPT_FRENCH", 'French') }, { Key: 'es-es', Label: GetTextByKey("P_IPT_SPANISH", 'Spanish') }]; | ||||
|         var inputs = []; | ||||
|  | ||||
|         var d = $('<div class="dialog textdialog" style="width: 380px;min-width:380px;box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 5px 0px;"></div>'); | ||||
|         var c = $('<div class="dialog-content" style="margin-top:5px;min-height:unset;"></div>'); | ||||
|         d.append(c); | ||||
|  | ||||
|         var tb = $('<table style="line-height: 30px;"></table>'); | ||||
|         c.append(tb); | ||||
|  | ||||
|         var tr = null; | ||||
|         var input = null; | ||||
|         for (var i = 0; i < languages.length; i++) { | ||||
|             var l = languages[i]; | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append($('<td class="label" style="width:80px;"></td>').text(l.Label)); | ||||
|             input = $('<input type="text" class="form-control" style="width:220px"  autocomplete="off"/>').attr("tabindex", i + 1); | ||||
|             if (textbox.attr("maxlength")) | ||||
|                 input.attr("maxlength", textbox.attr("maxlength")); | ||||
|             if (templatereadonly || !editable) | ||||
|                 input.prop('disabled', true); | ||||
|             inputs[l.Key] = input; | ||||
|  | ||||
|             var texts = textbox.data("texts") | ||||
|             if (texts) { | ||||
|                 for (var j in texts) { | ||||
|                     var t = texts[j]; | ||||
|                     if (t.Key === l.Key) { | ||||
|                         input.val(t.Value); | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             tr.append($('<td></td>').append(input)); | ||||
|         } | ||||
|  | ||||
|         var funcs = $('<div class="dialog-func"></div>'); | ||||
|         funcs.append($('<input type="button" class="dialog-close" value="' + GetTextByKey("P_IPT_CANCEL", "Cancel") + '" tabindex="9999" />').click(oncancel)); | ||||
|         if (!templatereadonly && editable) | ||||
|             funcs.append($('<input type="button" value="' + GetTextByKey("P_IPT_OK", "OK") + '" tabindex="9998" />').click(onok)); | ||||
|         funcs.append('<div class="clear"></div>'); | ||||
|         d.append(funcs); | ||||
|  | ||||
|         function onok() { | ||||
|             var texts = []; | ||||
|             for (var i in inputs) { | ||||
|                 var input = inputs[i]; | ||||
|                 texts.push({ Key: i, Value: input.val() }); | ||||
|             } | ||||
|             textbox.data("texts", texts); | ||||
|             textbox.change(); | ||||
|             d.remove(); | ||||
|         } | ||||
|         function oncancel() { | ||||
|             d.remove(); | ||||
|         } | ||||
|  | ||||
|         d.css({ | ||||
|             'top': textbox.offset().top + textbox.height() + 5, 'left': textbox.offset().left | ||||
|         }); | ||||
|  | ||||
|         $(document.body).append(d); | ||||
|         $(window).mousedown(function (e) { | ||||
|             if ($(e.target).is(d)) | ||||
|                 return; | ||||
|             else { | ||||
|                 var textdialog = $(e.target).parents(".textdialog"); | ||||
|                 if (textdialog.is(d)) | ||||
|                     return; | ||||
|             } | ||||
|             d.remove(); | ||||
|         }); | ||||
|  | ||||
|         d.find('input.dialog-close').keydown(resettab); | ||||
|         function resettab(e) { | ||||
|             if (e.keyCode == 9) { | ||||
|                 var input = d.find("input:not(:disabled),select:not(:disabled)").eq(0); | ||||
|                 input.focus(); | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return d; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     gs.createImageDialog = function (obj, pageele) {//pageele should contain StaticPictures attr. | ||||
|         var inputs = []; | ||||
|         var tabindex = 0; | ||||
|  | ||||
|         var d = $('<div class="dialog textdialog" style="width: 380px;min-width:380px;box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 5px 0px;"></div>'); | ||||
|         var c = $('<div class="dialog-content" style="margin-top:5px;min-height:unset;"></div>'); | ||||
|         d.append(c); | ||||
|  | ||||
|         var tb = $('<table style="line-height: 30px;"></table>'); | ||||
|         c.append(tb); | ||||
|  | ||||
|         var tr = null; | ||||
|         var input = null; | ||||
|         if (pageele && pageele.StaticPictures && pageele.StaticPictures.length > 0) { | ||||
|             for (var i = 0; i < pageele.StaticPictures.length; i++) { | ||||
|                 var p = pageele.StaticPictures[i]; | ||||
|                 addpicturerow(p); | ||||
|             } | ||||
|         } | ||||
|         else { | ||||
|             addnopicrow(); | ||||
|         } | ||||
|  | ||||
|         var nopictr = null; | ||||
|         function addnopicrow() { | ||||
|             nopictr = $('<tr style="height:30px;"></tr>'); | ||||
|             var td = $('<td style="padding:5px;padding-left:10px;">No Picture</td>'); | ||||
|             nopictr.append(td); | ||||
|             tb.append(nopictr); | ||||
|         } | ||||
|  | ||||
|         function addpicturerow(p) { | ||||
|             if (nopictr) { | ||||
|                 nopictr.remove(); | ||||
|                 nopictr = null; | ||||
|             } | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             var td = $('<td></td>'); | ||||
|             var img = $('<img style="width:40px;height:40px;"/>').attr('src', p.Url); | ||||
|             td.append(img); | ||||
|             tr.append(td); | ||||
|             input = $('<input type="text" class="form-control" style="width:220px" maxlength="100" autocomplete="off"/>').attr("tabindex", ++tabindex); | ||||
|             if (templatereadonly || !editable) | ||||
|                 input.prop('disabled', true); | ||||
|             input.val(p.Name); | ||||
|             input.data("pic", p); | ||||
|             inputs.push(input); | ||||
|  | ||||
|             tr.append($('<td></td>').append(input)); | ||||
|  | ||||
|             td = $('<td></td>'); | ||||
|             if (!templatereadonly && editable) { | ||||
|                 var del = $('<span class="spanbtn icondelete"></span>').click(input, function (e) { | ||||
|                     showConfirm(GetTextByKey("P_IPT_DELETEPICTURECONFIRM", 'Are you sure you want to delete this picture?'), GetTextByKey("P_IPT_DELETEPICTURE", 'Delete Picture'), function () { | ||||
|                         var p = e.data.data("pic"); | ||||
|                         e.data.parent().parent().remove(); | ||||
|                         inputs.splice(inputs.indexOf(e.data), 1); | ||||
|  | ||||
|                         //inspectionrequest("DeleteStaticPicture", p.ContentId, function (data) { | ||||
|                         //}, function (err) { | ||||
|                         //}); | ||||
|                     }); | ||||
|                 }); | ||||
|                 td.append(del) | ||||
|             } | ||||
|             tr.append(td); | ||||
|         } | ||||
|  | ||||
|         function browsePicture() { | ||||
|             var file = $('<input type="file" style="display: none;" accept="image/png,image/jpg,image/jpeg" />'); | ||||
|             file.change(function () { | ||||
|                 var files = this.files; | ||||
|                 var file = files[0]; | ||||
|                 if (file.size == 0) { | ||||
|                     alert(GetTextByKey("P_MA_DOCUMENTTIPS", "Document size is 0kb, uploading failed.")); | ||||
|                     return false; | ||||
|                 } | ||||
|                 if (file.size > 1024 * 1024 * 2) { | ||||
|                     alert(GetTextByKey("P_MA_DOCUMENTTIPS1", "Document is too large. Maximum file size is 2MB.")); | ||||
|                     return false; | ||||
|                 } | ||||
|                 SavePicture(file); | ||||
|             }).click(); | ||||
|         } | ||||
|  | ||||
|         function SavePicture(file) { | ||||
|             var formData = new FormData(); | ||||
|             formData.append("pic", file); | ||||
|             formData.append("MethodName", "UploadStaticPicture"); | ||||
|             $.ajax({ | ||||
|                 url: 'Inspection.aspx', | ||||
|                 type: 'POST', | ||||
|                 dataType: 'json', | ||||
|                 processData: false, | ||||
|                 contentType: false, | ||||
|                 data: formData, | ||||
|                 async: true, | ||||
|                 success: function (data) { | ||||
|                     if (data) { | ||||
|                         var p = {}; | ||||
|                         p.ContentId = data.Item1; | ||||
|                         p.Url = data.Item2; | ||||
|                         p.Name = file.name; | ||||
|                         p.DataType = file.name.substring(file.name.lastIndexOf(".")); | ||||
|                         addpicturerow(p); | ||||
|                     } | ||||
|                 }, | ||||
|                 error: function (err) { | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         if (!templatereadonly && editable) { | ||||
|             var addpicdiv = $('<div style="line-height: 30px;"></div>'); | ||||
|             var addpicicon = $('<span class="sbutton iconadd">Add Picture</span>').click(function () { | ||||
|                 browsePicture(); | ||||
|             }); | ||||
|             addpicdiv.append(addpicicon); | ||||
|             var addtemppicicon = $('<span class="sbutton iconadd">Add Template Picture</span>').click(function () { | ||||
|                 //browsePicture(); | ||||
|             }); | ||||
|             addpicdiv.append(addtemppicicon); | ||||
|             c.append(addpicdiv); | ||||
|         } | ||||
|  | ||||
|         var funcs = $('<div class="dialog-func"></div>'); | ||||
|         funcs.append($('<input type="button" value="' + GetTextByKey("P_IPT_OK", "OK") + '" tabindex="9998" />').click(onok)); | ||||
|         funcs.append('<div class="clear"></div>'); | ||||
|         d.append(funcs); | ||||
|  | ||||
|         function onok() { | ||||
|             if (!templatereadonly && editable) { | ||||
|                 var pics = []; | ||||
|                 for (var i in inputs) { | ||||
|                     var input = inputs[i]; | ||||
|                     var p = input.data("pic"); | ||||
|                     p.Name = input.val(); | ||||
|                     pics.push(p); | ||||
|                 } | ||||
|                 pageele.StaticPictures = pics; | ||||
|             } | ||||
|  | ||||
|             d.remove(); | ||||
|         } | ||||
|  | ||||
|         d.css({ | ||||
|             'top': obj.offset().top + obj.height() + 5, 'left': obj.offset().left | ||||
|         }); | ||||
|  | ||||
|         $(document.body).append(d); | ||||
|         $(window).mousedown(function (e) { | ||||
|             if ($(e.target).is(d)) | ||||
|                 return; | ||||
|             else { | ||||
|                 var textdialog = $(e.target).parents(".textdialog"); | ||||
|                 if (textdialog.is(d)) | ||||
|                     return; | ||||
|             } | ||||
|             d.remove(); | ||||
|         }); | ||||
|  | ||||
|         d.find('input.dialog-close').keydown(resettab); | ||||
|         function resettab(e) { | ||||
|             if (e.keyCode == 9) { | ||||
|                 var input = d.find("input:not(:disabled),select:not(:disabled)").eq(0); | ||||
|                 input.focus(); | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return d; | ||||
|     } | ||||
|  | ||||
|     return gs; | ||||
| }); | ||||
							
								
								
									
										44
									
								
								Site/Inspection/js/main.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								Site/Inspection/js/main.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| require.config({ | ||||
|     baseUrl: 'js', | ||||
|     paths: { | ||||
|         //jquery: "../../js/jquery-3.6.0.min", | ||||
|         //spectrum: "../../js/spectrum" | ||||
|     }, | ||||
|     waitSeconds: 0, | ||||
|     urlArgs: "v=437" //+ Math.random() | ||||
| }) | ||||
|  | ||||
| requirejs(['modules/pageloader'], function (loader) { | ||||
|     loader.links = '.ul_menu .nav_item'; | ||||
|     loader.content = '#set_right'; | ||||
|     loader.init(); | ||||
|  | ||||
|     setFavoriteDisplay(true, teamintelligence ? 700 : 650); | ||||
|  | ||||
|     var ANIMATION_DURATION = 120; | ||||
|  | ||||
|     $('#nav_arrow').click(function () { | ||||
|         var flag = !$('#set_left').prop('isexpanded'); | ||||
|         setCookie("LeftPanelExpanded", flag ? "1" : "0"); | ||||
|         $('#set_left').stop() | ||||
|             .prop('isexpanded', flag) | ||||
|             .animate({ 'width': flag ? 250 : 50 }, ANIMATION_DURATION) | ||||
|             //.find('li a').css('display', flag ? 'none' : '') | ||||
|             ; | ||||
|         if (flag) | ||||
|             $('#set_left').find(".subitem").show(); | ||||
|         else | ||||
|             $('#set_left').find(".subitem").hide(); | ||||
|  | ||||
|         $('#set_right').stop() | ||||
|             .animate({ 'margin-left': flag ? 250 : 50 }, ANIMATION_DURATION); | ||||
|  | ||||
|         $('#nav_arrow div').attr('class', 'icn') | ||||
|             .addClass(flag ? 'expand' : 'collapse'); | ||||
|     }); | ||||
|  | ||||
|     $('#set_left').prop('isexpanded', false); | ||||
|     var leftexpanded = getCookie("LeftPanelExpanded") === "1"; | ||||
|     if (leftexpanded) | ||||
|         $('#nav_arrow').click(); | ||||
| }) | ||||
							
								
								
									
										178
									
								
								Site/Inspection/js/modules/editor.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										178
									
								
								Site/Inspection/js/modules/editor.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,178 @@ | ||||
| !function (factory) { | ||||
|     if (typeof define === 'function' && define.amd) { | ||||
|         define([], function () { | ||||
|             return factory(window.jQuery); | ||||
|         }); | ||||
|     } | ||||
| }(function ($) { | ||||
|     'use strict'; | ||||
|  | ||||
|     function Editor(element, options) { | ||||
|         this.selectedRange = null; | ||||
|         this.container = $(element); | ||||
|  | ||||
|         var editor = $('<div class="editor-content"></div>'); | ||||
|         this.container.find('.editor-content').remove(); | ||||
|         this.container.append(editor); | ||||
|         this.editor = editor; | ||||
|  | ||||
|         var defaults = { | ||||
|             toolbarSelector: '.editor-toolbar', | ||||
|             commandRole: 'edit', | ||||
|             activeToolbarClass: 'selected', | ||||
|             selectionColor: 'darkgray' | ||||
|         }; | ||||
|         var opts = $.extend(true, {}, defaults, options); | ||||
|         var toolbarBtnSelector = 'a[data-' + opts.commandRole + '],button[data-' + opts.commandRole + '],input[type=button][data-' + opts.commandRole + ']'; | ||||
|         this.bindHotkeys(editor, opts, toolbarBtnSelector); | ||||
|         this.bindToolbar(editor, this.container.find(opts.toolbarSelector), opts, toolbarBtnSelector); | ||||
|  | ||||
|         editor.attr('contenteditable', true).on('mouseup keyup mouseout', function () { | ||||
|             this.saveSelection(); | ||||
|             this.updateToolbar(toolbarBtnSelector, opts); | ||||
|         }.bind(this)); | ||||
|  | ||||
|         $(window).bind('touchend', function (e) { | ||||
|             if (!this.getCurrentRange) { | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             var inside = (editor.is(e.target) || editor.has(e.target).length > 0), | ||||
|                 currentRange = this.getCurrentRange(), | ||||
|                 clear = currentRange && (currentRange.startContainer === currentRange.endContainer && currentRange.startOffset === currentRange.endOffset); | ||||
|  | ||||
|             if (!clear || inside) { | ||||
|                 this.saveSelection(); | ||||
|                 this.updateToolbar(toolbarBtnSelector, opts); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     Editor.prototype.cleanHtml = function () { | ||||
|         var html = this.editor.html(); | ||||
|         return html && html.replace(/(\<br\>|\s|\<div\>\<br\>\<\/div\>| )*$/g, ''); | ||||
|     }; | ||||
|  | ||||
|     Editor.prototype.updateToolbar = function (selector, options) { | ||||
|         if (options.activeToolbarClass) { | ||||
|             this.container.find(options.toolbarSelector).find(selector).each(function () { | ||||
|                 var This = $(this); | ||||
|                 var commandArray = This.data(options.commandRole).split(' '); | ||||
|                 var command = commandArray[0]; | ||||
|                 if (commandArray.length > 1 && document.queryCommandEnabled(command) && document.queryCommandValue(command) === commandArray[1]) { | ||||
|                     This.addClass(options.activeToolbarClass); | ||||
|                 } else if (commandArray.length === [1] && document.queryCommandEnabled(command) && document.queryCommandState(command)) { | ||||
|                     This.addClass(options.activeToolbarClass); | ||||
|                 } else { | ||||
|                     This.removeClass(options.activeToolbarClass); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     Editor.prototype.execCommand = function (commandWithArgs, valueArg, editor, options, selector) { | ||||
|         var commandArray = commandWithArgs.split(' '), | ||||
|             command = commandArray.shift(), | ||||
|             args = commandArray.join(' ') + (valueArg || ''); | ||||
|         var parts = commandWithArgs.split('-'); | ||||
|         if (parts.length === 1) { | ||||
|             document.execCommand(command, false, args); | ||||
|         } else if (parts.length === 2) { | ||||
|             document.execCommand(parts[0], false, parts[1]); | ||||
|         } | ||||
|         editor.trigger('change'); | ||||
|         this.updateToolbar(selector, options); | ||||
|     }; | ||||
|  | ||||
|     Editor.prototype.bindHotkeys = function (editor, options, selector) { | ||||
|         var This = this; | ||||
|         editor.on('keydown', function (e) { | ||||
|             if (e.key === 'Tab') { | ||||
|                 var command = e.shiftKey ? 'outdent' : 'indent'; | ||||
|                 e.preventDefault(); | ||||
|                 e.stopPropagation(); | ||||
|                 This.execCommand(command, null, editor, options, selector); | ||||
|             } | ||||
|         }).on('keyup', function () { | ||||
|             editor.trigger('change'); | ||||
|         }); | ||||
|     }; | ||||
|  | ||||
|     Editor.prototype.getCurrentRange = function () { | ||||
|         var sel, range; | ||||
|         if (window.getSelection) { | ||||
|             sel = window.getSelection(); | ||||
|             if (sel.getRangeAt && sel.rangeCount) { | ||||
|                 range = sel.getRangeAt(0); | ||||
|             } | ||||
|         } else if (document.selection) { | ||||
|             range = document.selection.createRange(); | ||||
|         } | ||||
|         return range; | ||||
|     }; | ||||
|  | ||||
|     Editor.prototype.saveSelection = function () { | ||||
|         this.selectedRange = this.getCurrentRange(); | ||||
|     } | ||||
|  | ||||
|     Editor.prototype.restoreSelection = function () { | ||||
|         var selection; | ||||
|         if (window.getSelection || document.createRange) { | ||||
|             selection = window.getSelection(); | ||||
|             if (this.selectedRange) { | ||||
|                 try { | ||||
|                     selection.removeAllRanges(); | ||||
|                 } catch { | ||||
|                     document.body.createTextRange().select(); | ||||
|                     document.selection.empty(); | ||||
|                 } | ||||
|                 selection.addRange(this.selectedRange); | ||||
|             } | ||||
|         } else if (document.selection && this.selectedRange) { | ||||
|             this.selectedRange.select(); | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     Editor.prototype.markSelection = function (color) { | ||||
|         this.restoreSelection(); | ||||
|         if (document.queryCommandSupported('hiliteColor')) { | ||||
|             document.execCommand('hiliteColor', false, color || 'transparent'); | ||||
|         } | ||||
|         this.saveSelection(); | ||||
|     }; | ||||
|  | ||||
|     Editor.prototype.bindToolbar = function (editor, toolbar, options, selector) { | ||||
|         var This = this; | ||||
|         toolbar.find(selector).on('click', function () { | ||||
|             var command = $(this).data(options.commandRole); | ||||
|             if (command === 'createlink') { | ||||
|                 var link = prompt('Write the URL here', 'https:\/\/'); | ||||
|                 This.restoreSelection(); | ||||
|                 editor.focus(); | ||||
|                 if (link == null || link === '' || link === 'https:\/\/') { | ||||
|                     This.saveSelection(); | ||||
|                     return; | ||||
|                 } | ||||
|                 This.execCommand(command, link, editor, options, selector); | ||||
|             } else { | ||||
|                 This.restoreSelection(); | ||||
|                 editor.focus(); | ||||
|                 This.execCommand(command, null, editor, options, selector); | ||||
|                 This.saveSelection(); | ||||
|             } | ||||
|         }); | ||||
|         toolbar.find('select').on('change', function () { | ||||
|             var command = $(this).data(options.commandRole); | ||||
|             var value = $(this).val(); | ||||
|             if (value == null || value === '') { | ||||
|                 editor.focus(); | ||||
|                 return; | ||||
|             } | ||||
|             This.execCommand(command + '-' + value, null, editor, options, selector); | ||||
|             editor.focus(); | ||||
|             this.selectedIndex = 0; | ||||
|         }); | ||||
|     }; | ||||
|  | ||||
|     return Editor; | ||||
| }); | ||||
							
								
								
									
										187
									
								
								Site/Inspection/js/modules/exportpackages.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								Site/Inspection/js/modules/exportpackages.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,187 @@ | ||||
| define(['modules/packages/createpackage'], function (CreatePackageModule) { | ||||
|     var exppkg = {}; | ||||
|     exppkg.title = GetTextByKey("P_IPT_EXPORTPACKAGES", 'Export Packages'); | ||||
|     exppkg.description = GetTextByKey("P_IPT_EXPORTPACKAGES", 'Export Packages'); | ||||
|     exppkg.version = '1.0'; | ||||
|     exppkg.status = 0; | ||||
|  | ||||
|     var datacontent = null; | ||||
|     var grid_dt; | ||||
|     exppkg.createContent = function (args) { | ||||
|         var _this = this; | ||||
|         if (args && args.length > 0) | ||||
|             exppkg.status = eval(args[0]); | ||||
|  | ||||
|         var content = $('<div style="width:100%;" ></div>'); | ||||
|  | ||||
|         function createHeader() { | ||||
|             var header = $('<div></div>'); | ||||
|             header.append($('<div class="page_title"></div>').text(exppkg.title)); | ||||
|             setPageTitle(exppkg.title, true); | ||||
|  | ||||
|             var func = $('<div class="function_title"></div>'); | ||||
|             var iconCreate = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_CREATE", "Create") + '</span>').click(function () { | ||||
|                 exppkg.oncreate(); | ||||
|             }); | ||||
|             func.append(iconCreate); | ||||
|             var iconRefresh = $('<span class="sbutton iconrefresh">' + GetTextByKey("P_IPT_REFRESH", "Refresh") + '</span>').click(function () { | ||||
|                 exppkg.refresh(); | ||||
|             }); | ||||
|             func.append(iconRefresh); | ||||
|             header.append(func) | ||||
|  | ||||
|             return header; | ||||
|         } | ||||
|  | ||||
|         function InitGridData() { | ||||
|             var div_grid = $('<div style="padding-right:10px;"></div>'); | ||||
|             div_grid.css("height", $(window).height() - 145); | ||||
|  | ||||
|             grid_dt = new GridView(div_grid); | ||||
|             grid_dt.lang = { | ||||
|                 all: GetTextByKey("P_GRID_ALL", "(All)"), | ||||
|                 ok: GetTextByKey("P_GRID_OK", "OK"), | ||||
|                 reset: GetTextByKey("P_GRID_RESET", "Reset") | ||||
|             }; | ||||
|             var list_columns = [ | ||||
|                 { name: 'PackageName', caption: GetTextByKey("P_IPT_PACKAGENAME", "Package Name"), valueIndex: 'PackageName', css: { 'width': 300, 'text-align': 'left' } }, | ||||
|                 { name: 'Notes', caption: GetTextByKey("P_IPT_NOTES", "Notes"), valueIndex: 'Notes', css: { 'width': 300, 'text-align': 'left' } }, | ||||
|                 { name: 'Creator', caption: GetTextByKey("P_IPT_CREATOR", "Creator"), valueIndex: 'Creator', css: { 'width': 250, 'text-align': 'left' } }, | ||||
|                 { name: 'CreatedOnLocal', caption: GetTextByKey("P_IPT_DATETIMECREATED", "Date/Time Created"), valueIndex: 'CreatedOnLocal', css: { 'width': 180, 'text-align': 'left' } }, | ||||
|                 { name: 'DownLoad', caption: "", css: { 'width': 30, 'text-align': 'center' } }, | ||||
|                 { name: 'Delete', caption: "", css: { 'width': 30, 'text-align': 'center' } } | ||||
|             ]; | ||||
|             var columns = []; | ||||
|             // head | ||||
|             for (var hd in list_columns) { | ||||
|                 var col = {}; | ||||
|                 col.name = list_columns[hd].name; | ||||
|                 if (ReportReadonly && col.name === 'Edit') { | ||||
|                     continue; | ||||
|                 } | ||||
|                 col.caption = list_columns[hd].caption; | ||||
|                 col.visible = true; | ||||
|                 col.sortable = true; | ||||
|                 col.width = list_columns[hd].css.width; | ||||
|                 col.align = list_columns[hd].css["text-align"] | ||||
|                 col.key = list_columns[hd].valueIndex; | ||||
|                 col.allowFilter = list_columns[hd].allowFilter; | ||||
|  | ||||
|                 if (col.name === "DownLoad") { | ||||
|                     col.isurl = true; | ||||
|                     col.text = "\uf019"; | ||||
|                     col.sortable = false; | ||||
|                     col.events = { | ||||
|                         onclick: function () { | ||||
|                             _this.onDownLoadPackage(); | ||||
|                         } | ||||
|                     }; | ||||
|                     col.classFilter = function (e) { | ||||
|                         return "icon-col"; | ||||
|                     } | ||||
|                     col.attrs = { 'title': GetTextByKey("P_IPT_DOWNLOADPACKAGE", 'Download Package') }; | ||||
|                 } | ||||
|                 else if (col.name === "Delete") { | ||||
|                     col.isurl = true; | ||||
|                     col.text = "\uf00d"; | ||||
|                     col.sortable = false; | ||||
|                     col.events = { | ||||
|                         onclick: function () { | ||||
|                             _this.onDeletePackage(); | ||||
|                         } | ||||
|                     }; | ||||
|                     col.classFilter = function (e) { | ||||
|                         return "icon-col"; | ||||
|                     } | ||||
|                     col.attrs = { 'title': GetTextByKey("P_IPT_DELETEPACKAGE", 'Delete Package') }; | ||||
|                 } | ||||
|  | ||||
|  | ||||
|                 columns.push(col); | ||||
|             } | ||||
|             grid_dt.canMultiSelect = false; | ||||
|             grid_dt.columns = columns; | ||||
|             grid_dt.init(); | ||||
|             grid_dt.rowdblclick = _this.onDownLoad; | ||||
|  | ||||
|             grid_dt.selectedrowchanged = function (rowindex) { | ||||
|                 var rowdata = grid_dt.source[rowindex]; | ||||
|                 if (rowdata) { | ||||
|                 } | ||||
|             } | ||||
|             return div_grid; | ||||
|         } | ||||
|  | ||||
|         content.append(createHeader()); | ||||
|         content.append(InitGridData()); | ||||
|         datacontent = $('<div></div>'); | ||||
|         content.append(datacontent); | ||||
|  | ||||
|         _this.refresh(); | ||||
|         return content; | ||||
|     } | ||||
|  | ||||
|     exppkg.oncreate = function () { | ||||
|         var _this = this; | ||||
|  | ||||
|         var ei = new CreatePackageModule.CreatePackage(_this); | ||||
|         $('#right_popup').empty().append(ei.createContent()); | ||||
|         showRightPopup(true); | ||||
|     } | ||||
|  | ||||
|     exppkg.onDeletePackage = function () { | ||||
|         var _this = this; | ||||
|         var index = grid_dt.selectedIndex; | ||||
|         var package = grid_dt.source[index].Values; | ||||
|         showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISPACKAGE", 'Are you sure you want to delete this package?'), GetTextByKey("P_IPT_DELETEPACKAGE", 'Delete Package'), function () { | ||||
|             var p = JSON.stringify([teamintelligence, htmlencode(package.PackageId)]); | ||||
|             inspectionrequest("DeletePackage", p, function (data) { | ||||
|                 if (data !== 'OK') { | ||||
|                     showAlert(data, GetTextByKey("P_IPT_DELETEPACKAGE", 'Delete Package')); | ||||
|                     return; | ||||
|                 } | ||||
|                 _this.refresh(); | ||||
|             }, function (err) { | ||||
|                 showAlert(GetTextByKey("P_IPT_FAILEDTODELETEPACKAGE", 'Failed to delete package.'), GetTextByKey("P_IPT_DELETEPACKAGE", 'Delete Package')); | ||||
|             }); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     exppkg.onDownLoadPackage = function () { | ||||
|         var index = grid_dt.selectedIndex; | ||||
|         var package = grid_dt.source[index].Values; | ||||
|         window.open("../filesvc.ashx?sourceType=ipackage&attchid=" + package.PackageId); | ||||
|     } | ||||
|  | ||||
|     function showPackages(data) { | ||||
|         var rows = []; | ||||
|         for (var i = 0; i < data.length; i++) { | ||||
|             var r = data[i]; | ||||
|             for (var j in r) { | ||||
|                 if (j === "CreatedOnLocal") { | ||||
|                     r[j] = { DisplayValue: r["CreatedOnLocalStr"], Value: r[j] }; | ||||
|                 } | ||||
|             } | ||||
|             var fr = { Values: r }; | ||||
|             rows.push(fr); | ||||
|         } | ||||
|  | ||||
|         grid_dt.setData(rows); | ||||
|     } | ||||
|  | ||||
|     exppkg.refresh = function () { | ||||
|         datacontent.empty(); | ||||
|         inspectionrequest("GetCreatedPackages", '', function (data) { | ||||
|             if (typeof (data) === "string") { | ||||
|                 showAlert(data, GetTextByKey("P_IPT_EXPORTPACKAGES", 'Export Packages')); | ||||
|                 return; | ||||
|             } | ||||
|             datacontent.empty(); | ||||
|             if (data) { | ||||
|                 showPackages(data); | ||||
|             } | ||||
|         }, function (err) { | ||||
|         }); | ||||
|     } | ||||
|     return exppkg; | ||||
| }); | ||||
							
								
								
									
										284
									
								
								Site/Inspection/js/modules/fuellog.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										284
									
								
								Site/Inspection/js/modules/fuellog.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,284 @@ | ||||
| define([], function () { | ||||
|     var gs = {}; | ||||
|     gs.title = GetTextByKey("P_IPT_FUELLOG", 'Fuel Log'); | ||||
|     gs.description = GetTextByKey("P_IPT_FUELLOG", 'Fuel Log'); | ||||
|     gs.version = '1.0'; | ||||
|     gs.status = 0; | ||||
|  | ||||
|     var datacontent = null; | ||||
|     var startdateinputcontrol = undefined; | ||||
|     var enddateinputcontrol = undefined; | ||||
|     gs.createContent = function () { | ||||
|         var _this = this; | ||||
|         var content = $('<div style="width:100%;" ></div>'); | ||||
|  | ||||
|         function createHeader() { | ||||
|             var header = $('<div></div>'); | ||||
|             header.append($('<div class="page_title"></div>').text(gs.title)); | ||||
|             setPageTitle(gs.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" />'); | ||||
|             search_bar.append('<span style="margin-left:5px;">' + GetTextByKey("P_IPT_BEGINDATE_COLON", "Begin Date:") + '</span>'); | ||||
|             startdateinputcontrol = $('<input type="text" style="margin-left: 5px; width: 80px;" autocomplete="off" />').val(begindate); | ||||
|             search_bar.append($('<span></span>').append(startdateinputcontrol)); | ||||
|             startdateinputcontrol.datetimepicker({ | ||||
|                 timepicker: false, | ||||
|                 format: 'm/d/Y' | ||||
|             }); | ||||
|             search_bar.append('<span style="margin-left:10px;">' + GetTextByKey("P_IPT_ENDDATE_COLON", "End Date:") + '</span>'); | ||||
|             enddateinputcontrol = $('<input type="text" style="margin-left: 5px; width: 80px;" autocomplete="off" />').val(enddate); | ||||
|             search_bar.append($('<span></span>').append(enddateinputcontrol)); | ||||
|             enddateinputcontrol.datetimepicker({ | ||||
|                 timepicker: false, | ||||
|                 format: 'm/d/Y' | ||||
|             }); | ||||
|  | ||||
|             var btnRefresh = $('<input class="search" type="button" value="' + GetTextByKey("P_IPT_SEARCH", "Search") + '" style="margin-left:10px;"/>'); | ||||
|             search_bar.append(btnRefresh); | ||||
|             btnRefresh.click(function () { | ||||
|                 gs.refresh(); | ||||
|             }); | ||||
|  | ||||
|             var func = $('<div class="function_title"></div>'); | ||||
|             var iconRefresh = $('<span class="sbutton iconrefresh">' + GetTextByKey("P_IPT_REFRESH", "Refresh") + '</span>').click(function () { | ||||
|                 gs.refresh(); | ||||
|             }); | ||||
|             func.append(iconRefresh); | ||||
|             var iconSettings = $('<span class="sbutton iconcog" style="float: right; line-height: 20px">' + GetTextByKey("P_MAIN_SETTINGS", "Settings") + '</span>').click(function () { | ||||
|                 gs.createSettings(); | ||||
|             }); | ||||
|             func.append(iconSettings); | ||||
|             header.append(func) | ||||
|  | ||||
|             return header; | ||||
|         } | ||||
|  | ||||
|         content.append(createHeader()); | ||||
|  | ||||
|         var dataheader = $('<div class="question-holder no-hover" style="font-weight: bold;font-size:14px;"></div>'); | ||||
|         dataheader.append('<div style="width:60px; flex-shrink: 0"></div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 150px">' + GetTextByKey("P_IPT_DATE", "Date") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 200px">' + GetTextByKey("P_IPT_ASSETNAME", "Asset Name") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 200px">' + GetTextByKey("P_IPT_VIN", "VIN") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 200px;">' + GetTextByKey("P_IPT_EMPLOYEENAME", "Employee Name") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 150px;">' + GetTextByKey("P_IPT_CHECKEDIN", "Checked In") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 150px;">' + GetTextByKey("P_IPT_CHECKEDOUT", "Checked Out") + '</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; | ||||
|     } | ||||
|  | ||||
|     gs.refresh = function () { | ||||
|         var _this = this; | ||||
|         datacontent.empty(); | ||||
|         var startydate = startdateinputcontrol.val(); | ||||
|         var enddate = enddateinputcontrol.val(); | ||||
|         var p = JSON.stringify([teamintelligence, startydate, enddate]); | ||||
|         inspectionrequest("GetFuelReportItems", htmlencode(p), function (data) { | ||||
|             datacontent.empty(); | ||||
|             if (typeof (data) === "string") { | ||||
|                 showAlert(data, GetTextByKey("P_IPT_ERROR", 'Error')); | ||||
|                 return; | ||||
|             } | ||||
|             if (data) { | ||||
|                 for (var i = 0; i < data.length; i++) { | ||||
|                     _this.createFuelLog(data[i]); | ||||
|                 } | ||||
|                 //showFuelLogs(data); | ||||
|             } | ||||
|         }, function (err) { | ||||
|         }); | ||||
|     } | ||||
|     gs.createFuelLog = function (fuellog) { | ||||
|         var _this = this; | ||||
|         var content = $('<div></div>'); | ||||
|         var holder = $('<div class="section-holder"></div>'); | ||||
|         content.append(holder); | ||||
|  | ||||
|         var btnfuleitem = $('<div class="section-icon" style="width: 30px;"><em class="spanbtn iconangleright" style="font-size:18px;"></em></div>'); | ||||
|         btnfuleitem.click(function () { | ||||
|             var icon = btnfuleitem.find('.spanbtn'); | ||||
|             if (icon.hasClass('iconangleright')) { | ||||
|                 icon.removeClass('iconangleright').addClass('iconangledown'); | ||||
|                 if (fuellog.FuelReportItems) | ||||
|                     _this.createFuelItem(content, fuellog.FuelReportItems); | ||||
|             } | ||||
|             else { | ||||
|                 icon.removeClass('iconangledown').addClass('iconangleright'); | ||||
|                 btnfuleitem.parents().parents().children('.questionitem').remove(); | ||||
|             } | ||||
|         }); | ||||
|         holder.append(btnfuleitem); | ||||
|  | ||||
|         var spantime = $('<lable></lable>').text(GetTextByKey("P_IPT_DATE", "Date:") + fuellog.LocalCalendarDateStr); | ||||
|         var spancount = $('<lable></lable>').text("(" + fuellog.FuelReportCount + ")"); | ||||
|         holder.append($('<div class="section-cell section-name" style="width:200px;flex-grow:0;font-size:12px;"></div>').append(spantime).append(spancount)); | ||||
|         datacontent.append(content); | ||||
|     } | ||||
|  | ||||
|     gs.createFuelItem = function (content, fuelitem) { | ||||
|         var _this = this; | ||||
|         for (var i = 0; i < fuelitem.length; i++) { | ||||
|             var fuel = fuelitem[i]; | ||||
|             var holder = $('<div class="questionitem"></div>'); | ||||
|             var qholder = $('<div class="question-holder"></div>');//question holder | ||||
|             holder.append(qholder); | ||||
|  | ||||
|             if (_this.index % 2 == 1) | ||||
|                 qholder.addClass('holder-even'); | ||||
|  | ||||
|             qholder.append('<div class="question-icon" style="width:30px;"><em class="fa"></em></div>'); | ||||
|  | ||||
|             var span = $('<span></span>').text(fuel.LocalCalendarDateStr); | ||||
|             qholder.append($('<div class="question-cell question-name" style="width: 150px;padding-left:10px;"></div>').append(span)); | ||||
|  | ||||
|             span = $('<span></span>').text(fuel.AssetName); | ||||
|             qholder.append($('<div class="question-cell" style="width: 200px;padding-left:10px;"></div>').append(span)); | ||||
|  | ||||
|             span = $('<span></span>').text(fuel.VIN); | ||||
|             qholder.append($('<div class="question-cell" style="width: 200px;padding-left:10px;"></div>').append(span)); | ||||
|  | ||||
|             span = $('<span></span>').text(fuel.EmployeeName); | ||||
|             qholder.append($('<div class="question-cell" style="width: 200px;padding-left:10px;"></div>').append(span)); | ||||
|  | ||||
|             span = $('<span></span>').text(fuel.CheckInTimeLocalStr); | ||||
|             qholder.append($('<div class="question-cell" style="width: 150px;padding-left:10px;"></div>').append(span)); | ||||
|  | ||||
|             span = $('<span></span>').text(fuel.CheckOutTimeLocalStr); | ||||
|             qholder.append($('<div class="question-cell" style="width: 150px;padding-left:10px;"></div>').append(span)); | ||||
|  | ||||
|             holder.dblclick(fuel, function (e) { | ||||
|                 window.open("fuelreport.aspx?rid=" + e.data.Id + "&team=" + (teamintelligence ? 1 : 0), "_blank"); | ||||
|             }); | ||||
|  | ||||
|             holder.find('.question-name span').click(fuel, function (e) { | ||||
|                 window.open("fuelreport.aspx?rid=" + e.data.Id + "&team=" + (teamintelligence ? 1 : 0), "_blank"); | ||||
|             }); | ||||
|  | ||||
|             content.append(holder); | ||||
|         } | ||||
|     } | ||||
|     gs.createSettings = function () { | ||||
|         var loading = $('<div class="loading_holder" style="top: 0; background-color: rgba(0,0,0,0.2); display: none"></div>'); | ||||
|         loading.append('<div class="loading_icon icn icn-spin"></div>'); | ||||
|  | ||||
|         function onSave(exit) { | ||||
|             var alerttitle = GetTextByKey("P_IPT_FUELRPT_SETTING", 'Fuel Report Page Settings'); | ||||
|             loading.fadeIn(100); | ||||
|             var headerLeft = $('#fuelrpt_headers_left').val(); | ||||
|             var headerMiddle = $('#fuelrpt_headers_middle').val(); | ||||
|             var headerRight = $('#fuelrpt_headers_right').val(); | ||||
|             var footerLeft = $('#fuelrpt_footers_left').val(); | ||||
|             var footerMiddle = $('#fuelrpt_footers_middle').val(); | ||||
|             var footerRight = $('#fuelrpt_footers_right').val(); | ||||
|             var item = { | ||||
|                 '$type': 'Foresight.Fleet.Services.Inspection.FuelReportHeaderFooterItem, FleetServiceClient', | ||||
|                 HeaderLeft: headerLeft, | ||||
|                 HeaderMiddle: headerMiddle, | ||||
|                 HeaderRight: headerRight, | ||||
|                 FooterLeft: footerLeft, | ||||
|                 FooterMiddle: footerMiddle, | ||||
|                 FooterRight: footerRight | ||||
|             }; | ||||
|             var p = [false, htmlencode(JSON.stringify(item))]; | ||||
|             inspectionrequest('UpdateFuelReportHeaderFooter', JSON.stringify(p), function (r) { | ||||
|                 if (r == 'OK') { | ||||
|                     showAlert(GetTextByKey("P_MV_SAVSUCCESSFULLY", 'Saved successfully.'), alerttitle, null, function () { | ||||
|                         loading.fadeOut(100); | ||||
|                         if (exit) { | ||||
|                             showRightPopup(false); | ||||
|                         } | ||||
|                     }); | ||||
|                 } else { | ||||
|                     showAlert(GetTextByKey("P_IPT_FUELRPT_SAVEERROR", 'Failed to save fuel report page settings.'), alerttitle, null, function () { | ||||
|                         loading.fadeOut(100); | ||||
|                     }); | ||||
|                 } | ||||
|             }, 1000); | ||||
|         } | ||||
|  | ||||
|         var content = $('<div></div>'); | ||||
|         var funcs = $('<div class="function_title"></div>'); | ||||
|         var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE", "Save") + '</span>').click(function () { | ||||
|             onSave(); | ||||
|         }); | ||||
|         funcs.append(btn); | ||||
|         btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE1", "Save and Exit") + '</span>').click(function () { | ||||
|             onSave(true); | ||||
|         }); | ||||
|         funcs.append(btn); | ||||
|         btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_SAVE2", "Exit Without Saving") + '</span>').click(function () { | ||||
|             showRightPopup(false); | ||||
|         }); | ||||
|         funcs.append(btn); | ||||
|         content.append(funcs); | ||||
|  | ||||
|         content.append($('<div class="page_title"></div>').text(GetTextByKey('P_IPT_FUELRPT_HEADER', 'Page Headers'))); | ||||
|         var line = $('<div class="settings-line"></div>'); | ||||
|         var label = $('<span></span>').text(GetTextByKey('P_IPT_FUELRPT_LEFT', 'Left')); | ||||
|         line.append(label); | ||||
|         var field = $('<textarea id="fuelrpt_headers_left"></textarea>'); | ||||
|         line.append(field); | ||||
|         content.append(line); | ||||
|  | ||||
|         line = $('<div class="settings-line"></div>'); | ||||
|         label = $('<span></span>').text(GetTextByKey('P_IPT_FUELRPT_MIDDLE', 'Middle')); | ||||
|         line.append(label); | ||||
|         field = $('<textarea id="fuelrpt_headers_middle"></textarea>'); | ||||
|         line.append(field); | ||||
|         content.append(line); | ||||
|  | ||||
|         line = $('<div class="settings-line"></div>'); | ||||
|         label = $('<span></span>').text(GetTextByKey('P_IPT_FUELRPT_RIGHT', 'Right')); | ||||
|         line.append(label); | ||||
|         field = $('<textarea id="fuelrpt_headers_right"></textarea>'); | ||||
|         line.append(field); | ||||
|         content.append(line); | ||||
|         content.append($('<div class="page_title"></div>').text(GetTextByKey('P_IPT_FUELRPT_FOOTER', 'Page Footers'))); | ||||
|  | ||||
|         line = $('<div class="settings-line"></div>'); | ||||
|         label = $('<span></span>').text(GetTextByKey('P_IPT_FUELRPT_LEFT', 'Left')); | ||||
|         line.append(label); | ||||
|         field = $('<textarea id="fuelrpt_footers_left"></textarea>'); | ||||
|         line.append(field); | ||||
|         content.append(line); | ||||
|  | ||||
|         line = $('<div class="settings-line"></div>'); | ||||
|         label = $('<span></span>').text(GetTextByKey('P_IPT_FUELRPT_MIDDLE', 'Middle')); | ||||
|         line.append(label); | ||||
|         field = $('<textarea id="fuelrpt_footers_middle"></textarea>'); | ||||
|         line.append(field); | ||||
|         content.append(line); | ||||
|  | ||||
|         line = $('<div class="settings-line"></div>'); | ||||
|         label = $('<span></span>').text(GetTextByKey('P_IPT_FUELRPT_RIGHT', 'Right')); | ||||
|         line.append(label); | ||||
|         field = $('<textarea id="fuelrpt_footers_right"></textarea>'); | ||||
|         line.append(field); | ||||
|         content.append(line); | ||||
|  | ||||
|         content.append(loading); | ||||
|         $('#right_popup').empty().append(content); | ||||
|         showRightPopup(true); | ||||
|  | ||||
|         loading.fadeIn(100); | ||||
|         inspectionrequest('GetFuelReportHeaderFooter', 'false', function (r) { | ||||
|             //console.log(r); | ||||
|             gs.fuelRptSettings = r; | ||||
|             content.find('#fuelrpt_headers_left').val(r.HeaderLeft); | ||||
|             content.find('#fuelrpt_headers_middle').val(r.HeaderMiddle); | ||||
|             content.find('#fuelrpt_headers_right').val(r.HeaderRight); | ||||
|             content.find('#fuelrpt_footers_left').val(r.FooterLeft); | ||||
|             content.find('#fuelrpt_footers_middle').val(r.FooterMiddle); | ||||
|             content.find('#fuelrpt_footers_right').val(r.FooterRight); | ||||
|             loading.fadeOut(100); | ||||
|         }); | ||||
|     }; | ||||
|     return gs; | ||||
| }); | ||||
							
								
								
									
										105
									
								
								Site/Inspection/js/modules/globalsections.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								Site/Inspection/js/modules/globalsections.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | ||||
| define(['modules/sections/section', 'modules/sections/addsection'], function (Section, AddSection) { | ||||
|     var gs = {}; | ||||
|     gs.title = GetTextByKey("P_GLOBALSECTIONS", 'Global Sections'); | ||||
|     gs.description = GetTextByKey("P_GLOBALSECTIONS", 'Global Sections'); | ||||
|     gs.version = '1.0'; | ||||
|  | ||||
|     var datacontent = null; | ||||
|     gs.createContent = function (sections) { | ||||
|         templatereadonly = false; | ||||
|         editable = true; | ||||
|         sectiontype = 0;//sectiontype:0 - global,1 - normal | ||||
|         templatestatus = 0;//templatestatus:0 - draft,1 - published | ||||
|  | ||||
|         var content = $('<div style="min-width:1940px;"></div>'); | ||||
|  | ||||
|         function createHeader() { | ||||
|             var header = $('<div></div>'); | ||||
|             header.append($('<div class="page_title"></div>').text(gs.title)); | ||||
|             setPageTitle(gs.title, true); | ||||
|             //var search_bar = $('<div class="search_bar"></div>'); | ||||
|             //header.append(search_bar); | ||||
|             //header.append('<input type="text" id="searchinputtxt" autocomplete="off" />'); | ||||
|             //var btnRefresh = $('<input class="search" type="button" value="Search" />'); | ||||
|             //header.append(btnRefresh); | ||||
|             //btnRefresh.click(function () { | ||||
|             //    gs.refresh(); | ||||
|             //}); | ||||
|  | ||||
|             var func = $('<div class="function_title"></div>'); | ||||
|             var iconAdd = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADD", "Add") + '</span>').click(function () { | ||||
|                 gs.addSection(); | ||||
|             }); | ||||
|             func.append(iconAdd); | ||||
|             var iconRefresh = $('<span class="sbutton iconrefresh">' + GetTextByKey("P_IPT_REFRESH", "Refresh") + '</span>').click(function () { | ||||
|                 gs.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;"></div>'); | ||||
|         dataheader.append('<div style="width:60px; flex-shrink: 0"></div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 200px">' + GetTextByKey("P_IPT_NAME", "Name") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 310px">' + GetTextByKey("P_IPT_DISPLAYTEXT", "Display Text") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 420px">' + GetTextByKey("P_IPT_TYPE", "Type") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 80px; text-align: center">' + GetTextByKey("P_IPT_REQUIRED", "Required") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 100px; text-align: center">' + GetTextByKey("P_IPT_CANCOMMENT", "Can Comment") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 100px; text-align: center">' + GetTextByKey("P_IPT_ISIMPORTANT", "Is Important") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 140px">' + GetTextByKey("P_IPT_CUSTOMERVISIBLE", "Customer Visible") + '</div>'); | ||||
|         dataheader.append('<div class="question-cell" style="width: 140px">' + GetTextByKey("P_IPT_SEVERITYLEVEL", "Severity Level") + '</div>'); | ||||
|         dataheader.append('<div style="flex-grow: 1" style="width: 160px">' + GetTextByKey("P_IPT_NOTES", "Notes") + '</div>'); | ||||
|         if (sectiontype === 0) | ||||
|             dataheader.append('<div class="question-cell" style="width: 120px;">' + 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); | ||||
|  | ||||
|         //setTimeout(function () { | ||||
|         //    gs.resize(); | ||||
|         //}); | ||||
|         //$(window).resize(function () { | ||||
|         //    gs.resize(); | ||||
|         //}); | ||||
|         if (sections) { | ||||
|             for (var i = 0; i < sections.length; i++) { | ||||
|                 var s = new Section(sections[i], gs); | ||||
|                 datacontent.append(s.createContent()); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|             this.refresh(); | ||||
|         return content; | ||||
|     } | ||||
|  | ||||
|     gs.resize = function () { | ||||
|         datacontent.css("height", document.documentElement.clientHeight - datacontent.offset().top) | ||||
|     } | ||||
|  | ||||
|     gs.addSection = function () { | ||||
|         var s = new AddSection(gs); | ||||
|         $('#right_popup').empty().append(s.createContent()); | ||||
|         showRightPopup(true); | ||||
|     } | ||||
|  | ||||
|     gs.refresh = function () { | ||||
|         datacontent.empty(); | ||||
|         inspectionrequest("GetGlobalSections", teamintelligence, function (data) { | ||||
|             datacontent.empty(); | ||||
|             if (data) { | ||||
|                 for (var i = 0; i < data.length; i++) { | ||||
|                     var s = new Section(data[i], gs); | ||||
|                     datacontent.append(s.createContent()); | ||||
|                 } | ||||
|             } | ||||
|         }, function (err) { | ||||
|         }); | ||||
|     } | ||||
|     return gs; | ||||
| }); | ||||
							
								
								
									
										376
									
								
								Site/Inspection/js/modules/importpackages.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										376
									
								
								Site/Inspection/js/modules/importpackages.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,376 @@ | ||||
| define([], function () { | ||||
|     var imppkg = {}; | ||||
|  | ||||
|     var txtfilename; | ||||
|     var txtpwd; | ||||
|     var btnbrowse; | ||||
|     var btnunpackpkg; | ||||
|     var txtname; | ||||
|     var txtnotes; | ||||
|     var grid_templatedt; | ||||
|     var grid_sectiondt; | ||||
|     var divpkg; | ||||
|  | ||||
|     var tempgridholder; | ||||
|     var sectiongridholder; | ||||
|  | ||||
|     var filedata; | ||||
|  | ||||
|     function InitTemplateGridData() { | ||||
|         var div_grid = $('<div style="margin-top:5px;"></div>'); | ||||
|         div_grid.css("height", 200); | ||||
|  | ||||
|         grid_templatedt = new GridView(div_grid); | ||||
|         grid_templatedt.lang = { | ||||
|             all: GetTextByKey("P_GRID_ALL", "(All)"), | ||||
|             ok: GetTextByKey("P_GRID_OK", "OK"), | ||||
|             reset: GetTextByKey("P_GRID_RESET", "Reset") | ||||
|         }; | ||||
|         var list_columns = [ | ||||
|             { name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 30, 'text-align': 'center' } }, | ||||
|             { name: 'TemplateName', caption: GetTextByKey("P_TEMPLATE", "Template"), valueIndex: 'Name', css: { 'width': 320, 'text-align': 'left' } }, | ||||
|             { name: 'AssetName', caption: GetTextByKey("P_IPT_NOTES", "Notes"), valueIndex: 'Notes', css: { 'width': 400, 'text-align': 'left' } } | ||||
|         ]; | ||||
|         var columns = []; | ||||
|         // head | ||||
|         for (var hd in list_columns) { | ||||
|             var col = {}; | ||||
|             col.name = list_columns[hd].name; | ||||
|             col.caption = list_columns[hd].caption; | ||||
|             col.visible = true; | ||||
|             col.sortable = true; | ||||
|             col.width = list_columns[hd].css.width; | ||||
|             col.align = list_columns[hd].css["text-align"] | ||||
|             col.key = list_columns[hd].valueIndex; | ||||
|             col.allowFilter = list_columns[hd].allowFilter; | ||||
|             if (list_columns[hd].type) { | ||||
|                 col.type = list_columns[hd].type; | ||||
|             } | ||||
|             if (col.name === 'Selected') { | ||||
|                 col.allcheck = true; | ||||
|                 col.sortable = false; | ||||
|             } | ||||
|  | ||||
|             columns.push(col); | ||||
|         } | ||||
|         grid_templatedt.canMultiSelect = false; | ||||
|         grid_templatedt.columns = columns; | ||||
|         grid_templatedt.init(); | ||||
|  | ||||
|         return div_grid; | ||||
|     } | ||||
|  | ||||
|     function showTemplates(data) { | ||||
|         var rows = []; | ||||
|         for (var i = 0; i < data.length; i++) { | ||||
|             var r = data[i]; | ||||
|             r.Selected = true; | ||||
|             var fr = { Values: r }; | ||||
|             rows.push(fr); | ||||
|         } | ||||
|  | ||||
|         grid_templatedt.setData(rows); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     function InitSectionGridData() { | ||||
|         var div_grid = $('<div style="margin-top:5px;"></div>'); | ||||
|         div_grid.css("height", 200); | ||||
|  | ||||
|         grid_sectiondt = new GridView(div_grid); | ||||
|         grid_sectiondt.lang = { | ||||
|             all: GetTextByKey("P_GRID_ALL", "(All)"), | ||||
|             ok: GetTextByKey("P_GRID_OK", "OK"), | ||||
|             reset: GetTextByKey("P_GRID_RESET", "Reset") | ||||
|         }; | ||||
|         var list_columns = [ | ||||
|             { name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 30, 'text-align': 'center' } }, | ||||
|             { name: 'SectionName', caption: GetTextByKey("P_IPT_SECTION", "Section"), valueIndex: 'ItemName', css: { 'width': 320, 'text-align': 'left' } }, | ||||
|             { name: 'AssetName', caption: GetTextByKey("P_IPT_NOTES", "Notes"), valueIndex: 'Notes', css: { 'width': 400, 'text-align': 'left' } } | ||||
|         ]; | ||||
|         var columns = []; | ||||
|         // head | ||||
|         for (var hd in list_columns) { | ||||
|             var col = {}; | ||||
|             col.name = list_columns[hd].name; | ||||
|             col.caption = list_columns[hd].caption; | ||||
|             col.visible = true; | ||||
|             col.sortable = true; | ||||
|             col.width = list_columns[hd].css.width; | ||||
|             col.align = list_columns[hd].css["text-align"] | ||||
|             col.key = list_columns[hd].valueIndex; | ||||
|             col.allowFilter = list_columns[hd].allowFilter; | ||||
|             if (list_columns[hd].type) { | ||||
|                 col.type = list_columns[hd].type; | ||||
|             } | ||||
|             if (col.name === 'Selected') { | ||||
|                 col.allcheck = true; | ||||
|                 col.sortable = false; | ||||
|             } | ||||
|  | ||||
|             columns.push(col); | ||||
|         } | ||||
|         grid_sectiondt.canMultiSelect = false; | ||||
|         grid_sectiondt.columns = columns; | ||||
|         grid_sectiondt.init(); | ||||
|  | ||||
|         return div_grid; | ||||
|     } | ||||
|  | ||||
|     function showGlobalSections(data) { | ||||
|         var rows = []; | ||||
|         for (var i = 0; i < data.length; i++) { | ||||
|             var r = data[i]; | ||||
|             r.Selected = true; | ||||
|             var fr = { Values: r }; | ||||
|             rows.push(fr); | ||||
|         } | ||||
|  | ||||
|         grid_sectiondt.setData(rows); | ||||
|     } | ||||
|  | ||||
|     function onImport(_this, overwritten) { | ||||
|         var alerttitle = GetTextByKey("P_IPT_IMPORTPACKAGE", 'Import Package'); | ||||
|         if (!filedata) { | ||||
|             showAlert(GetTextByKey("P_IPT_PLEASESELECTTHEPACKAGEFILE", 'Please select the package file.'), alerttitle); | ||||
|             return; | ||||
|         } | ||||
|         if (txtname.text() == "") { | ||||
|             showAlert(GetTextByKey("P_IPT_PLEASEUNPACKTHEPACKAGE", 'Please unpack the package.'), alerttitle); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         var templateids = []; | ||||
|         for (var i = 0; i < grid_templatedt.source.length; i++) { | ||||
|             var t = grid_templatedt.source[i].Values; | ||||
|             if (t.Selected) | ||||
|                 templateids.push(t.Id); | ||||
|         } | ||||
|  | ||||
|         var sectionids = []; | ||||
|         for (var i = 0; i < grid_sectiondt.source.length; i++) { | ||||
|             var t = grid_sectiondt.source[i].Values; | ||||
|             if (t.Selected) | ||||
|                 sectionids.push(t.ItemId); | ||||
|         } | ||||
|         if (templateids.length < 1 && sectionids.length < 1) { | ||||
|             showAlert(GetTextByKey("P_IPT_PLEASESELECTATLEASTONETEMPLATEORGLOBALSECTIONTOIMPORT", 'Please select at least one template or global section to import.'), alerttitle); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         _this.loading && _this.loading.fadeIn(100); | ||||
|  | ||||
|         var p = [overwritten, JSON.stringify(templateids), JSON.stringify(sectionids)]; | ||||
|         p = JSON.stringify(p); | ||||
|         var formData = new FormData(); | ||||
|         formData.append("pkgfile", filedata); | ||||
|         formData.append("MethodName", "ImportPackage"); | ||||
|         formData.append("ClientData", htmldecode(p)); | ||||
|         $.ajax({ | ||||
|             url: 'Inspection.aspx?tp=ashx', | ||||
|             type: 'POST', | ||||
|             dataType: 'json', | ||||
|             processData: false, | ||||
|             contentType: false, | ||||
|             data: formData, | ||||
|             async: true, | ||||
|             success: function (data) { | ||||
|                 if (data === "OK") { | ||||
|                     showAlert(GetTextByKey("P_IPT_PACKAGEHASBEENIMPORTEDSUCCESSFULLY", 'Package has been imported successfully.'), alerttitle); | ||||
|                     filedata = null; | ||||
|                     divpkg.hide(); | ||||
|                     txtfilename.val(""); | ||||
|                     txtpwd.val(""); | ||||
|                     txtname.text(""); | ||||
|                     txtnotes.html(""); | ||||
|                 } else { | ||||
|                     showAlert(data, alerttitle); | ||||
|                 } | ||||
|                 _this.loading && _this.loading.fadeOut(100); | ||||
|             }, | ||||
|             error: function (err) { | ||||
|                 showAlert(err.statusText, alerttitle); | ||||
|                 _this.loading && _this.loading.fadeOut(100); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     function getPackageData(_this) { | ||||
|         var alerttitle = GetTextByKey("P_IPT_IMPORTPACKAGE", 'Import Package'); | ||||
|         var pwd = txtpwd.val(); | ||||
|         if (!pwd || pwd == "") { | ||||
|             showAlert(GetTextByKey("P_IPT_PASSWORDISREQUIRED", 'Password is required.'), alerttitle); | ||||
|             return; | ||||
|         } | ||||
|         _this.loading && _this.loading.fadeIn(100); | ||||
|  | ||||
|         var formData = new FormData(); | ||||
|         formData.append("pkgfile", filedata); | ||||
|         formData.append("MethodName", "GetPackageData"); | ||||
|         formData.append("ClientData", htmldecode(pwd)); | ||||
|         $.ajax({ | ||||
|             url: 'Inspection.aspx?tp=ashx', | ||||
|             type: 'POST', | ||||
|             dataType: 'json', | ||||
|             processData: false, | ||||
|             contentType: false, | ||||
|             data: formData, | ||||
|             async: true, | ||||
|             success: function (data) { | ||||
|                 if (typeof (data) === "string") { | ||||
|                     showAlert(data, alerttitle); | ||||
|                 } else { | ||||
|                     showPackageData(data); | ||||
|                 } | ||||
|                 _this.loading && _this.loading.fadeOut(100); | ||||
|             }, | ||||
|             error: function (err) { | ||||
|                 showAlert(err.statusText, alerttitle); | ||||
|                 _this.loading && _this.loading.fadeOut(100); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     function showPackageData(pkgdata) { | ||||
|         divpkg.show(); | ||||
|         reshowgrid(); | ||||
|         txtname.text(pkgdata.PackageName); | ||||
|         txtnotes.html(replaceHtmlText(pkgdata.Notes)); | ||||
|         showTemplates(pkgdata.Templates); | ||||
|         showGlobalSections(pkgdata.GlobalSections); | ||||
|     } | ||||
|  | ||||
|     imppkg.createContent = function () { | ||||
|         var _this = this; | ||||
|         setPageTitle(GetTextByKey("P_IPT_IMPORTPACKAGE", 'Import Package'), true); | ||||
|         var content = $('<div style="padding-left:10px;padding-right:10px;"></div>'); | ||||
|         this.content = content; | ||||
|         var funcs = $('<div class="function_title"></div>'); | ||||
|         var btn = $('<span class="sbutton iconsave">' + GetTextByKey('P_IPT_IMPORT', 'Import') + '</span>').click(function () { | ||||
|             showConfirm(GetTextByKey("P_IPT_DOYOUWANTTOOVERWRITETHEITEMSWHICHHAVEANEWERVERSION", 'Do you want to overwrite the items which have a higher version?'), GetTextByKey("P_IPT_IMPORTPACKAGE", 'Import Package'), function () { | ||||
|                 onImport(_this, 1); | ||||
|             }, function () { | ||||
|                 onImport(_this, 0); | ||||
|             }); | ||||
|         }); | ||||
|         funcs.append(btn); | ||||
|         content.append(funcs); | ||||
|  | ||||
|         var tb = $('<table style="line-height:24px;"></table>'); | ||||
|         content.append(tb); | ||||
|  | ||||
|         var tr = $('<tr></tr>'); | ||||
|         tb.append(tr); | ||||
|         var td = $('<td class="label" style="width:160px;">' + GetTextByKey('P_IPT_IMPORTPACKAGEFILE_COLON', 'Import Package File:') + '</td>'); | ||||
|         tr.append(td); | ||||
|         td = $('<td></td>'); | ||||
|         tr.append(td); | ||||
|         txtfilename = $('<input type="text" maxlength=100 style="width: 500px; height: 21px;margin-top:5px;margin-bottom:5px;" disabled="disabled"></input>'); | ||||
|         td.append(txtfilename); | ||||
|         btnbrowse = $('<input type="button" value="' + GetTextByKey('P_IPT_BROWSE', 'Browse...') + '" style="margin-left:10px;width:80px;"></input>'); | ||||
|         td.append(btnbrowse); | ||||
|         btnbrowse.click(function UpLoadMachineIcon(type, e) { | ||||
|             var file = $('<input type="file" style="display: none;" />') | ||||
|             file.change(function () { | ||||
|                 filedata = this.files[0]; | ||||
|                 txtname.text(""); | ||||
|                 txtnotes.html("") | ||||
|                 if (filedata) { | ||||
|                     txtfilename.val(filedata.name); | ||||
|                     btnunpackpkg.prop("disabled", false); | ||||
|                 } | ||||
|             }).click(); | ||||
|         }); | ||||
|  | ||||
|         var tr = $('<tr></tr>'); | ||||
|         tb.append(tr); | ||||
|         td = $('<td class="label" style="width:160px;">Password:</td>'); | ||||
|         tr.append(td); | ||||
|         td = $('<td></td>'); | ||||
|         tr.append(td); | ||||
|         txtpwd = $('<input type="password" maxlength=16 style="width: 500px; height: 21px;margin-top:5px;margin-bottom:5px;"></input>'); | ||||
|         td.append(txtpwd); | ||||
|         btnunpackpkg = $('<input type="button" value="' + GetTextByKey('P_IPT_UNPACK', 'Unpack') + '" style="margin-left:10px;width:80px;" disabled="disabled"></input>'); | ||||
|         td.append(btnunpackpkg); | ||||
|         btnunpackpkg.click(function () { | ||||
|             getPackageData(_this); | ||||
|         }); | ||||
|  | ||||
|         divpkg = $('<div style="display:none;"></div>'); | ||||
|         content.append(divpkg); | ||||
|  | ||||
|         var tb = $('<table style="line-height:24px;"></table>'); | ||||
|         divpkg.append(tb); | ||||
|  | ||||
|         var tr = $('<tr></tr>'); | ||||
|         tb.append(tr); | ||||
|         var td = $('<td class="label" style="width:160px;">Name:</td>'); | ||||
|         tr.append(td); | ||||
|         td = $('<td></td>'); | ||||
|         tr.append(td); | ||||
|         txtname = $('<span></span>'); | ||||
|         td.append(txtname); | ||||
|  | ||||
|         var tr = $('<tr></tr>'); | ||||
|         tb.append(tr); | ||||
|         var td = $('<td class="label" style="width:160px;vertical-align:top;">Notes:</td>'); | ||||
|         tr.append(td); | ||||
|         td = $('<td></td>'); | ||||
|         tr.append(td); | ||||
|         txtnotes = $('<div></div>'); | ||||
|         td.append(txtnotes); | ||||
|  | ||||
|         var ul = $('<ul class="tab_header" style="padding-top: 5px;"></ul>'); | ||||
|         divpkg.append(ul); | ||||
|  | ||||
|         var tabName = "tabTemplates"; | ||||
|         var templi = $('<li></li>').attr('data-href', tabName); | ||||
|         ul.append(templi); | ||||
|         templi.append($('<span></span>').text(GetTextByKey("P_TEMPLATES", 'Templates'))); | ||||
|         templi.click(function () { | ||||
|             reshowgrid(); | ||||
|         }); | ||||
|         tempgridholder = InitTemplateGridData(); | ||||
|         tempgridholder.attr('data-page', tabName) | ||||
|         divpkg.append(tempgridholder); | ||||
|  | ||||
|         tabName = "tabSections"; | ||||
|         var li = $('<li></li>').attr('data-href', tabName); | ||||
|         ul.append(li); | ||||
|         li.append($('<span></span>').text(GetTextByKey("P_GLOBALSECTIONS", 'Global Sections'))); | ||||
|         li.click(function () { | ||||
|             reshowgrid(); | ||||
|         }); | ||||
|         sectiongridholder = InitSectionGridData(); | ||||
|         sectiongridholder.attr('data-page', tabName) | ||||
|         divpkg.append(sectiongridholder); | ||||
|  | ||||
|         ul.append($('<li style="clear: both;"></li>')); | ||||
|  | ||||
|         divpkg.tab(); | ||||
|         templi.click(); | ||||
|  | ||||
|         //divpkg.append($('<span style="margin-left:5px;font-size:16px;font-weight:bold;">Templates</span>')); | ||||
|         //divpkg.append(InitTemplateGridData()); | ||||
|  | ||||
|         //divpkg.append($('<span style="margin-left:5px;font-size:16px;font-weight:bold;">Global Sections</span>')); | ||||
|         //divpkg.append(InitSectionGridData()); | ||||
|  | ||||
|         var loading = $('<div id="mask_bg" style="display:none;"></div>'); | ||||
|         _this.loading = loading; | ||||
|         content.append(loading); | ||||
|  | ||||
|         return content; | ||||
|     }; | ||||
|  | ||||
|     function reshowgrid() { | ||||
|         setTimeout(function () { | ||||
|             tempgridholder.css("height", $(window).height() - tempgridholder.offset().top - 15); | ||||
|             grid_templatedt && grid_templatedt.resize(); | ||||
|             sectiongridholder.css("height", $(window).height() - sectiongridholder.offset().top - 15); | ||||
|             grid_sectiondt && grid_sectiondt.resize(); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     return imppkg; | ||||
| }); | ||||
							
								
								
									
										389
									
								
								Site/Inspection/js/modules/inspections.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										389
									
								
								Site/Inspection/js/modules/inspections.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,389 @@ | ||||
| define(['modules/inspects/inspect', 'modules/inspects/editinspection'], function (Inspect, EditModule) { | ||||
|     var gs = {}; | ||||
|     gs.title = GetTextByKey("P_INSPECTIONS", 'Inspections'); | ||||
|     gs.description = GetTextByKey("P_INSPECTIONS", 'Inspections'); | ||||
|     gs.version = '1.0'; | ||||
|     gs.status = 0; | ||||
|  | ||||
|     var datacontent = null; | ||||
|     var startdateinputcontrol = undefined; | ||||
|     var enddateinputcontrol = undefined; | ||||
|     var searchinputcontrol = undefined; | ||||
|     var makeinputcontrol = undefined; | ||||
|     var modelinputcontrol = undefined; | ||||
|     var typeinputcontrol = undefined; | ||||
|     var grid_dt; | ||||
|     gs.createContent = function (args) { | ||||
|         var _this = this; | ||||
|         if (args && args.length > 0) | ||||
|             gs.status = eval(args[0]); | ||||
|  | ||||
|         var content = $('<div style="width:100%;" ></div>'); | ||||
|  | ||||
|         function createHeader() { | ||||
|             var header = $('<div></div>'); | ||||
|             header.append($('<div class="page_title"></div>').text(gs.title)); | ||||
|             setPageTitle(gs.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" />'); | ||||
|             search_bar.append('<span style="margin-left:5px;">' + GetTextByKey("P_IPT_BEGINDATE_COLON", "Begin Date:") + '</span>'); | ||||
|             startdateinputcontrol = $('<input type="text" style="margin-left: 5px; width: 80px;" autocomplete="off" />').val(begindate); | ||||
|             search_bar.append($('<span></span>').append(startdateinputcontrol)); | ||||
|             startdateinputcontrol.datetimepicker({ | ||||
|                 timepicker: false, | ||||
|                 format: 'm/d/Y' | ||||
|             }); | ||||
|             search_bar.append('<span style="margin-left:10px;">' + GetTextByKey("P_IPT_ENDDATE_COLON", "End Date:") + '</span>'); | ||||
|             enddateinputcontrol = $('<input type="text" style="margin-left: 5px; width: 80px;" autocomplete="off" />').val(enddate); | ||||
|             search_bar.append($('<span></span>').append(enddateinputcontrol)); | ||||
|             enddateinputcontrol.datetimepicker({ | ||||
|                 timepicker: false, | ||||
|                 format: 'm/d/Y' | ||||
|             }); | ||||
|  | ||||
|             makeinputcontrol = $('<select type="text" style="margin-left: 5px; width: 80px;" autocomplete="off" />').val(enddate); | ||||
|             search_bar.append($('<span></span>').append(enddateinputcontrol)); | ||||
|             enddateinputcontrol.datetimepicker({ | ||||
|                 timepicker: false, | ||||
|                 format: 'm/d/Y' | ||||
|             }); | ||||
|  | ||||
|  | ||||
|             searchinputcontrol = $('<input type="text" style="margin-left:10px;" autocomplete="off" />'); | ||||
|             search_bar.append(searchinputcontrol); | ||||
|             searchinputcontrol.keydown(function (e) { | ||||
|                 if (e.keyCode == 13 || e.keyCode == 9) | ||||
|                     gs.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 () { | ||||
|                 gs.refresh(); | ||||
|             }); | ||||
|  | ||||
|             var func = $('<div class="function_title"></div>'); | ||||
|             if (!ReportReadonly) { | ||||
|                 var iconEdit = $('<span class="sbutton iconedit">' + GetTextByKey("P_IPT_EDIT", "Edit") + '</span>').click(function () { | ||||
|                     if (grid_dt.selectedIndex >= 0) { | ||||
|                         gs.onedit(); | ||||
|                     } | ||||
|                 }); | ||||
|                 func.append(iconEdit); | ||||
|             } | ||||
|             var iconRefresh = $('<span class="sbutton iconrefresh">' + GetTextByKey("P_IPT_REFRESH", "Refresh") + '</span>').click(function () { | ||||
|                 gs.refresh(); | ||||
|             }); | ||||
|             func.append(iconRefresh); | ||||
|             var iconResetPivots = $('<span class="sbutton iconfilter">' + GetTextByKey("P_IPT_XXXXXX", "Reset Pivots") + '</span>').click(function () { | ||||
|                 if (grid_dt && grid_dt.columns) { | ||||
|                     for (var i = 0; i < grid_dt.columns.length; i++) { | ||||
|                         if (grid_dt.columns[i].filterValues) | ||||
|                             grid_dt.columns[i].filterValues = null; | ||||
|                     } | ||||
|                     grid_dt.refreshGrid(); | ||||
|                 } | ||||
|             }); | ||||
|             func.append(iconResetPivots); | ||||
|             header.append(func) | ||||
|  | ||||
|             return header; | ||||
|         } | ||||
|  | ||||
|         function InitGridData() { | ||||
|             var div_grid = $('<div></div>'); | ||||
|             div_grid.css("height", $(window).height() - 185); | ||||
|  | ||||
|             grid_dt = new GridView(div_grid); | ||||
|             grid_dt.lang = { | ||||
|                 all: GetTextByKey("P_GRID_ALL", "(All)"), | ||||
|                 ok: GetTextByKey("P_GRID_OK", "OK"), | ||||
|                 reset: GetTextByKey("P_GRID_RESET", "Reset") | ||||
|             }; | ||||
|             var list_columns = [ | ||||
|                 { name: 'TemplateName', caption: GetTextByKey("P_TEMPLATE", "Template"), allowFilter: true, valueIndex: 'TemplateName', css: { 'width': 250, 'text-align': 'left' } }, | ||||
|                 { name: 'AssetName', caption: GetTextByKey("P_IPT_ASSETNAME", "Asset Name"), valueIndex: 'AssetName', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } }, | ||||
|                 { name: 'WorkOrderNumber', caption: GetTextByKey("P_IPT_WORKORDER", "Work Order"), valueIndex: 'WorkOrderNumber', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } }, | ||||
|                 { name: 'CustomerName', caption: GetTextByKey("P_IPT_XXX", "Customer Name"), valueIndex: 'CustomerName', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } }, | ||||
|                 { name: 'VisibleToCustomer', caption: GetTextByKey("P_IPT_CUSTOMERVISIBLE", "Customer Visible"), valueIndex: 'VisibleToCustomer', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } }, | ||||
|                 { name: 'VIN', caption: GetTextByKey("P_IPT_VIN", "VIN"), valueIndex: 'VIN', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } }, | ||||
|                 { name: 'MakeName', caption: GetTextByKey("P_IPT_MAKE", "Make"), valueIndex: 'MakeName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } }, | ||||
|                 { name: 'ModelName', caption: GetTextByKey("P_IPT_MODEL", "Model"), valueIndex: 'ModelName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } }, | ||||
|                 { name: 'TypeName', caption: GetTextByKey("P_IPT_ASSETTYPE", "Asset Type"), valueIndex: 'TypeName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } }, | ||||
|                 { name: 'Status', caption: GetTextByKey("P_IPT_STATUS", "Status"), valueIndex: 'Status', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } }, | ||||
|                 { name: 'CommitTimeLocal', caption: GetTextByKey("P_IPT_COMMITTIME", "Commit Time"), valueIndex: 'CommitTimeLocal', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } }, | ||||
|                 { name: 'CommitedByUserName', caption: GetTextByKey("P_IPT_COMMITUSER", "Commit User"), valueIndex: 'CommitedByUserName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } }, | ||||
|                 { name: 'LastUpdatedTimeLocal', caption: GetTextByKey("P_IPT_LASTUPDATEDTIME", "Last Updated Time"), valueIndex: 'LastUpdatedTimeLocal', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } }, | ||||
|                 { name: 'LastUpdatedByUserName', caption: GetTextByKey("P_IPT_LASTUPDATEDUSER", "Last Updated User"), valueIndex: 'LastUpdatedByUserName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } }, | ||||
|                 { name: 'Edit', caption: "", css: { 'width': 30, 'text-align': 'center' } }, | ||||
|                 { name: 'Detail', caption: "", css: { 'width': 30, 'text-align': 'center' } }, | ||||
|                 { name: 'DownloadPDF', caption: "", css: { 'width': 30, 'text-align': 'center' } }, | ||||
|                 { name: 'Print', caption: "", css: { 'width': 30, 'text-align': 'center' } }, | ||||
|                 { name: 'ViewChangeHistory', caption: "", css: { 'width': 30, 'text-align': 'center' } } | ||||
|             ]; | ||||
|             var columns = []; | ||||
|             // head | ||||
|             for (var hd in list_columns) { | ||||
|                 var col = {}; | ||||
|                 col.name = list_columns[hd].name; | ||||
|                 if (ReportReadonly && col.name === 'Edit') { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 col.caption = list_columns[hd].caption; | ||||
|                 col.visible = true; | ||||
|                 col.sortable = true; | ||||
|                 col.width = list_columns[hd].css.width; | ||||
|                 col.align = list_columns[hd].css["text-align"] | ||||
|                 col.key = list_columns[hd].valueIndex; | ||||
|                 col.allowFilter = list_columns[hd].allowFilter; | ||||
|                 if (!IsCustomerRecord && (col.name === "CustomerName")) { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 if (col.name === "TemplateName" || col.name === "AssetName") { | ||||
|                     col.isurl = true; | ||||
|                     col.sortable = false; | ||||
|                     col.events = { | ||||
|                         onclick: function () { | ||||
|                             _this.openReport(); | ||||
|                         } | ||||
|                     }; | ||||
|                     col.styleFilter = function () { | ||||
|                         return { | ||||
|                             'color': 'black', | ||||
|                             'cursor': 'pointer', | ||||
|                             //'text-decoration': 'none' | ||||
|                         }; | ||||
|                     } | ||||
|                 } | ||||
|                 else if (col.name === "Edit") { | ||||
|                     col.isurl = true; | ||||
|                     col.text = "\uf044"; | ||||
|                     col.sortable = false; | ||||
|                     col.events = { | ||||
|                         onclick: function () { | ||||
|                             _this.onedit(); | ||||
|                         } | ||||
|                     }; | ||||
|                     col.classFilter = function (e) { | ||||
|                         return "icon-col"; | ||||
|                     } | ||||
|                     col.attrs = { 'title': GetTextByKey("P_IPT_EDIT", 'Edit') }; | ||||
|                 } | ||||
|                 else if (col.name === "Detail") { | ||||
|                     col.isurl = true; | ||||
|                     col.text = "\uf0c9"; | ||||
|                     col.sortable = false; | ||||
|                     col.events = { | ||||
|                         onclick: function () { | ||||
|                             _this.openReport(); | ||||
|                         } | ||||
|                     }; | ||||
|                     col.classFilter = function (e) { | ||||
|                         return "icon-col"; | ||||
|                     } | ||||
|                     col.attrs = { 'title': GetTextByKey("P_IPT_DETAIL", 'Detail') }; | ||||
|                 } | ||||
|                 else if (col.name === "DownloadPDF") { | ||||
|                     col.isurl = true; | ||||
|                     col.text = "\uf019"; | ||||
|                     col.sortable = false; | ||||
|                     col.visible = canExport; | ||||
|                     col.events = { | ||||
|                         onclick: function () { | ||||
|                             window.open("Inspection.aspx?rt=f&t=1&id=" + this.Id + "&team=" + (teamintelligence ? 1 : 0), '_blank'); | ||||
|                         } | ||||
|                     }; | ||||
|                     col.classFilter = function (e) { | ||||
|                         return "icon-col"; | ||||
|                     } | ||||
|                     col.attrs = { 'title': GetTextByKey("P_IPT_DOWNLOADPDF", 'Download PDF') }; | ||||
|                 } | ||||
|                 else if (col.name === "Print") { | ||||
|                     col.isurl = true; | ||||
|                     col.text = "\uf02f"; | ||||
|                     col.sortable = false; | ||||
|                     col.visible = canExport; | ||||
|                     col.events = { | ||||
|                         onclick: function () { | ||||
|                             if (navigator.userAgent.indexOf('Firefox') >= 0 || | ||||
|                                 navigator.userAgent.indexOf('Opera') >= 0) { | ||||
|                                 window.open("Inspection.aspx?rt=f&t=2&id=" + this.Id + "&team=" + (teamintelligence ? 1 : 0), '_blank'); | ||||
|                             } | ||||
|                             else | ||||
|                                 OnPrint(this.Id); | ||||
|                         } | ||||
|                     }; | ||||
|                     col.classFilter = function (e) { | ||||
|                         return "icon-col"; | ||||
|                     } | ||||
|                     col.attrs = { 'title': GetTextByKey("P_IPT_PRINT", 'Print') }; | ||||
|                 } | ||||
|                 else if (col.name === "ViewChangeHistory") { | ||||
|                     col.isurl = true; | ||||
|                     col.text = "\uf06e"; | ||||
|                     col.sortable = false; | ||||
|                     col.events = { | ||||
|                         onclick: function () { | ||||
|                             _this.onViewChangeHistory(); | ||||
|                         } | ||||
|                     }; | ||||
|                     col.classFilter = function (e) { | ||||
|                         return "icon-col"; | ||||
|                     } | ||||
|                     col.attrs = { 'title': GetTextByKey("P_IPT_VIEWCHANGEHIS", 'View Change History') }; | ||||
|                 } | ||||
|  | ||||
|                 if (col.name === "AssetName" || col.name === "VIN" || col.name === "MakeName" || col.name === "ModelName" || col.name === "TypeName" || col.name === "WorkOrderNumber" || col.name === "VisibleToCustomer" || col.name === "CustomerName") { | ||||
|                     col.visible = !teamintelligence; | ||||
|                 } | ||||
|  | ||||
|                 if (!teamintelligence && AllowReassignWorkorders && col.name === "WorkOrderNumber") { | ||||
|                     col.allowHtml = true; | ||||
|                     col.filterCustom = true; | ||||
|                     col.filter = function (item) { | ||||
|                         if (item.Id === "") | ||||
|                             return htmldecode(item.WorkOrderNumber); | ||||
|  | ||||
|                         var div = $('<div class="dropdown" style="width: 200px;"></div>'); | ||||
|                         div.dropdown(item.WorkOrders || [{ Id: -1, WorkOrderNumber: "Not Assigned" }], { | ||||
|                             search: false, | ||||
|                             textKey: 'WorkOrderNumber', | ||||
|                             valueKey: 'Id', | ||||
|                             selected: item.WorkOrderId > 0 ? item.WorkOrderId : -1, | ||||
|                             parent: '#content' | ||||
|                         }).on('select', function (_e, wo) { | ||||
|                             if (wo) { | ||||
|                                 var msg1 = GetTextByKey('P_WO_AREYOUSURETHATYOUWANTTOPROCEED', 'Are you sure that you want to proceed ?'); | ||||
|                                 var msg = GetTextByKey('P_WO_YOUAREREASSIGNINGTHISWORKORDER', 'You are reassigning this work order. ') + "<br/>" + msg1; | ||||
|                                 if (wo.Completed) | ||||
|                                     msg = GetTextByKey('P_WO_YOUAREREASSIGNINGTHISWORKORDERTOACLOSEDWORKORDER', 'You are reassigning this Work Order to a CLOSED Work Order.') + "<br/>" + msg1; | ||||
|                                 showConfirm(msg, GetTextByKey("P_WO_WORKORDERASSIGNMENT", 'Work Order Assignment'), function () { | ||||
|                                     var oldwoid = item.WorkOrderId; | ||||
|                                     item.WorkOrderId = wo.Id; | ||||
|                                     item.WorkOrderNumber = wo.WorkOrderNumber; | ||||
|                                     updateInspectionWorkOrder(item.Id, item.WorkOrderId, oldwoid, wo.CustomerName); | ||||
|                                 }, function () { | ||||
|                                     var dropdown = div.data('dropdown'); | ||||
|                                     if (dropdown) | ||||
|                                         dropdown.select(item.WorkOrderId > 0 ? item.WorkOrderId : -1); | ||||
|                                 }); | ||||
|                             } | ||||
|                         }); | ||||
|                         return div; | ||||
|                     } | ||||
|                     col.styleFilter = function () { | ||||
|                         return { "width": "100%", 'margin': 0 }; | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 columns.push(col); | ||||
|             } | ||||
|             grid_dt.canMultiSelect = false; | ||||
|             grid_dt.columns = columns; | ||||
|             grid_dt.init(); | ||||
|             grid_dt.rowdblclick = _this.openReport; | ||||
|  | ||||
|             grid_dt.selectedrowchanged = function (rowindex) { | ||||
|                 var rowdata = grid_dt.source[rowindex]; | ||||
|                 if (rowdata) { | ||||
|                 } | ||||
|             } | ||||
|             return div_grid; | ||||
|         } | ||||
|  | ||||
|         content.append(createHeader()); | ||||
|         content.append(InitGridData()); | ||||
|         datacontent = $('<div></div>'); | ||||
|         content.append(datacontent); | ||||
|  | ||||
|         _this.refresh(); | ||||
|         return content; | ||||
|     } | ||||
|  | ||||
|     gs.onedit = function () { | ||||
|         var _this = this; | ||||
|         var index = grid_dt.selectedIndex; | ||||
|         var inspect = grid_dt.source[index].Values; | ||||
|  | ||||
|  | ||||
|         // check permissions | ||||
|         var ei = new EditModule.EditInspection(_this, inspect.Id); | ||||
|         $('#right_popup').empty().append(ei.createContent()); | ||||
|         showRightPopup(true); | ||||
|  | ||||
|  | ||||
|     } | ||||
|  | ||||
|     gs.openReport = function () { | ||||
|         var index = grid_dt.selectedIndex; | ||||
|         var inspect = grid_dt.source[index].Values; | ||||
|         window.open("report.aspx?rid=" + inspect.Id + "&ro=" + (ReportReadonly ? 1 : 0), "_blank"); | ||||
|     } | ||||
|  | ||||
|     gs.onViewChangeHistory = function () { | ||||
|         var index = grid_dt.selectedIndex; | ||||
|         var inspect = grid_dt.source[index].Values; | ||||
|         window.open("InspectionChangeHistory.aspx?rid=" + inspect.Id, "_blank"); | ||||
|     } | ||||
|  | ||||
|     function updateInspectionWorkOrder(id, woid, oldwoid, custname) { | ||||
|         var p = JSON.stringify([id, woid, oldwoid]); | ||||
|         inspectionrequest("UpdateInspectionWorkOrder", htmlencode(p), function (data) { | ||||
|             if (typeof (data) === "string") { | ||||
|                 return; | ||||
|             } | ||||
|             if (grid_dt.selectedIndex >= 0) { | ||||
|                 grid_dt.source[grid_dt.selectedIndex].Values.CustomerName = custname; | ||||
|                 grid_dt && grid_dt.reload(); | ||||
|             } | ||||
|  | ||||
|         }, function (err) { | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     function showInspections(data) { | ||||
|         var rows = []; | ||||
|         for (var i = 0; i < data.length; i++) { | ||||
|             var r = data[i]; | ||||
|             var statustext = ""; | ||||
|             if (r.Status == 0) | ||||
|                 statustext = 'Draft'; | ||||
|             else if (r.Status == 1) | ||||
|                 statustext = 'Committed'; | ||||
|             for (var j in r) { | ||||
|                 if (j === "Status") { | ||||
|                     r[j] = { DisplayValue: statustext, Value: r[j] }; | ||||
|                 } else if (j === "CommitTimeLocal") { | ||||
|                     r[j] = { DisplayValue: r["CommitTimeLocalStr"], Value: r[j] }; | ||||
|                 } else if (j === "LastUpdatedTimeLocal") { | ||||
|                     r[j] = { DisplayValue: r["LastUpdatedTimeLocalStr"], Value: r[j] }; | ||||
|                 } else if (j === "VisibleToCustomer") { | ||||
|                     r[j] = { DisplayValue: r["VisibleToCustomer"] ? "Yes" : "No", Value: r[j] }; | ||||
|                 } | ||||
|             } | ||||
|             var fr = { Values: r }; | ||||
|             rows.push(fr); | ||||
|         } | ||||
|  | ||||
|         grid_dt.setData(rows); | ||||
|     } | ||||
|  | ||||
|     gs.refresh = function () { | ||||
|         datacontent.empty(); | ||||
|         var startydate = startdateinputcontrol.val(); | ||||
|         var enddate = enddateinputcontrol.val(); | ||||
|         var searchtxt = searchinputcontrol.val(); | ||||
|         searchtxt = htmlencode(searchtxt); | ||||
|         var p = JSON.stringify([teamintelligence, startydate, enddate, searchtxt]); | ||||
|         inspectionrequest("GetInspectItems", htmlencode(p), function (data) { | ||||
|             datacontent.empty(); | ||||
|             if (data) { | ||||
|                 showInspections(data); | ||||
|             } | ||||
|         }, function (err) { | ||||
|         }); | ||||
|     } | ||||
|     return gs; | ||||
| }); | ||||
							
								
								
									
										407
									
								
								Site/Inspection/js/modules/inspects/editinspection.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										407
									
								
								Site/Inspection/js/modules/inspects/editinspection.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,407 @@ | ||||
| define(['modules/inspects/editsection', 'modules/inspects/editquestion'], function (Section, Question) { | ||||
|     var edit = function (inspection, id) { | ||||
|         this.reportId = id; | ||||
|         this.instance = inspection; | ||||
|     }; | ||||
|  | ||||
|     var __proto = edit.prototype; | ||||
|  | ||||
|     function onSave(_this, exit) { | ||||
|         var alerttitle = GetTextByKey("P_IPT_EDITINSPECTION", 'Edit Inspection'); | ||||
|         if (!_this || !_this.report) { | ||||
|             showAlert(GetTextByKey("P_IPT_PAGEERROR", 'An unknown error occurred.  Please refresh page.'), alerttitle); | ||||
|             return; | ||||
|         } | ||||
|         _this.loading && _this.loading.fadeIn(100); | ||||
|         var pages = _this.content.children('div[data-page]'); | ||||
|         var answers = []; | ||||
|         for (var i = 0; i < pages.length; i++) { | ||||
|             var qs = $(pages[i]).find('.question-item'); | ||||
|             for (var j = 0; j < qs.length; j++) { | ||||
|                 var question = $(qs[j]).data('question'); | ||||
|                 var q = question.question; | ||||
|                 var a = question.getAnswer(); | ||||
|                 var flag; | ||||
|                 var msg; | ||||
|                 var isChoice = | ||||
|                     q.QuestionType === Question.types.List || | ||||
|                     q.QuestionType === Question.types.DropDown || | ||||
|                     q.QuestionType === Question.types.YesOrNo || | ||||
|                     q.QuestionType === Question.types.EmailList || | ||||
|                     q.QuestionType === Question.types.AssetStatus || | ||||
|                     (q.QuestionType === Question.types.FuelRecords | ||||
|                         && (q.SubType === Question.fueltypes.State || | ||||
|                             q.SubType === Question.fueltypes.FuelType)); | ||||
|                 if (q.IsRequired) { | ||||
|                     if (isChoice) { | ||||
|                         flag = a.SelectedItems == null || a.SelectedItems.length == 0; | ||||
|                     } else if (a.Result == null || a.Result.length == 0) { | ||||
|                         if (q.QuestionType === Question.types.Picture) { | ||||
|                             flag = false; | ||||
|                         } else if (q.QuestionType === Question.types.FuelRecords | ||||
|                             && (q.SubType === Question.fueltypes.TotalCost || | ||||
|                                 q.SubType === Question.fueltypes.Picture)) { | ||||
|                             flag = false; | ||||
|                         } else { | ||||
|                             flag = true; | ||||
|                         } | ||||
|                     } | ||||
|                 } else if (a.Comment == null || a.Comment.length == 0) { | ||||
|                     if (isChoice) { | ||||
|                         if (a.SelectedItems == null || a.SelectedItems.length == 0) { | ||||
|                             continue; | ||||
|                         } | ||||
|                     } else if (a.Result == null || a.Result.length == 0) { | ||||
|                         if (q.QuestionType !== Question.types.Picture) { | ||||
|                             continue; | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 // check | ||||
|                 if (!flag && a.Result != null && a.Result.length > 0) { | ||||
|                     switch (q.QuestionType) { | ||||
|                         case Question.types.DateAndTime: | ||||
|                             if (isNaN(new Date(a.Result.replace(' ', 'T')))) { | ||||
|                                 msg = GetTextByKey("P_IPT_SUPPLIEDINPUTISNOTAVALIDTIME", 'Supplied input is not a valid time.'); | ||||
|                             } | ||||
|                             break; | ||||
|                         case Question.types.Email: | ||||
|                             var emails = a.Result.split(';'); | ||||
|                             for (var k = 0; k < emails.length; k++) { | ||||
|                                 if (!/^[0-9a-zA-Z][^@]*@[0-9a-zA-Z.]+$/.test(emails[k].trim())) { | ||||
|                                     msg = GetTextByKey("P_IPT_VALIDEMAILADDRESSFORMATREQUIRED", 'Valid email address format required.'); | ||||
|                                 } | ||||
|                             } | ||||
|                             break; | ||||
|                         case Question.types.EngingHours: | ||||
|                         case Question.types.Number: | ||||
|                         case Question.types.Odometer: | ||||
|                         case Question.types.FuelUsed: | ||||
|                             if (isNaN(Number(a.Result))) { | ||||
|                                 msg = GetTextByKey("P_IPT_SUPPLIEDINPUTISNOTAVALIDNUMBER", 'Supplied input is not a valid number.'); | ||||
|                             } | ||||
|                             break; | ||||
|                         case Question.types.FuelRemaining: | ||||
|                             var d = Number(a.Result); | ||||
|                             if (isNaN(d) || d < 0 || d > 100) { | ||||
|                                 msg = GetTextByKey("P_IPT_SUPPLIEDINPUTISNOTAVALIDPERCENTVALUE", 'Supplied input is not a valid percent value.'); | ||||
|                             } | ||||
|                             break; | ||||
|                         case Question.types.Integer: | ||||
|                             if (isNaN(Number(a.Result)) || a.Result.indexOf('.') >= 0) { | ||||
|                                 msg = 'Supplied input is not a valid integer.'; | ||||
|                             } | ||||
|                             break; | ||||
|                         case Question.types.FuelRecords: | ||||
|                             switch (q.SubType) { | ||||
|                                 case Question.fueltypes.Odometer: | ||||
|                                 case Question.fueltypes.Quantity: | ||||
|                                     if (isNaN(Number(a.Result))) { | ||||
|                                         msg = GetTextByKey("P_IPT_SUPPLIEDINPUTISNOTAVALIDNUMBER", 'Supplied input is not a valid number.'); | ||||
|                                     } | ||||
|                                     break; | ||||
|                             } | ||||
|                             break; | ||||
|                     } | ||||
|                 } | ||||
|                 if (flag || msg) { | ||||
|                     showAlert(flag ? GetTextByKey("P_IPT_THEQUESTIONISREQUIRED", 'The question is required.') : (msg || GetTextByKey("P_IPT_QUESTIONRESULTISINVALID", 'Question result is invalid.')), alerttitle, null, function () { | ||||
|                         if (typeof question.focus === 'function') { | ||||
|                             question.focus(); | ||||
|                         } | ||||
|                     }); | ||||
|                     _this.loading && _this.loading.fadeOut(100); | ||||
|                     return; | ||||
|                 } | ||||
|                 if (q.QuestionType === Question.types.AssetStatus) { | ||||
|                     a.Result = a.Comment; | ||||
|                     a.Comment = ""; | ||||
|                 } | ||||
|  | ||||
|                 answers.push(a); | ||||
|             } | ||||
|         } | ||||
|         _this.report.Answers = answers; | ||||
|         _this.report.Medias = []; | ||||
|         console.log(answers); | ||||
|  | ||||
|         var p = JSON.stringify(_this.report); | ||||
|         inspectionrequest('UpdateInspectionReport', htmlencode(p), function (result) { | ||||
|             if (typeof result === 'string') { | ||||
|                 showAlert(GetTextByKey("P_IPT_PAGEERROR1", 'An unknown error occurred. ') + result, alerttitle); | ||||
|                 _this.loading && _this.loading.fadeOut(100); | ||||
|                 return; | ||||
|             } else if (!result) { | ||||
|                 showAlert(GetTextByKey("P_IPT_FAILEDTOUPDATEINSPECTION", 'Failed to update inspection.'), alerttitle); | ||||
|                 _this.loading && _this.loading.fadeOut(100); | ||||
|                 return; | ||||
|             } else { | ||||
|                 _this.changed = true; | ||||
|                 if (exit) { | ||||
|                     showRightPopup(false); | ||||
|                     if (typeof _this.instance === 'function') { | ||||
|                         showAlert(GetTextByKey("P_IPT_UPDATEINSPECTIONSUCCESSFULLY", 'Update inspection successfully.'), alerttitle, null, function () { | ||||
|                             _this.instance(); | ||||
|                         }); | ||||
|                         return; | ||||
|                     } else { | ||||
|                         _this.instance.refresh(); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             showAlert(GetTextByKey("P_IPT_UPDATEINSPECTIONSUCCESSFULLY", 'Update inspection successfully.'), alerttitle); | ||||
|             _this.loading && _this.loading.fadeOut(100); | ||||
|         }, function () { | ||||
|             showAlert(GetTextByKey("P_IPT_PAGEERROR", 'An unknown error occurred.  Please refresh page.'), alerttitle); | ||||
|             _this.loading && _this.loading.fadeOut(100); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     __proto.createContent = function () { | ||||
|         var _this = this; | ||||
|         var content = $('<div></div>'); | ||||
|         this.content = content; | ||||
|         var funcs = $('<div class="function_title"></div>'); | ||||
|         var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE", "Save") + '</span>').click(function () { | ||||
|             onSave(_this); | ||||
|         }); | ||||
|         funcs.append(btn); | ||||
|         btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE1", "Save and Exit") + '</span>').click(function () { | ||||
|             onSave(_this, true); | ||||
|         }); | ||||
|         funcs.append(btn); | ||||
|         btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_SAVE2", "Exit Without Saving") + '</span>').click(function () { | ||||
|             showRightPopup(false); | ||||
|             if (_this.changed) { | ||||
|                 if (typeof _this.instance === 'function') { | ||||
|                     _this.instance(); | ||||
|                 } else { | ||||
|                     _this.instance.refresh(); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|         funcs.append(btn); | ||||
|         content.append(funcs); | ||||
|  | ||||
|         // committed information | ||||
|         var info = $('<div style="margin: 6px 0 0 10px; line-height: 32px"></div>'); | ||||
|         var templatename = $('<span style="font-size: 1.7em"></span>'); | ||||
|         info.append(templatename); | ||||
|         var committedby = $('<span style="margin-left: 10px"></span>'); | ||||
|         info.append(committedby); | ||||
|         content.append(info); | ||||
|         // asset info | ||||
|         var assetpanel = $('<div style="margin: 6px 0 0 10px; line-height: 26px"></div>').hide(); | ||||
|         content.append(assetpanel); | ||||
|  | ||||
|         var ul = $('<ul class="tab_header" style="padding-top: 5px;"></ul>'); | ||||
|         content.append(ul); | ||||
|  | ||||
|         //var tabIndex = 0; | ||||
|         //for (var i = 0; i < this.pages.length; i++) { | ||||
|         //    var p = this.pages[i]; | ||||
|         //    addTab(p, false); | ||||
|         //} | ||||
|         var p = JSON.stringify([teamintelligence, this.reportId]); | ||||
|         inspectionrequest('GetInspectionReportForEdit', htmlencode(p), function (data) { | ||||
|             console.log(data); | ||||
|             if (typeof data === 'string') { | ||||
|                 showAlert(data + GetTextByKey("P_IPT_REFRESHPAGE", ' Please refresh page.'), GetTextByKey("P_IPT_EDITINSPECTION", 'Edit Inspection')); | ||||
|                 return; | ||||
|             } | ||||
|             _this.report = data; | ||||
|             //if (data.AssetList) { | ||||
|             //    window.AssetList = data.AssetList; | ||||
|             //} | ||||
|             if (data.EmailList) { | ||||
|                 window.EmailList = data.EmailList; | ||||
|             } | ||||
|             if (data.JobSiteList) { | ||||
|                 window.JobSiteList = data.JobSiteList; | ||||
|             } | ||||
|             templatename.text(data.Template.Name); | ||||
|             committedby.text(data.CommitTimeLocalStr + ' by ' + data.CommitedByUserName); | ||||
|             if (data.Target === 0 && data.Asset) { | ||||
|                 var asset = data.Asset; | ||||
|                 var tb = $('<table class="inspect-asset" style="width: 100%"></table>'); | ||||
|                 var tr = $('<tr></tr>'); | ||||
|                 var td = $('<td style="width: 25%"><b style="display: inline-block; width: 85px">' + GetTextByKey("P_IPT_ASSETNAME_COLON", "Asset Name:") + '</b></td>'); | ||||
|                 td.append($('<span style="margin-left: 6px"></span>').text(asset.DisplayName)); | ||||
|                 tr.append(td); | ||||
|                 td = $('<td colspan="3" style="width: 75%"><b style="display: inline-block; width: 145px">' + GetTextByKey("P_IPT_ASSETNAME2_COLON", "Asset Name(Custom):") + '</b></td>'); | ||||
|                 td.append($('<span style="margin-left: 6px"></span>').text(asset.Name2 || asset.Name)); | ||||
|                 tr.append(td); | ||||
|                 tb.append(tr); | ||||
|                 tr = $('<tr></tr>'); | ||||
|                 td = $('<td style="width: 25%"><b style="display: inline-block; width: 85px">' + GetTextByKey("P_IPT_VINSN_COLON", "VIN/SN:") + '</b></td>'); | ||||
|                 td.append($('<span style="margin-left: 6px"></span>').text(asset.VIN)); | ||||
|                 tr.append(td); | ||||
|                 td = $('<td style="width: 30%"><b style="display: inline-block; width: 145px">' + GetTextByKey("P_IPT_MAKE_COLON", "Make:") + '</b></td>'); | ||||
|                 td.append($('<span style="margin-left: 6px"></span>').text(asset.MakeName)); | ||||
|                 tr.append(td); | ||||
|                 td = $('<td style="width: 20%"><b>' + GetTextByKey("P_IPT_MODEL_COLON", "Model:") + '</b></td>'); | ||||
|                 td.append($('<span style="margin-left: 6px"></span>').text(asset.ModelName)); | ||||
|                 tr.append(td); | ||||
|                 td = $('<td style="width: 25%"><b>' + GetTextByKey("P_IPT_ASSETTYPE_COLON", "Asset Type:") + '</b></td>'); | ||||
|                 td.append($('<span style="margin-left: 6px"></span>').text(asset.TypeName)); | ||||
|                 tr.append(td); | ||||
|                 tb.append(tr); | ||||
|  | ||||
|                 if (data.ForWorkOrder) { | ||||
|                     tr = $('<tr></tr>'); | ||||
|                     td = $('<td style="width: 25%"><b style="display: inline-block; width: 85px">' + GetTextByKey("P_IPT_WORKORDER_COLON", "Work Order:") + '</b></td>'); | ||||
|                     var selwo = $('<select style="margin-left: 6px;width: 160px"></select>'); | ||||
|                     selwo.change(function () { | ||||
|                         _this.report.WorkOrderId = selwo.find("option:selected").val(); | ||||
|                     }); | ||||
|                     td.append(selwo);//WorkOrderId | ||||
|                     tr.append(td); | ||||
|  | ||||
|  | ||||
|                     td = $('<td style="width: 25%"><label for="chkcv"><b style="display: inline-block; width: 145px;">' + GetTextByKey("P_IPT_CUSTOMERVISIBLE_COLON", "Customer Visible:") + '</b><label></td>'); | ||||
|                     var chkcv = $('<input id="chkcv" type="checkbox" style="margin-left: 6px;" />'); | ||||
|                     chkcv.change(function () { | ||||
|                         _this.report.VisibleToCustomer = chkcv.prop("checked"); | ||||
|                     }); | ||||
|                     chkcv.prop("checked", _this.report.VisibleToCustomer); | ||||
|                     td.append(chkcv);//VisibleToCustomer | ||||
|                     tr.append(td); | ||||
|  | ||||
|                     tb.append(tr); | ||||
|  | ||||
|                     selwo.append($("<option></option>").val(-1).text("")); | ||||
|                     inspectionrequest('GetAssetWorkOrders', data.AssetId, function (list) { | ||||
|                         if (typeof list === 'string') { | ||||
|                         } else if (list && list.length > 0) { | ||||
|                             var txt = ""; | ||||
|                             for (var i = 0; i < list.length; i++) { | ||||
|                                 var wo = list[i]; | ||||
|                                 txt = wo.Id; | ||||
|                                 if (wo.CustomerName && $.trim(wo.CustomerName) != "") | ||||
|                                     txt += " - " + wo.CustomerName; | ||||
|                                 selwo.append($("<option></option>").val(wo.Id).text(txt)); | ||||
|                             } | ||||
|                         } | ||||
|                         selwo.val(data.WorkOrderId); | ||||
|                     }); | ||||
|                 } | ||||
|  | ||||
|                 assetpanel.empty().show().append(tb); | ||||
|             } | ||||
|  | ||||
|             // pages | ||||
|             var hasAssets = false; | ||||
|             for (var i = 0; i < data.Template.Pages.length; i++) { | ||||
|                 var page = data.Template.Pages[i]; | ||||
|                 var name = 'page_' + i; | ||||
|                 var li = $('<li></li>').attr('data-href', name); | ||||
|                 if (i == 0) { | ||||
|                     li.addClass('selected'); | ||||
|                 } | ||||
|                 ul.append(li); | ||||
|                 li.append($('<span class="spanbtn icondetail"></span>')); | ||||
|                 li.append($('<span></span>').text(page.DisplayText)); | ||||
|  | ||||
|                 // content | ||||
|                 var p = $('<div></div>').attr('data-page', name); | ||||
|                 var change = (function (panel) { | ||||
|                     return function (e) { | ||||
|                         var v = e.data.getAnswer(); | ||||
|                         var left = parseFloat(v && v.Result); | ||||
|                         if (isNaN(left)) { | ||||
|                             return; | ||||
|                         } | ||||
|                         var items = panel.find('.question-item'); | ||||
|                         var total; | ||||
|                         var rightObj; | ||||
|                         var right = e.data.question.SubType === Question.fueltypes.Quantity | ||||
|                             ? Question.fueltypes.UnitCost : Question.fueltypes.Quantity; | ||||
|                         for (var n = 0; n < items.length; n++) { | ||||
|                             var q = $(items[n]).data('question'); | ||||
|                             if (q.question.QuestionType === Question.types.FuelRecords) { | ||||
|                                 if (total == null && q.question.SubType === Question.fueltypes.TotalCost) { | ||||
|                                     total = q; | ||||
|                                     if (rightObj != null) { | ||||
|                                         break; | ||||
|                                     } | ||||
|                                 } else if (rightObj == null && q.question.SubType === right) { | ||||
|                                     rightObj = q; | ||||
|                                     if (total != null) { | ||||
|                                         break; | ||||
|                                     } | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                         if (total != null && rightObj != null) { | ||||
|                             var a = rightObj.getAnswer(); | ||||
|                             var val = parseFloat(a && a.Result); | ||||
|                             if (!isNaN(val)) { | ||||
|                                 total.fillResult((left * val).toFixed(2)); | ||||
|                             } | ||||
|                         } | ||||
|                     }; | ||||
|                 })(p); | ||||
|                 for (var j = 0; j < page.Sections.length; j++) { | ||||
|                     var section = new Section(page.Sections[j], data); | ||||
|                     if (!hasAssets && section.section.Questions.filter(function (q) { | ||||
|                         return q.QuestionType === Question.types.DropDown && ( | ||||
|                             q.LookupSource === Question.sources.Assets || | ||||
|                             q.LookupSource === Question.sources.AssetCustomerName); | ||||
|                     }).length > 0) { | ||||
|                         hasAssets = true; | ||||
|                         inspectionrequest('GetAssetBasicInfoForEdit', '', function (list) { | ||||
|                             if (typeof list === 'string') { | ||||
|                                 console.log(list); | ||||
|                             } else if (list && list.length > 0) { | ||||
|                                 window.AssetList = list; | ||||
|                                 var pages = _this.content.children('div[data-page]'); | ||||
|                                 for (var i = 0; i < pages.length; i++) { | ||||
|                                     var qs = $(pages[i]).find('.question-item'); | ||||
|                                     for (var j = 0; j < qs.length; j++) { | ||||
|                                         var question = $(qs[j]).data('question'); | ||||
|                                         var q = question.question; | ||||
|                                         if (q.QuestionType === Question.types.DropDown && ( | ||||
|                                             q.LookupSource === Question.sources.Assets || | ||||
|                                             q.LookupSource === Question.sources.AssetCustomerName)) { | ||||
|                                             question.setLoaded && question.setLoaded(); | ||||
|                                         } | ||||
|                                     } | ||||
|                                 } | ||||
|                                 console.log(GetTextByKey("P_IPT_LOADEDASSETLIST", 'loaded asset list: ') + list.length); | ||||
|                             } else { | ||||
|                                 console.log(GetTextByKey("P_IPT_FAILEDTODOWNLOADASSETLIST", 'failed to download asset list.')); | ||||
|                             } | ||||
|                         }); | ||||
|                     } | ||||
|                     p.append(section.createContent(change)); | ||||
|                 } | ||||
|                 content.append(p); | ||||
|  | ||||
|                 var items = p.find('.question-item'); | ||||
|                 for (var n = 0; n < items.length; n++) { | ||||
|                     var q = $(items[n]).data('question'); | ||||
|                     if (q.question.QuestionType === Question.types.FuelRecords | ||||
|                         && (q.question.SubType === Question.fueltypes.Quantity || | ||||
|                             q.question.SubType === Question.fueltypes.UnitCost)) { | ||||
|                         change({ data: q }); | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             ul.append($('<li style="clear: both;"></li>')); | ||||
|             content.tab(); | ||||
|  | ||||
|             _this.loading && _this.loading.fadeOut(100); | ||||
|         }); | ||||
|  | ||||
|         var loading = $('<div id="mask_bg"></div>'); | ||||
|         _this.loading = loading; | ||||
|         content.append(loading); | ||||
|  | ||||
|         return content; | ||||
|     }; | ||||
|  | ||||
|     return { | ||||
|         EditInspection: edit | ||||
|     } | ||||
| }); | ||||
							
								
								
									
										948
									
								
								Site/Inspection/js/modules/inspects/editquestion.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										948
									
								
								Site/Inspection/js/modules/inspects/editquestion.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,948 @@ | ||||
| define([], function () { | ||||
|     var QTypes = { | ||||
|         SingleLineText: 0, | ||||
|         MultipleLineText: 1, | ||||
|         Email: 2, | ||||
|         Number: 3, | ||||
|         Integer: 4, | ||||
|         YesOrNo: 5, | ||||
|         Date: 6, | ||||
|         DateAndTime: 7, | ||||
|         DropDown: 8, | ||||
|         List: 9, | ||||
|         Picture: 10, | ||||
|         Odometer: 11, | ||||
|         EngingHours: 12, | ||||
|         FuelRemaining: 13, | ||||
|         EmailList: 14, | ||||
|         FuelRecords: 15, | ||||
|         BarCode: 16, | ||||
|         BarCodeValidate: 17, | ||||
|         FuelUsed: 18, | ||||
|         AssetStatus: 19 | ||||
|     }; | ||||
|     var LookupSources = { | ||||
|         None: 0, | ||||
|         Jobsites: 1, | ||||
|         Assets: 2, | ||||
|         Employee: 3, | ||||
|         AssetCustomerName: 4 | ||||
|     }; | ||||
|     var FuelRecordTypes = { | ||||
|         TransactionDate: 0, | ||||
|         TicketNumber: 1, | ||||
|         DriverName: 2, | ||||
|         RetailerName: 3, | ||||
|         RetailerAddress: 4, | ||||
|         City: 5, | ||||
|         State: 6, | ||||
|         Zip: 7, | ||||
|         Odometer: 8, | ||||
|         FuelType: 9, | ||||
|         Quantity: 10, | ||||
|         UnitCost: 11, | ||||
|         TotalCost: 12, | ||||
|         BrandName: 13, | ||||
|         Notes: 14, | ||||
|         Picture: 15, | ||||
|         DistributedBy: 16 | ||||
|     }; | ||||
|  | ||||
|     // base question type | ||||
|     var question = function (q) { | ||||
|         this.question = q; | ||||
|         // comment | ||||
|         // content | ||||
|         // unit | ||||
|         this.ui = {}; | ||||
|         // items | ||||
|         this.data = {}; | ||||
|     }; | ||||
|     question.prototype.createContent = function (answer, medias, change) { | ||||
|         this.answer = answer; | ||||
|         var content = $('<div class="question-item" style="line-height: 26px; margin: 0 0 22px 22px"></div>'); | ||||
|         var q = this.question; | ||||
|  | ||||
|         var div_title = $('<div style="font-weight: bold; font-size: 1.1em"></div>').text(q.DisplayText); | ||||
|         if (q.IsRequired) { | ||||
|             div_title.append('<span style="color: red; margin-left: 4px">*</span>'); | ||||
|         } | ||||
|         content.append(div_title); | ||||
|         if (q.StaticPictures && q.StaticPictures.length > 0) { | ||||
|             var div_pic = $('<div></div>'); | ||||
|             for (var i = 0; i < q.StaticPictures.length; i++) { | ||||
|                 var pic = q.StaticPictures[i]; | ||||
|                 var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', pic.Url).attr('title', pic.Name); | ||||
|                 img.click(pic.Url, function (e) { | ||||
|                     window.open(e.data, "_blank") | ||||
|                 }); | ||||
|                 div_pic.append(img); | ||||
|             } | ||||
|             content.append(div_pic); | ||||
|         } | ||||
|  | ||||
|         var cnt = $('<div style="margin: 6px 0 0 22px"></div>'); | ||||
|         if (typeof this.createQuestion === 'function') { | ||||
|             this.ui.content = this.createQuestion(answer, medias, change); | ||||
|             cnt.append(this.ui.content); | ||||
|         } else { | ||||
|             cnt.append('<div style="font-style: italic; color: #ccc"><Not implemented yet.></div>'); | ||||
|         } | ||||
|         var divComment = $('<div style="padding: 6px 0"></div>'); | ||||
|         if (q.CanComment) { | ||||
|             var comment = $('<textarea class="form-control" style="width: 100%; box-sizing: border-box; height: 70px" placeholder="Comment"></textarea>'); | ||||
|             comment.attr('maxlength', 500); | ||||
|             if (answer && answer.Comment) { | ||||
|                 comment.val(answer.Comment); | ||||
|             } | ||||
|             this.ui.comment = comment; | ||||
|             divComment.append(comment); | ||||
|         } | ||||
|         cnt.append(divComment); | ||||
|         content.append(cnt); | ||||
|         return content; | ||||
|     }; | ||||
|     question.prototype.getAnswer = function () { | ||||
|         var answer = this.answer; | ||||
|         if (answer == null) { | ||||
|             answer = { | ||||
|                 'QuestionId': this.question.Id, | ||||
|                 'SeverityLevel': this.question.SeverityLevel | ||||
|             }; | ||||
|             this.answer = answer; | ||||
|         } | ||||
|         if (this.ui.comment != null) { | ||||
|             answer.Comment = this.ui.comment.val(); | ||||
|         } | ||||
|         return answer; | ||||
|     }; | ||||
|     question.prototype.focus = function () { | ||||
|         if (this.ui.comment != null) { | ||||
|             this.ui.comment.focus(); | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     // input type question | ||||
|     var inputQuestion = function (q) { | ||||
|         question.call(this, q); | ||||
|     }; | ||||
|     inputQuestion.prototype = Object.create(question.prototype); | ||||
|     inputQuestion.prototype.constructor = inputQuestion; | ||||
|     inputQuestion.prototype.createQuestion = function (answer, _medias, change) { | ||||
|         var content = $('<div></div>'); | ||||
|         var input; | ||||
|         if (this.question.QuestionType === QTypes.MultipleLineText | ||||
|             || (this.question.QuestionType === QTypes.FuelRecords && | ||||
|                 this.question.SubType === FuelRecordTypes.Notes)) { | ||||
|             input = $('<textarea style="width: 100%; height: 70px"></textarea>'); | ||||
|         } else { | ||||
|             input = $('<input type="text" style="width: 100%; height: 21px"></input>'); | ||||
|         } | ||||
|         if (this.question.QuestionType === QTypes.Email) { | ||||
|             input.attr('placeholder', 'name@example.com; ...'); | ||||
|         } else if (this.question.QuestionType === QTypes.FuelRecords) { | ||||
|             if (this.question.SubType === FuelRecordTypes.TotalCost) { | ||||
|                 input.prop('readonly', true).css('background', '#eee'); | ||||
|             } else if (this.question.SubType === FuelRecordTypes.Quantity | ||||
|                 || this.question.SubType === FuelRecordTypes.UnitCost) { | ||||
|                 if (typeof change === 'function') { | ||||
|                     input.on('input propertychange', this, change); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         if (answer && answer.Result) { | ||||
|             input.val(answer.Result); | ||||
|         } | ||||
|         input.attr('maxlength', 500); | ||||
|         input.css('box-sizing', 'border-box'); | ||||
|         input.addClass('form-control'); | ||||
|         this.ui.input = input; | ||||
|         if (typeof this.createUnit === 'function') { | ||||
|             content.append(this.createUnit(answer)); | ||||
|             content.append($('<div style="margin-right: 110px"></div>').append(input)); | ||||
|         } else { | ||||
|             content.append(input); | ||||
|         } | ||||
|  | ||||
|         if (this.question.QuestionType === QTypes.AssetStatus) { | ||||
|             if (_medias && _medias.length > 0) { | ||||
|                 var div_pic = $('<div></div>'); | ||||
|                 for (var i = 0; i < _medias.length; i++) { | ||||
|                     var pic = _medias[i]; | ||||
|                     var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', pic.Url).attr('title', pic.Name); | ||||
|                     img.click(pic.Url, function (e) { | ||||
|                         window.open(e.data, "_blank") | ||||
|                     }); | ||||
|                     div_pic.append(img); | ||||
|                 } | ||||
|                 content.append(div_pic); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return content; | ||||
|     }; | ||||
|     inputQuestion.prototype.getAnswer = function () { | ||||
|         var answer = question.prototype.getAnswer.call(this); | ||||
|         //if (this.question.QuestionType !== QTypes.FuelRecords || | ||||
|         //    this.question.SubType !== FuelRecordTypes.TotalCost) { | ||||
|         answer.Result = this.ui.input.val(); | ||||
|         //} | ||||
|         return answer; | ||||
|     }; | ||||
|     inputQuestion.prototype.fillResult = function (result) { | ||||
|         if (this.ui.input != null) { | ||||
|             this.ui.input.val(result); | ||||
|         } | ||||
|     }; | ||||
|     inputQuestion.prototype.focus = function () { | ||||
|         this.ui.input.focus(); | ||||
|     }; | ||||
|  | ||||
|     // input with dropdown | ||||
|     var inputDropQuestion = function (q) { | ||||
|         inputQuestion.call(this, q); | ||||
|     }; | ||||
|     inputDropQuestion.prototype = Object.create(inputQuestion.prototype); | ||||
|     inputDropQuestion.prototype.constructor = inputDropQuestion; | ||||
|     inputDropQuestion.prototype.createUnit = function (answer) { | ||||
|         var selector = $('<select style="float: right; width: 100px; height: 21px; margin-top: 2px"></select>'); | ||||
|         var opts; | ||||
|         if (this.question.QuestionType === QTypes.FuelRemaining) { | ||||
|             opts = [{ v: 'percent', t: 'Percent' }]; | ||||
|         } else if (this.question.QuestionType === QTypes.Odometer) { | ||||
|             opts = [ | ||||
|                 { v: 'mile', t: 'Mile(s)' }, | ||||
|                 { v: 'kilometre', t: 'kilometre' } | ||||
|             ]; | ||||
|         } else if (this.question.QuestionType === QTypes.FuelUsed) { | ||||
|             opts = [ | ||||
|                 { v: 'Gallon', t: 'Gallon' }, | ||||
|                 { v: 'Litre', t: 'Litre' } | ||||
|             ]; | ||||
|         } else if (this.question.QuestionType === QTypes.FuelRecords) { | ||||
|             if (this.question.SubType === FuelRecordTypes.Odometer) { | ||||
|                 opts = [ | ||||
|                     { v: 'mile', t: 'Mile(s)' }, | ||||
|                     { v: 'kilometre', t: 'Kilometer' } | ||||
|                 ]; | ||||
|             } else if (this.question.SubType === FuelRecordTypes.Quantity) { | ||||
|                 opts = [ | ||||
|                     { v: 'Gallon', t: 'Gallon' }, | ||||
|                     { v: 'Litre', t: 'Litre' } | ||||
|                 ]; | ||||
|             } | ||||
|         } else { | ||||
|             opts = []; | ||||
|         } | ||||
|         for (var i = 0; i < opts.length; i++) { | ||||
|             var o = opts[i]; | ||||
|             selector.append($('<option></option>').val(o.v).text(o.t)); | ||||
|         } | ||||
|         if (answer && answer.Units) { | ||||
|             selector.val(answer.Units); | ||||
|         } else { | ||||
|             selector.val(opts[0].v); | ||||
|         } | ||||
|         this.ui.unit = selector; | ||||
|         return selector; | ||||
|     }; | ||||
|     inputDropQuestion.prototype.getAnswer = function () { | ||||
|         var answer = inputQuestion.prototype.getAnswer.call(this); | ||||
|         answer.Units = this.ui.unit.val(); | ||||
|         return answer; | ||||
|     }; | ||||
|  | ||||
|     // list question | ||||
|     var listQuestion = function (q) { | ||||
|         question.call(this, q); | ||||
|     }; | ||||
|     listQuestion.prototype = Object.create(question.prototype); | ||||
|     listQuestion.prototype.constructor = listQuestion; | ||||
|     listQuestion.prototype.createQuestion = function (answer) { | ||||
|         var content = $('<div></div>'); | ||||
|         var q = this.question; | ||||
|         for (var i = 0; i < q.SelectItems.length; i++) { | ||||
|             var item = q.SelectItems[i]; | ||||
|             var line = $('<div></div>'); | ||||
|             var check; | ||||
|             var name = 'item_' + q.Id; | ||||
|             var id = name + '_' + i; | ||||
|             var left = $('<div style="float: left"></div>'); | ||||
|             var val = item.Value || item.Text; | ||||
|             if (q.MultipleSelect) { | ||||
|                 check = $('<input type="checkbox"></input>').attr('id', id).val(val); | ||||
|             } else { | ||||
|                 check = $('<input type="radio"></input>').attr({ 'id': id, 'name': name }).val(val); | ||||
|             } | ||||
|             check.data('item', item); | ||||
|             if (answer && answer.SelectedItems) { | ||||
|                 var s = answer.SelectedItems.filter(function (a) { return (a.Value || a.Text) === val }); | ||||
|                 if (s.length > 0) { | ||||
|                     check.prop('checked', true); | ||||
|                 } | ||||
|             } | ||||
|             left.append(check); | ||||
|             var circle = $('<div></div>').css({ | ||||
|                 'width': 12, | ||||
|                 'height': 12, | ||||
|                 'border-radius': 6, | ||||
|                 'display': 'inline-block', | ||||
|                 'margin-left': 5, | ||||
|                 'vertical-align': 'middle' | ||||
|             }); | ||||
|             circle.css('background-color', item.BackgroundColor); | ||||
|             left.append(circle); | ||||
|             line.append(left); | ||||
|             line.append($('<label style="margin-left: 45px; display: block"></label>').attr('for', id).text(item.Text)); | ||||
|  | ||||
|             content.append(line); | ||||
|         } | ||||
|         return content; | ||||
|     }; | ||||
|     listQuestion.prototype.getAnswer = function () { | ||||
|         var answer = question.prototype.getAnswer.call(this); | ||||
|         var checks = this.ui.content.find('input:checked'); | ||||
|         var items = []; | ||||
|         for (var i = 0; i < checks.length; i++) { | ||||
|             var item = $(checks[i]).data('item'); | ||||
|             items.push(item); | ||||
|         } | ||||
|         answer.SelectedItems = items; | ||||
|         if (items.length > 0) { | ||||
|             answer.Result = items.map(function (i) { return i.Value || i.Text }).join('\n'); | ||||
|             //answer.SeverityLevel = items[0].SeverityLevel; | ||||
|         } else { | ||||
|             answer.Result = ''; | ||||
|         } | ||||
|         return answer; | ||||
|     }; | ||||
|     listQuestion.prototype.focus = function () { | ||||
|         var ele = this.ui.content.find('input:first'); | ||||
|         if (ele.length > 0) { | ||||
|             ele.focus(); | ||||
|         } else { | ||||
|             question.prototype.focus.call(this); | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     // date&time question | ||||
|     var dateTimeQuestion = function (q) { | ||||
|         question.call(this, q); | ||||
|     }; | ||||
|     dateTimeQuestion.prototype = Object.create(question.prototype); | ||||
|     dateTimeQuestion.prototype.constructor = dateTimeQuestion; | ||||
|     dateTimeQuestion.prototype.createQuestion = function (answer) { | ||||
|         var content = $('<div></div>'); | ||||
|         var q = this.question; | ||||
|         var result; | ||||
|         if (answer && answer.Result) { | ||||
|             result = answer.Result.split(' '); | ||||
|         } | ||||
|         var date = $('<input type="text" style="width: 100px; height: 21px"></input>'); | ||||
|         date.css('box-sizing', 'border-box'); | ||||
|         date.addClass('form-control'); | ||||
|         if (result) { | ||||
|             date.val(result[0]); | ||||
|         } | ||||
|         this.ui.date = date; | ||||
|         content.append(date); | ||||
|         date.datetimepicker({ | ||||
|             timepicker: false, | ||||
|             format: 'Y-m-d', | ||||
|             enterLikeTab: false, | ||||
|             //onSelectDate: function (v, inp) { | ||||
|  | ||||
|             //} | ||||
|         }); | ||||
|         if (q.QuestionType === QTypes.DateAndTime | ||||
|             || (q.QuestionType === QTypes.FuelRecords && | ||||
|                 q.SubType === FuelRecordTypes.TransactionDate)) { | ||||
|             var time = $('<input type="text" style="width: 100px; margin-left: 10px; height: 21px"></input>'); | ||||
|             time.css('box-sizing', 'border-box'); | ||||
|             time.addClass('form-control'); | ||||
|             if (result) { | ||||
|                 time.val(result[1]); | ||||
|             } | ||||
|             this.ui.time = time; | ||||
|             content.append(time); | ||||
|             //time.blur(function () { | ||||
|             //    var dt = new Date('1970-01-01T' + $(this).val()); | ||||
|             //    if (isNaN(dt.getDate())) { | ||||
|             //        $(this).css('border-color', 'red'); | ||||
|             //    } else { | ||||
|             //        $(this).css('border-color', ''); | ||||
|             //    } | ||||
|             //}); | ||||
|             //time.datetimepicker({ | ||||
|             //    datepicker: false, | ||||
|             //    format: 'H:m:s', | ||||
|             //    enterLikeTab: false | ||||
|             //}); | ||||
|         } | ||||
|         return content; | ||||
|     }; | ||||
|     dateTimeQuestion.prototype.getAnswer = function () { | ||||
|         var answer = question.prototype.getAnswer.call(this); | ||||
|         var date = this.ui.date.val(); | ||||
|         if (this.ui.time != null) { | ||||
|             date += ' ' + this.ui.time.val(); | ||||
|         } | ||||
|         if (date != ' ') { | ||||
|             answer.Result = date; | ||||
|         } | ||||
|         return answer; | ||||
|     }; | ||||
|     dateTimeQuestion.prototype.focus = function () { | ||||
|         if (this.ui.time != null) { | ||||
|             this.ui.time.focus(); | ||||
|         } else { | ||||
|             this.ui.date.focus(); | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     // drop question | ||||
|     var dropQuestion = function (q) { | ||||
|         question.call(this, q); | ||||
|     }; | ||||
|     dropQuestion.prototype = Object.create(question.prototype); | ||||
|     dropQuestion.prototype.constructor = dropQuestion; | ||||
|     dropQuestion.prototype.createQuestion = function (answer) { | ||||
|         var _this = this; | ||||
|         var content = $('<div></div>').click(function () { _this.openDrop(content.offset()) }); | ||||
|         var result = $('<div class="drop-result" style="float: left; cursor: pointer"></div>'); | ||||
|         this.fillResult(result, answer && answer.SelectedItems); | ||||
|         content.append(result); | ||||
|         var icon = $('<div class="icon-col iconcaretdown" style="float: left; margin-left: 10px; font-weight: bold"></div>'); | ||||
|         content.append(icon); | ||||
|         if (!this.loaded && ( | ||||
|             this.question.LookupSource === LookupSources.Assets || | ||||
|             this.question.LookupSource === LookupSources.AssetCustomerName)) { | ||||
|             var loading = $('<div class="loading c-spin" style="float: left; margin-left: 10px; color: gray"></div>'); | ||||
|             content.append(loading); | ||||
|         } | ||||
|         content.append('<div style="clear: both"></div>'); | ||||
|         return content; | ||||
|     }; | ||||
|     dropQuestion.prototype.setLoaded = function () { | ||||
|         this.loaded = true; | ||||
|         this.ui.content && this.ui.content.find('.loading').remove(); | ||||
|     }; | ||||
|     dropQuestion.prototype.focus = function () { | ||||
|         var ele = this.ui.content.find('input:first'); | ||||
|         if (ele.length > 0) { | ||||
|             ele.focus(); | ||||
|         } else { | ||||
|             question.prototype.focus.call(this); | ||||
|         } | ||||
|     }; | ||||
|     dropQuestion.prototype.fillResult = function (container, items) { | ||||
|         container.empty(); | ||||
|         if (items && items.length > 0) { | ||||
|             for (var i = 0; i < items.length; i++) { | ||||
|                 var item = items[i]; | ||||
|                 var line = $('<div></div>'); | ||||
|                 line.append($('<input type="hidden"></input>').data('item', item).val(item.Value || item.Text)); | ||||
|                 var circle = $('<div></div>').css({ | ||||
|                     'width': 12, | ||||
|                     'height': 12, | ||||
|                     'border-radius': 6, | ||||
|                     'display': 'inline-block', | ||||
|                     'margin-left': 5, | ||||
|                     'vertical-align': 'middle' | ||||
|                 }); | ||||
|                 circle.css('background-color', item.BackgroundColor || '#ccc'); | ||||
|                 line.append(circle); | ||||
|                 var text; | ||||
|                 if (this.question.QuestionType === QTypes.EmailList) { | ||||
|                     text = item.Text + ' <' + item.Value + '>'; | ||||
|                 } else { | ||||
|                     text = item.Text; | ||||
|                 } | ||||
|                 line.append($('<span style="margin-left: 10px"></span>').text(text)); | ||||
|                 container.append(line); | ||||
|             } | ||||
|         } else { | ||||
|             if (this.question.QuestionType === QTypes.EmailList) { | ||||
|                 container.append($('<span style="color: #ccc">No Emails Selected</span>')); | ||||
|             } else { | ||||
|                 container.append($('<span style="color: #ccc">No Selection</span>')); | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
|     dropQuestion.prototype.openDrop = function (pos) { | ||||
|         var _this = this; | ||||
|         var q = this.question; | ||||
|         var mask = this.ui.mask; | ||||
|         if (mask == null) { | ||||
|             mask = $('<div style="position:fixed; left:0;right:0;top:0;bottom:0"></div>'); | ||||
|             this.ui.mask = mask; | ||||
|         } | ||||
|         mask.on('mousedown touchstart', function () { | ||||
|             if (panel.is(":visible")) { | ||||
|                 panel.find(".iconcheck").click(); | ||||
|             } | ||||
|             //_this.closeDrop() | ||||
|         }); | ||||
|         $(document.body).append(mask); | ||||
|  | ||||
|         // drop panel | ||||
|         var panel = this.ui.droplist; | ||||
|         if (panel != null) { | ||||
|             panel.remove(); | ||||
|         } | ||||
|         panel = $('<div style="position:absolute;background:white;width:400px;height:300px;border:1px solid #ccc;box-shadow:3px 3px 10px #eee"></div>'); | ||||
|         var answer = this.answer; | ||||
|         var isEmailList = q.QuestionType === QTypes.EmailList; | ||||
|         var isEmployee = q.QuestionType === QTypes.DropDown && q.LookupSource === LookupSources.Employee; | ||||
|         var refreshList = function (content, items) { | ||||
|             content.find('.drop-item').remove(); | ||||
|             for (var i = 0; i < items.length; i++) { | ||||
|                 var item = items[i]; | ||||
|                 var line = $('<div class="drop-item"></div>'); | ||||
|                 var check; | ||||
|                 var name = 'item_' + q.Id; | ||||
|                 var id = name + '_' + i; | ||||
|                 var left = $('<div style="float: left"></div>'); | ||||
|                 var val = item.Value || item.Text; | ||||
|                 if (isEmailList || q.MultipleSelect) { | ||||
|                     check = $('<input type="checkbox"></input>').attr('id', id).val(val); | ||||
|                 } else { | ||||
|                     check = $('<input type="radio"></input>').attr({ 'id': id, 'name': name }).val(val); | ||||
|                 } | ||||
|                 check.data('item', item); | ||||
|                 check.change(function () { | ||||
|                     if (!q.MultipleSelect && q.QuestionType !== QTypes.EmailList) { | ||||
|                         for (var i = 0; i < _this.data.items.length; i++) { | ||||
|                             _this.data.items[i].Selected = false; | ||||
|                         } | ||||
|                     } | ||||
|                     $(this).data('item').Selected = $(this).prop('checked'); | ||||
|                 }); | ||||
|                 if (answer && answer.SelectedItems) { | ||||
|                     var s = answer.SelectedItems.filter(function (a) { return (a.Value || a.Text) === val }); | ||||
|                     if (s.length > 0) { | ||||
|                         check.prop('checked', true); | ||||
|                         item.Selected = true; | ||||
|                     } | ||||
|                 } | ||||
|                 left.append(check); | ||||
|                 var circle = $('<div></div>').css({ | ||||
|                     'width': 12, | ||||
|                     'height': 12, | ||||
|                     'border-radius': 6, | ||||
|                     'display': 'inline-block', | ||||
|                     'margin-left': 5, | ||||
|                     'vertical-align': 'middle' | ||||
|                 }); | ||||
|                 circle.css('background-color', item.BackgroundColor); | ||||
|                 left.append(circle); | ||||
|                 line.append(left); | ||||
|                 line.append($('<label style="margin-left: 45px; display: block"></label>').attr('for', id).text( | ||||
|                     isEmailList ? item.Text + ' <' + item.Value + '>' : item.Text)); | ||||
|  | ||||
|                 content.append(line); | ||||
|             } | ||||
|         }; | ||||
|         var search = $('<input type="text" placeholder="Search"></input>').css({ | ||||
|             'height': 29, | ||||
|             'line-height': '29px', | ||||
|             'padding': '0 6px', | ||||
|             'width': '100%', | ||||
|             'border': 'none', | ||||
|             'border-bottom': '1px solid #ccc', | ||||
|             'box-sizing': 'border-box' | ||||
|         }).on('propertychange input', function () { | ||||
|             var items = _this.data.items; | ||||
|             var key = $(this).val().toLowerCase(); | ||||
|             if (items && items.length > 0) { | ||||
|                 items = items.filter(function (e) { return e.Text.toLowerCase().indexOf(key) >= 0 }); | ||||
|                 refreshList(panelContent, items); | ||||
|             } | ||||
|         }); | ||||
|         var funcs = $('<div style="margin-right: 45px"></div>'); | ||||
|         funcs.append(search); | ||||
|         panel.append($('<div class="sbutton iconcheck"></div>').css({ | ||||
|             'float': 'right', | ||||
|             'padding': '0 10px', | ||||
|             'height': 29, | ||||
|             'line-height': '29px' | ||||
|         }).click(function () { | ||||
|             var checks = _this.data.items; // panelContent.find('input:checked'); | ||||
|             var items = []; | ||||
|             for (var i = 0; i < checks.length; i++) { | ||||
|                 var item = checks[i]; // $(checks[i]).data('item'); | ||||
|                 if (item.Selected) { | ||||
|                     items.push(item); | ||||
|                 } | ||||
|             } | ||||
|             if (answer == null) { | ||||
|                 answer = { | ||||
|                     'QuestionId': q.Id, | ||||
|                     'SeverityLevel': q.SeverityLevel | ||||
|                 }; | ||||
|                 _this.answer = answer; | ||||
|             } | ||||
|             answer.SelectedItems = items; | ||||
|             _this.fillResult(_this.ui.content.find('.drop-result'), items); | ||||
|             _this.closeDrop(); | ||||
|         })); | ||||
|         panel.append(funcs); | ||||
|         // scroller | ||||
|         var panelContent = $('<div></div>').css({ | ||||
|             'overflow-y': 'auto', | ||||
|             'line-height': '26px', | ||||
|             'box-sizing': 'border-box', | ||||
|             'height': 270, | ||||
|             'padding': '4px 2px' | ||||
|         }); | ||||
|         panel.append(panelContent); | ||||
|         this.ui.panelContent = panelContent; | ||||
|         var generateItem = function (text, value) { | ||||
|             return { | ||||
|                 'BackgroundColor': '#cccccc', | ||||
|                 'SeverityLevel': q.SeverityLevel, | ||||
|                 'Text': text, | ||||
|                 'Value': value | ||||
|             }; | ||||
|         }; | ||||
|         var items; | ||||
|         if (q.SelectItems && q.SelectItems.length > 0) { | ||||
|             items = q.SelectItems; | ||||
|         } else if (isEmailList || isEmployee) { | ||||
|             if (window.EmailList) { | ||||
|                 items = []; | ||||
|                 for (var i = 0; i < window.EmailList.length; i++) { | ||||
|                     var item = window.EmailList[i]; | ||||
|                     items.push(generateItem( | ||||
|                         isEmployee ? (item.UserName + ' <' + item.Email + '>') : item.UserName, | ||||
|                         isEmailList ? item.Email : item.UserIID)); | ||||
|                 } | ||||
|             } | ||||
|         } else if (q.LookupSource === LookupSources.Jobsites) { | ||||
|             if (window.JobSiteList) { | ||||
|                 items = []; | ||||
|                 for (var i = 0; i < window.JobSiteList.length; i++) { | ||||
|                     var item = window.JobSiteList[i]; | ||||
|                     items.push(generateItem(item.Name, String(item.Id))); | ||||
|                 } | ||||
|             } | ||||
|         } else if (q.LookupSource === LookupSources.Assets) { | ||||
|             if (window.AssetList) { | ||||
|                 items = []; | ||||
|                 for (var i = 0; i < window.AssetList.length; i++) { | ||||
|                     var item = window.AssetList[i]; | ||||
|                     var assetLabel = [item.Name, item.VIN, item.Make, item.Model, item.AssetType].filter(function (a) { return a && a.length > 0 }).join('/'); | ||||
|                     items.push(generateItem(assetLabel, String(item.Id))); | ||||
|                 } | ||||
|             } | ||||
|         } else if (q.LookupSource === LookupSources.AssetCustomerName) { | ||||
|             if (window.AssetList) { | ||||
|                 items = []; | ||||
|                 for (var i = 0; i < window.AssetList.length; i++) { | ||||
|                     var item = window.AssetList[i]; | ||||
|                     var assetLabel = item.Name; | ||||
|                     items.push(generateItem(assetLabel, String(item.Id))); | ||||
|                 } | ||||
|             } | ||||
|         } else if (q.QuestionType === QTypes.FuelRecords) { | ||||
|             if (q.SubType === FuelRecordTypes.State) { | ||||
|                 items = [ | ||||
|                     "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" | ||||
|                 ].map(function (s) { return generateItem(s, s) }); | ||||
|             } else if (q.SubType === FuelRecordTypes.FuelType) { | ||||
|                 items = [ | ||||
|                     { value: "BIOD", text: "B20 Diesel 20% Biodiesel" }, | ||||
|                     { value: "DEF", text: "Diesel Exhaust Fluid" }, | ||||
|                     { value: "DS+", text: "Premium Diesel #2" }, | ||||
|                     { value: "DSL", text: "Diesel #1" }, | ||||
|                     { value: "DSL2", text: "Regular Diesel #2" }, | ||||
|                     { value: "ETH-S", text: "Super Unleaded Ethanol (10% blend)" }, | ||||
|                     { value: "ETH", text: "Unleaded Ethanol (10% blend)" }, | ||||
|                     { value: "FRM", text: "Diesel Off Road (#1 and #2 non" }, | ||||
|                     { value: "FUL", text: "Miscellaneous Fuel" }, | ||||
|                     { value: "FUL-", text: "Other Fuel (Non-Taxable)" }, | ||||
|                     { value: "KERO", text: "Kerosene - Low Sulfur" }, | ||||
|                     { value: "MOT", text: "Motor Oil" }, | ||||
|                     { value: "OTH", text: "General Merchandise" }, | ||||
|                     { value: "SUP4", text: "Unleaded 4" }, | ||||
|                     { value: "SUP", text: "Unleaded Super" }, | ||||
|                     { value: "SVC", text: "Repairs" }, | ||||
|                     { value: "ULSD", text: "Ultra Low Sulfur #2" }, | ||||
|                     { value: "UN+", text: "Unleaded Plus" }, | ||||
|                     { value: "UNL", text: "Unleaded Regular" }, | ||||
|                     { value: "WASH", text: "Car Wash" }, | ||||
|                     { value: "HYD", text: "Hydraulic" }, | ||||
|                     { value: "SHY", text: "Synthetic Hydraulic" }, | ||||
|                     { value: "GRO", text: "Gear Oil" } | ||||
|                 ].map(function (t) { return generateItem(t.text, t.value) }); | ||||
|             } else if (q.SubType === FuelRecordTypes.DistributedBy) { | ||||
|                 items = [ | ||||
|                     { value: "0", text: "Fueling Station" }, | ||||
|                     { value: "1", text: "Fueling Asset" } | ||||
|                 ].map(function (t) { return generateItem(t.text, t.value) }); | ||||
|             } | ||||
|         } | ||||
|         if (items && items.length > 0) { | ||||
|             this.data.items = items; | ||||
|             refreshList(panelContent, items); | ||||
|         } | ||||
|         this.ui.droplist = panel; | ||||
|  | ||||
|         var screenHeight = $(window).height(); | ||||
|         if (pos.top + 300 > screenHeight) { | ||||
|             pos.top = screenHeight - 310; | ||||
|         } | ||||
|         panel.css({ 'left': pos.left, 'top': pos.top }); | ||||
|         $(document.body).append(panel); | ||||
|     }; | ||||
|     dropQuestion.prototype.closeDrop = function () { | ||||
|         this.ui.mask.remove(); | ||||
|         this.ui.mask = null; | ||||
|         this.ui.droplist.remove(); | ||||
|     }; | ||||
|     dropQuestion.prototype.getAnswer = function () { | ||||
|         var answer = question.prototype.getAnswer.call(this); | ||||
|         var checks = this.ui.content.children('.drop-result').find('input'); | ||||
|         var items = []; | ||||
|         for (var i = 0; i < checks.length; i++) { | ||||
|             var item = $(checks[i]).data('item'); | ||||
|             items.push(item); | ||||
|         } | ||||
|         answer.SelectedItems = items; | ||||
|         if (items.length > 0) { | ||||
|             answer.Result = items.map(function (i) { return i.Value || i.Text }).join('\n'); | ||||
|             //answer.SeverityLevel = items[0].SeverityLevel; | ||||
|         } else { | ||||
|             answer.Result = ''; | ||||
|         } | ||||
|         return answer; | ||||
|     }; | ||||
|  | ||||
|     // picture question | ||||
|     var pictureQuestion = function (q) { | ||||
|         question.call(this, q); | ||||
|     }; | ||||
|     pictureQuestion.prototype = Object.create(question.prototype); | ||||
|     pictureQuestion.prototype.constructor = pictureQuestion; | ||||
|     pictureQuestion.prototype.createQuestion = function (_answer, medias) { | ||||
|         var content = $('<div></div>'); | ||||
|         if (medias && medias.length > 0) { | ||||
|             for (var i = 0; i < medias.length; i++) { | ||||
|                 var m = medias[i]; | ||||
|                 var ele; | ||||
|                 if (['.mp4', '.mov'].indexOf(m.FileType.toLowerCase()) >= 0) { | ||||
|                     ele = $('<div></div>').css({ | ||||
|                         'float': 'left', | ||||
|                         'border': '1px solid #ccc', | ||||
|                         'height': 38, | ||||
|                         'width': 38, | ||||
|                         'text-align': 'center' | ||||
|                     }); | ||||
|                     ele.append($('<span></span>').css({ | ||||
|                         'margin': '0 auto', | ||||
|                         'font-family': 'Fontawesome', | ||||
|                         'font-size': '20px', | ||||
|                         'line-height': '38px', | ||||
|                         'color': '#000' | ||||
|                     })); | ||||
|                 } else { | ||||
|                     ele = $('<img></img>').css({ | ||||
|                         'float': 'left', | ||||
|                         'border': '1px solid #ccc', | ||||
|                         'padding': '4px', | ||||
|                         'height': 30, | ||||
|                         'margin-right': 4 | ||||
|                     }).attr('src', m.ThumbnailUrl); | ||||
|                 } | ||||
|                 content.append($('<a target="_blank"></a>').attr('href', m.Url).append(ele)); | ||||
|             } | ||||
|         } else { | ||||
|             content.append('<div style="font-style: italic; color: #ccc"><No media.></div>'); | ||||
|         } | ||||
|         content.append('<div style="clear: both"></div>'); | ||||
|         return content; | ||||
|     }; | ||||
|  | ||||
|  | ||||
|     // assetstatus question | ||||
|     var assetStatusQuestion = function (q) { | ||||
|         question.call(this, q); | ||||
|     }; | ||||
|     assetStatusQuestion.prototype = Object.create(question.prototype); | ||||
|     assetStatusQuestion.prototype.constructor = assetStatusQuestion; | ||||
|     assetStatusQuestion.prototype.createQuestion = function (answer, medias) { | ||||
|         var content = $('<div></div>'); | ||||
|         var q = this.question; | ||||
|         q.SelectItems = [ | ||||
|             { Value: "0", Text: "In Use", BackgroundColor: "#93c47d" }, | ||||
|             { Value: "1", Text: "Available", BackgroundColor: "#9fc5e8" }, | ||||
|             { Value: "2", Text: "Standby", BackgroundColor: "#f3af83" }, | ||||
|             { Value: "10", Text: "Down", BackgroundColor: "#dd7e6b" } | ||||
|         ]; | ||||
|         for (var i = 0; i < q.SelectItems.length; i++) { | ||||
|             var item = q.SelectItems[i]; | ||||
|             var line = $('<div></div>'); | ||||
|             var name = 'item_' + q.Id; | ||||
|             var id = name + '_' + i; | ||||
|             var left = $('<div style="float: left"></div>'); | ||||
|             var val = item.Value || item.Text; | ||||
|             var check = $('<input type="radio"></input>').attr({ 'id': id, 'name': name }).val(val); | ||||
|             check.data('item', item); | ||||
|             if (answer && answer.SelectedItems) { | ||||
|                 var s = answer.SelectedItems.filter(function (a) { return (a.Value || a.Text) === val }); | ||||
|                 if (s.length > 0) { | ||||
|                     check.prop('checked', true); | ||||
|                 } | ||||
|             } | ||||
|             left.append(check); | ||||
|             var circle = $('<div></div>').css({ | ||||
|                 'width': 12, | ||||
|                 'height': 12, | ||||
|                 'border-radius': 6, | ||||
|                 'display': 'inline-block', | ||||
|                 'margin-left': 5, | ||||
|                 'vertical-align': 'middle' | ||||
|             }); | ||||
|             circle.css('background-color', item.BackgroundColor); | ||||
|             left.append(circle); | ||||
|             line.append(left); | ||||
|             line.append($('<label style="margin-left: 45px; display: block"></label>').attr('for', id).text(item.Text)); | ||||
|  | ||||
|             content.append(line); | ||||
|             content.append('<div style="clear: both"></div>'); | ||||
|         } | ||||
|  | ||||
|         if (medias && medias.length > 0) { | ||||
|             var cnt = $('<div style="margin: 6px 0 0 0px"></div>'); | ||||
|             for (var i = 0; i < medias.length; i++) { | ||||
|                 var m = medias[i]; | ||||
|                 var ele; | ||||
|                 if (['.mp4', '.mov'].indexOf(m.FileType.toLowerCase()) >= 0) { | ||||
|                     ele = $('<div></div>').css({ | ||||
|                         'float': 'left', | ||||
|                         'border': '1px solid #ccc', | ||||
|                         'height': 38, | ||||
|                         'width': 38, | ||||
|                         'text-align': 'center' | ||||
|                     }); | ||||
|                     ele.append($('<span></span>').css({ | ||||
|                         'margin': '0 auto', | ||||
|                         'font-family': 'Fontawesome', | ||||
|                         'font-size': '20px', | ||||
|                         'line-height': '38px', | ||||
|                         'color': '#000' | ||||
|                     })); | ||||
|                 } else { | ||||
|                     ele = $('<img></img>').css({ | ||||
|                         'float': 'left', | ||||
|                         'border': '1px solid #ccc', | ||||
|                         'padding': '4px', | ||||
|                         'height': 30, | ||||
|                         'margin-right': 4 | ||||
|                     }).attr('src', m.ThumbnailUrl); | ||||
|                 } | ||||
|                 cnt.append($('<a target="_blank"></a>').attr('href', m.Url).append(ele)); | ||||
|             } | ||||
|             content.append(cnt); | ||||
|         } | ||||
|         content.append('<div style="clear: both"></div>'); | ||||
|  | ||||
|         cnt = $('<div style="margin: 6px 0 0 0px"></div>'); | ||||
|         var divComment = $('<div style="padding: 6px 0"></div>'); | ||||
|         var comment = $('<textarea class="form-control" style="width: 100%; box-sizing: border-box; height: 70px" placeholder="Comment"></textarea>'); | ||||
|         comment.attr('maxlength', 500); | ||||
|         if (answer && answer.Result) { | ||||
|             comment.val(answer.Result); | ||||
|         } | ||||
|         this.ui.comment = comment; | ||||
|         divComment.append(comment); | ||||
|         cnt.append(divComment); | ||||
|         content.append(cnt); | ||||
|  | ||||
|         return content; | ||||
|     }; | ||||
|     assetStatusQuestion.prototype.getAnswer = function () { | ||||
|         var answer = question.prototype.getAnswer.call(this); | ||||
|         var checks = this.ui.content.find('input:checked'); | ||||
|         var items = []; | ||||
|         for (var i = 0; i < checks.length; i++) { | ||||
|             var item = $(checks[i]).data('item'); | ||||
|             items.push(item); | ||||
|         } | ||||
|         answer.SelectedItems = items; | ||||
|         if (items.length > 0) { | ||||
|             answer.Result = items.map(function (i) { return i.Value || i.Text }).join('\n'); | ||||
|             //answer.SeverityLevel = items[0].SeverityLevel; | ||||
|         } else { | ||||
|             answer.Result = ''; | ||||
|         } | ||||
|         return answer; | ||||
|     }; | ||||
|     assetStatusQuestion.prototype.focus = function () { | ||||
|         var ele = this.ui.content.find('input:first'); | ||||
|         if (ele.length > 0) { | ||||
|             ele.focus(); | ||||
|         } else { | ||||
|             question.prototype.focus.call(this); | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|  | ||||
|     return { | ||||
|         types: QTypes, | ||||
|         sources: LookupSources, | ||||
|         fueltypes: FuelRecordTypes, | ||||
|         factory: function (q) { | ||||
|             switch (q.QuestionType) { | ||||
|                 case QTypes.Odometer: | ||||
|                 case QTypes.FuelRemaining: | ||||
|                 case QTypes.FuelUsed: | ||||
|                     return new inputDropQuestion(q); | ||||
|                 case QTypes.YesOrNo: | ||||
|                 case QTypes.List: | ||||
|                     return new listQuestion(q); | ||||
|                 case QTypes.DropDown: | ||||
|                 case QTypes.EmailList: | ||||
|                     return new dropQuestion(q); | ||||
|                 case QTypes.Date: | ||||
|                 case QTypes.DateAndTime: | ||||
|                     return new dateTimeQuestion(q); | ||||
|                 case QTypes.Picture: | ||||
|                     return new pictureQuestion(q); | ||||
|                 case QTypes.FuelRecords: | ||||
|                     switch (q.SubType) { | ||||
|                         case FuelRecordTypes.TransactionDate: | ||||
|                             return new dateTimeQuestion(q); | ||||
|                         case FuelRecordTypes.State: | ||||
|                         case FuelRecordTypes.FuelType: | ||||
|                         case FuelRecordTypes.DistributedBy: | ||||
|                             return new dropQuestion(q); | ||||
|                         case FuelRecordTypes.Odometer: | ||||
|                         case FuelRecordTypes.Quantity: | ||||
|                             return new inputDropQuestion(q); | ||||
|                         case FuelRecordTypes.Picture: | ||||
|                             return new pictureQuestion(q); | ||||
|                         default: | ||||
|                             return new inputQuestion(q); | ||||
|                     } | ||||
|                     break; | ||||
|                 case QTypes.AssetStatus: | ||||
|                     return new assetStatusQuestion(q); | ||||
|                 default: | ||||
|                     return new inputQuestion(q); | ||||
|             } | ||||
|         }, | ||||
|         equals: function (s1, s2) { | ||||
|             if (typeof s1 === 'string' && typeof s2 === 'string') { | ||||
|                 if (s1.toLowerCase() === s2.toLowerCase()) { | ||||
|                     return true; | ||||
|                 } | ||||
|             } | ||||
|             return false; | ||||
|         } | ||||
|     } | ||||
| }); | ||||
							
								
								
									
										66
									
								
								Site/Inspection/js/modules/inspects/editsection.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								Site/Inspection/js/modules/inspects/editsection.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| define(['modules/inspects/editquestion'], function (Question) { | ||||
|     var ctor = function (section, report) { | ||||
|         this.section = section; | ||||
|         this.report = report; | ||||
|     }; | ||||
|  | ||||
|     var __proto = ctor.prototype; | ||||
|     __proto.createContent = function (change) { | ||||
|         var content = $('<div style="margin-bottom: 20px"></div>'); | ||||
|  | ||||
|         if (this.section.StaticPictures && this.section.StaticPictures.length > 0) { | ||||
|             var div_pic = $('<div style="background: #eee; padding: 2px 2px;"></div>'); | ||||
|             for (var i = 0; i < this.section.StaticPictures.length; i++) { | ||||
|                 var pic = this.section.StaticPictures[i]; | ||||
|                 var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', pic.Url).attr('title', pic.Name); | ||||
|                 img.click(pic.Url, function (e) { | ||||
|                     window.open(e.data, "_blank") | ||||
|                 }); | ||||
|                 div_pic.append(img); | ||||
|             } | ||||
|             content.append(div_pic); | ||||
|         } | ||||
|  | ||||
|         var div_title = $('<div style="background: #eee; padding: 5px 3px; margin: 5px 0; font-size: 1.4em"></div>').text(this.section.DisplayText); | ||||
|         content.append(div_title); | ||||
|  | ||||
|         for (var i = 0; i < this.section.Questions.length; i++) { | ||||
|             var question = this.section.Questions[i]; | ||||
|  | ||||
|             if (question.QuestionType === Question.types.YesOrNo || | ||||
|                 question.QuestionType === Question.types.DropDown || | ||||
|                 question.QuestionType === Question.types.List) { | ||||
|                 if (!question.SelectItems || question.SelectItems.length <= 0) { | ||||
|                     if (question.QuestionType !== Question.types.DropDown || | ||||
|                         question.LookupSource === 0) { | ||||
|                         continue; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             var q = Question.factory(question); | ||||
|             // get answer and media | ||||
|             var answer = this.report.Answers.filter(function (a) { return Question.equals(a.QuestionId, question.Id) })[0]; | ||||
|             var isPicture = question.QuestionType === Question.types.Picture | ||||
|                 || (question.QuestionType === Question.types.FuelRecords && | ||||
|                     question.SubType === Question.fueltypes.Picture) | ||||
|                 || question.QuestionType === Question.types.AssetStatus; | ||||
|             var medias = isPicture && answer && this.report.Medias.filter(function (m) { return Question.equals(m.AnswerId, answer.Id) }); | ||||
|  | ||||
|             var qContent; | ||||
|             if (question.QuestionType === Question.types.FuelRecords | ||||
|                 && (question.SubType === Question.fueltypes.Quantity || | ||||
|                     question.SubType === Question.fueltypes.UnitCost)) { | ||||
|                 qContent = q.createContent(answer, medias, change); | ||||
|             } else { | ||||
|                 qContent = q.createContent(answer, medias); | ||||
|             } | ||||
|             qContent.data('question', q); | ||||
|             content.append(qContent); | ||||
|         } | ||||
|  | ||||
|         return content; | ||||
|     }; | ||||
|  | ||||
|     return ctor; | ||||
| }); | ||||
							
								
								
									
										55
									
								
								Site/Inspection/js/modules/inspects/inspect.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								Site/Inspection/js/modules/inspects/inspect.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| define(['modules/templates/addtemplate'], function (AddTemplate) { | ||||
|     var q = function (ipt, inspect) { | ||||
|         this.inspect = inspect; | ||||
|         this.inspectmodule = ipt; | ||||
|     }; | ||||
|     q.prototype.description = "Inspect"; | ||||
|     q.prototype.version = "1.0.0.0"; | ||||
|  | ||||
|     q.prototype.createContent = function () { | ||||
|         var holder = $('<div class="question-holder"></div>'); | ||||
|         holder.append('<div class="question-cell inspect-templatename" style="width:150px;margin-left:8px;"><span></span></div>'); | ||||
|         holder.append('<div class="question-cell inspect-assetname" style="width:200px;"><span></span></div>'); | ||||
|         holder.append('<div class="question-cell inspect-vin" style="width:200px;"><span></span></div>'); | ||||
|         holder.append('<div class="question-cell inspect-make" style="width:150px;"><span></span></div>'); | ||||
|         holder.append('<div class="question-cell inspect-model" style="width:150px;"><span></span></div>'); | ||||
|         holder.append('<div class="question-cell inspect-type" style="width:150px;"><span></span></div>'); | ||||
|         holder.append('<div class="question-cell inspect-status" style="width:120px;"><span></span></div>'); | ||||
|         holder.append('<div class="question-cell inspect-committime" style="width:150px;"><span></span></div>'); | ||||
|         holder.append('<div class="question-cell inspect-commituser" style="width:150px;"><span></span></div>'); | ||||
|         var funcs = $('<div class="question-cell inspect-func" style="width:92px;text-align:right;padding-right:20px;"></div>'); | ||||
|         holder.append(funcs); | ||||
|         var _this = this; | ||||
|         holder.find('.inspect-assetname span').click(function () { | ||||
|             window.open("report.aspx?rid=" + _this.inspect.Id, "_blank"); | ||||
|         }); | ||||
|         funcs.append($('<em class="spanbtn icondetail"></em>').click(function () { | ||||
|             window.open("report.aspx?rid=" + _this.inspect.Id, "_blank"); | ||||
|         }).attr('title', 'Detail')); | ||||
|         this.holder = holder; | ||||
|         if (this.inspect != null) { | ||||
|             this.updateContent(this.inspect); | ||||
|         } | ||||
|         return holder; | ||||
|     }; | ||||
|     q.prototype.updateContent = function (inspect) { | ||||
|         if (this.inspect != inspect) { | ||||
|             this.inspect = inspect; | ||||
|         } | ||||
|         this.holder.find('.inspect-assetname span').text(inspect.AssetName); | ||||
|         this.holder.find('.inspect-vin span').text(inspect.VIN); | ||||
|         this.holder.find('.inspect-make span').text(inspect.MakeName); | ||||
|         this.holder.find('.inspect-model span').text(inspect.ModelName); | ||||
|         this.holder.find('.inspect-type span').text(inspect.TypeName); | ||||
|         this.holder.find('.inspect-templatename span').text(inspect.TemplateName); | ||||
|         var statustext = ''; | ||||
|         if (inspect.Status == 0) | ||||
|             statustext = 'Draft'; | ||||
|         else if (inspect.Status == 1) | ||||
|             statustext = 'Committed'; | ||||
|         this.holder.find('.inspect-status span').text(statustext); | ||||
|         this.holder.find('.inspect-committime span').text(inspect.CommitTimeLocalStr); | ||||
|         this.holder.find('.inspect-commituser span').text(inspect.CommitedByUserName); | ||||
|     }; | ||||
|     return q; | ||||
| }); | ||||
							
								
								
									
										513
									
								
								Site/Inspection/js/modules/layouts.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										513
									
								
								Site/Inspection/js/modules/layouts.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,513 @@ | ||||
| !function (factory) { | ||||
|     if (typeof define === 'function' && define.amd) { | ||||
|         define(['modules/editor'], function (Editor) { | ||||
|             return factory(window.jQuery, Editor); | ||||
|         }); | ||||
|     } | ||||
| }(function ($, Editor) { | ||||
|     'use strict'; | ||||
|  | ||||
|     var layouts = { | ||||
|         title: GetTextByKey('P_LAYOUTS', 'Layouts'), | ||||
|         description: GetTextByKey('P_LAYOUTS', 'Layouts'), | ||||
|         version: '1.0', | ||||
|         isteam: false, | ||||
|         changed: false, | ||||
|         ui: {} | ||||
|     }; | ||||
|  | ||||
|     function createHeader() { | ||||
|         var header = $('<div></div>'); | ||||
|         header.append($('<div class="page_title"></div>').text(layouts.title)); | ||||
|         setPageTitle(layouts.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" />'); | ||||
|         var searchinputcontrol = $('<input type="text" style="margin-left:10px;" autocomplete="off" />'); | ||||
|         layouts.searchInput = searchinputcontrol; | ||||
|         search_bar.append(searchinputcontrol); | ||||
|         searchinputcontrol.keydown(function (e) { | ||||
|             if (e.keyCode == 13 || e.keyCode == 9) | ||||
|                 layouts.refresh(); | ||||
|         }); | ||||
|         var btnRefresh = $('<input class="search" type="button" style="margin-left:10px;"/>').val(GetTextByKey("P_IPT_SEARCH", "Search")); | ||||
|         search_bar.append(btnRefresh); | ||||
|         btnRefresh.click(function () { | ||||
|             layouts.refresh(); | ||||
|         }); | ||||
|  | ||||
|         var func = $('<div class="function_title"></div>'); | ||||
|         var iconAdd = $('<span class="sbutton iconadd"></span>').text(GetTextByKey("P_IPT_ADD", "Add")).on('click', function () { | ||||
|             layouts.onadd(); | ||||
|         }); | ||||
|         func.append(iconAdd); | ||||
|         var iconEdit = $('<span class="sbutton iconedit"></span>').text(GetTextByKey("P_IPT_EDIT", "Edit")).on('click', function () { | ||||
|             if (layouts.grid.selectedIndex >= 0) { | ||||
|                 layouts.onedit(); | ||||
|             } | ||||
|         }).prop('disabled', true); | ||||
|         layouts.ui.edit = iconEdit; | ||||
|         func.append(iconEdit); | ||||
|         var iconRefresh = $('<span class="sbutton iconrefresh"></span>').text(GetTextByKey("P_IPT_REFRESH", "Refresh")).on('click', function () { | ||||
|             layouts.refresh(); | ||||
|         }); | ||||
|         func.append(iconRefresh); | ||||
|         header.append(func) | ||||
|  | ||||
|         return header; | ||||
|     } | ||||
|  | ||||
|     function InitGridData() { | ||||
|         var div_grid = $('<div style="flex: 1 1 auto"></div>'); | ||||
|  | ||||
|         var grid_dt = new GridView(div_grid); | ||||
|         layouts.grid = grid_dt; | ||||
|         grid_dt.lang = { | ||||
|             all: GetTextByKey("P_GRID_ALL", "(All)"), | ||||
|             ok: GetTextByKey("P_GRID_OK", "OK"), | ||||
|             reset: GetTextByKey("P_GRID_RESET", "Reset") | ||||
|         }; | ||||
|         grid_dt.canMultiSelect = false; | ||||
|         grid_dt.columns = [ | ||||
|             { | ||||
|                 caption: GetTextByKey('P_LAYOUT_NAME', 'Layout Name'), | ||||
|                 key: 'Name', | ||||
|                 width: 200, | ||||
|                 isurl: true, | ||||
|                 events: { | ||||
|                     onclick: function () { | ||||
|                         doedit(this.Id); | ||||
|                     } | ||||
|                 }, | ||||
|                 styleFilter: function () { | ||||
|                     return { | ||||
|                         color: 'initial', | ||||
|                         cursor: 'pointer' | ||||
|                     }; | ||||
|                 } | ||||
|             }, | ||||
|             { | ||||
|                 caption: GetTextByKey('P_LAYOUT_NOTES', 'Notes'), | ||||
|                 key: 'Notes', | ||||
|                 width: 300 | ||||
|             }, | ||||
|             { | ||||
|                 isurl: true, | ||||
|                 resizable: false, | ||||
|                 orderable: false, | ||||
|                 sortable: false, | ||||
|                 width: 40, | ||||
|                 align: 'center', | ||||
|                 text: '\uf044', | ||||
|                 events: { | ||||
|                     onclick: function () { | ||||
|                         doedit(this.Id); | ||||
|                     } | ||||
|                 }, | ||||
|                 classFilter: function () { return 'icon-col' }, | ||||
|                 attrs: { | ||||
|                     title: GetTextByKey('P_WOS_EDIT', 'Edit') | ||||
|                 } | ||||
|             }, | ||||
|             { | ||||
|                 isurl: true, | ||||
|                 resizable: false, | ||||
|                 orderable: false, | ||||
|                 sortable: false, | ||||
|                 width: 40, | ||||
|                 align: 'center', | ||||
|                 text: '\uf00d', | ||||
|                 events: { | ||||
|                     onclick: function () { | ||||
|                         var id = this.Id; | ||||
|                         showConfirm( | ||||
|                             GetTextByKey('P_LAYOUT_DELETETIPS', 'Are you sure you want to delete the layout?'), | ||||
|                             GetTextByKey('P_LAYOUTS', 'Layouts'), | ||||
|                             function () { | ||||
|                                 inspectionrequest('DeleteInspectLayout', | ||||
|                                     JSON.stringify([layouts.isteam ? 1 : 0, id]), | ||||
|                                     function (data) { | ||||
|                                         if (data == 'OK') { | ||||
|                                             layouts.refresh(); | ||||
|                                         } else { | ||||
|                                             showAlert(data != 'Failed' ? data : GetTextByKey('P_LAYOUT_FAILEDDELETE', 'Failed to delete this layout.'), GetTextByKey('P_LAYOUTS', 'Layouts')); | ||||
|                                         } | ||||
|                                     }, | ||||
|                                     function () { | ||||
|                                         showAlert(GetTextByKey('P_LAYOUT_FAILEDDELETE', 'Failed to delete this layout.'), GetTextByKey('P_LAYOUTS', 'Layouts')); | ||||
|                                     } | ||||
|                                 ); | ||||
|                             } | ||||
|                         ); | ||||
|                     } | ||||
|                 }, | ||||
|                 classFilter: function () { return 'icon-col' }, | ||||
|                 attrs: { | ||||
|                     title: GetTextByKey('P_WOS_DELETE', 'Delete') | ||||
|                 } | ||||
|             } | ||||
|         ]; | ||||
|         grid_dt.init(); | ||||
|         grid_dt.rowdblclick = layouts.onedit; | ||||
|  | ||||
|         grid_dt.selectedrowchanged = function (rowindex) { | ||||
|             layouts.ui.edit.prop('disabled', rowindex >= 0); | ||||
|         } | ||||
|         return div_grid; | ||||
|     } | ||||
|  | ||||
|     Object.defineProperty(layouts, 'createContent', { | ||||
|         value: function (isteam) { | ||||
|             layouts.isteam = isteam && isteam[0] == '1'; | ||||
|             var content = $('<div style="height:100%; display:flex; flex-direction:column"></div>'); | ||||
|             content.append(createHeader()); | ||||
|             content.append(InitGridData()); | ||||
|             content.append('<div style="height: 2px"></div>'); | ||||
|  | ||||
|             layouts.refresh(); | ||||
|             return content; | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     Object.defineProperty(layouts, 'refresh', { | ||||
|         value: function () { | ||||
|             layouts.changed = false; | ||||
|             showmaskbg(true); | ||||
|             inspectionrequest('GetInspectLayouts', encodeURIComponent( | ||||
|                 JSON.stringify([layouts.isteam ? 1 : 0, layouts.searchInput.val()]) | ||||
|             ), function (data) { | ||||
|                 if ($.isArray(data)) { | ||||
|                     layouts.grid.setData(data.map(function (i) { return { Values: i } })); | ||||
|                 } else { | ||||
|                     showAlert(data, GetTextByKey('P_LAYOUTS', 'Layouts')); | ||||
|                 } | ||||
|                 showmaskbg(false); | ||||
|             }, function () { | ||||
|                 showmaskbg(false); | ||||
|             }); | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     function appendToolbar(ele) { | ||||
|         ele.append( | ||||
|             $('<div class="editor-toolbar"></div>').append( | ||||
|                 $('<select data-edit="fontname"></select>').append( | ||||
|                     $('<option selected>- Font -</option>'), | ||||
|                     $('<option>Arial</option>'), | ||||
|                     $('<option>Arial Black</option>'), | ||||
|                     $('<option>Courier New</option>'), | ||||
|                     $('<option>Times New Roman</option>') | ||||
|                 ), | ||||
|                 $('<select data-edit="fontsize"></select>').append( | ||||
|                     $('<option selected>- Size -</option>'), | ||||
|                     $('<option value="1">Very small</option>'), | ||||
|                     $('<option value="2">A bit small</option>'), | ||||
|                     $('<option value="3">Normal</option>'), | ||||
|                     $('<option value="4">Medium-large</option>'), | ||||
|                     $('<option value="5">Big</option>'), | ||||
|                     $('<option value="6">Very big</option>'), | ||||
|                     $('<option value="7">Maximum</option>') | ||||
|                 ), | ||||
|                 $('<a data-edit="undo" title="Undo"><svg><use href="#symbol-undo"></use></svg></a>'), | ||||
|                 $('<a data-edit="redo" title="Redo"><svg><use href="#symbol-redo"></use></svg></a>'), | ||||
|                 $('<a data-edit="bold" title="Bold"><svg class="black"><use href="#symbol-bold"></use></svg></a>'), | ||||
|                 $('<a data-edit="italic" title="Italic"><svg class="black"><use href="#symbol-italic"></use></svg></a>'), | ||||
|                 $('<a data-edit="underline" title="Underline"><svg class="black"><use href="#symbol-underline"></use></svg></a>'), | ||||
|                 $('<a data-edit="createlink" title="Hyperlink"><svg><use href="#symbol-link"></use></svg></a>'), | ||||
|                 $('<select data-edit="forecolor" style="margin-left: 10px">').append( | ||||
|                     $('<option selected>- Color -</option>'), | ||||
|                     $('<option value="red">Red</option>'), | ||||
|                     $('<option value="blue">Blue</option>'), | ||||
|                     $('<option value="green">Green</option>'), | ||||
|                     $('<option value="black">Black</option>') | ||||
|                 ), | ||||
|                 $('<select data-edit>').append( | ||||
|                     $('<option selected>- Fields -</option>'), | ||||
|                     $('<option value="[Advisor]">Advisor</option>'), | ||||
|                     $('<option value="[Asset_Groups]">Asset Group(s)</option>'), | ||||
|                     $('<option value="[Asset_Name]">Asset Name</option>'), | ||||
|                     $('<option value="[Asset_Name_Custom]">Asset Name (Custom)</option>'), | ||||
|                     $('<option value="[Asset_Type]">Asset Type</option>'), | ||||
|                     $('<option value="[Creator]">Creator</option>'), | ||||
|                     $('<option value="[Current_Jobsite]">Current Jobsite</option>'), | ||||
|                     $('<option value="[Current_Location]">Current Location</option>'), | ||||
|                     $('<option value="[Customer_Visible]">Customer Visible</option>'), | ||||
|                     $('<option value="[Date_Performed]">Date Performed</option>'), | ||||
|                     $('<option value="[DateTime_Performed]">Date/Time Performed</option>'), | ||||
|                     $('<option value="[Engine_Hours]">Engine Hours</option>'), | ||||
|                     $('<option value="[Odometer]">Odometer</option>'), | ||||
|                     $('<option value="[Engine_Hours_Or_Odometer]">Engine Hours Or Odometer</option>'), | ||||
|                     $('<option value="[Make]">Make</option>'), | ||||
|                     $('<option value="[Model]">Model</option>'), | ||||
|                     $('<option value="[VIN]">VIN/SN</option>'), | ||||
|                     $('<option value="[Work_Order_Number]">Work Order Number</option>'), | ||||
|                     $('<option value="[Work_Order_Type]">Work Order Type</option>'), | ||||
|                     $('<option value="[Parts_Order_Number]">Parts Order Number</option>'), | ||||
|                     $('<option value="[Year]">Year</option>') | ||||
|                 ) | ||||
|             ) | ||||
|         ); | ||||
|         return ele; | ||||
|     } | ||||
|  | ||||
|     function initEditor(content, id) { | ||||
|         var textarea = $('<textarea class="editor-content"></textarea>'); | ||||
|         if (!layouts.isteam) { | ||||
|             var selector = $('<select class="editor-select"></select>').append( | ||||
|                 $('<option></option>'), | ||||
|                 $('<option value="[Advisor]">Advisor</option>'), | ||||
|                 $('<option value="[Asset_Groups]">Asset Group(s)</option>'), | ||||
|                 $('<option value="[Asset_Name]">Asset Name</option>'), | ||||
|                 $('<option value="[Asset_Name_Custom]">Asset Name (Custom)</option>'), | ||||
|                 $('<option value="[Asset_Type]">Asset Type</option>'), | ||||
|                 $('<option value="[Creator]">Creator</option>'), | ||||
|                 $('<option value="[Current_Jobsite]">Current Jobsite</option>'), | ||||
|                 $('<option value="[Current_Location]">Current Location</option>'), | ||||
|                 $('<option value="[Customer_Visible]">Customer Visible</option>'), | ||||
|                 $('<option value="[Date_Performed]">Date Performed</option>'), | ||||
|                 $('<option value="[DateTime_Performed]">Date/Time Performed</option>'), | ||||
|                 $('<option value="[Engine_Hours]">Engine Hours</option>'), | ||||
|                 $('<option value="[Odometer]">Odometer</option>'), | ||||
|                 $('<option value="[Engine_Hours_Or_Odometer]">Engine Hours Or Odometer</option>'), | ||||
|                 $('<option value="[Make]">Make</option>'), | ||||
|                 $('<option value="[Model]">Model</option>'), | ||||
|                 $('<option value="[VIN]">VIN/SN</option>'), | ||||
|                 $('<option value="[Work_Order_Number]">Work Order Number</option>'), | ||||
|                 $('<option value="[Work_Order_Type]">Work Order Type</option>'),  | ||||
|                 $('<option value="[Parts_Order_Number]">Parts Order Number</option>'), | ||||
|                 $('<option value="[Year]">Year</option>') | ||||
|             ); | ||||
|             if (typeof IsCustomerRecord !== 'undefined' && IsCustomerRecord) { | ||||
|                 selector.append( | ||||
|                     $('<option value="[Company_Name]">Company Name</option>'), | ||||
|                     $('<option value="[Contacts]">Contacts</option>'), | ||||
|                     $('<option value="[Customer_Code]">Customer Code</option>'), | ||||
|                     $('<option value="[Location]">Location</option>') | ||||
|                 ); | ||||
|             } | ||||
|             content.find(id + '-vars').append( | ||||
|                 $('<span></span>').text(GetTextByKey('P_LAYOUT_VARIABLE', 'Variable:')), | ||||
|                 selector.on('change', function () { | ||||
|                     var val = $(this).val(); | ||||
|                     var t = textarea[0]; | ||||
|                     if (document.selection) { | ||||
|                         textarea.focus(); | ||||
|                         var sel = document.selection.createRange(); | ||||
|                         sel.text = val; | ||||
|                         textarea.focus(); | ||||
|                     } else { | ||||
|                         if (t.selectionStart || t.selectionStart == 0) { | ||||
|                             var start = t.selectionStart; | ||||
|                             var end = t.selectionEnd; | ||||
|                             var scrollTop = t.scrollTop; | ||||
|                             t.value = t.value.substr(0, start) + val + t.value.substr(end, t.value.length); | ||||
|                             textarea.focus(); | ||||
|                             t.selectionStart = start + val.length; | ||||
|                             t.selectionEnd = start + val.length; | ||||
|                             t.scrollTop = scrollTop; | ||||
|                         } else { | ||||
|                             t.value += val; | ||||
|                             textarea.focus(); | ||||
|                         } | ||||
|                     } | ||||
|                     $(this).val(''); | ||||
|                 }) | ||||
|             ); | ||||
|         } | ||||
|         content.find(id).append(textarea); | ||||
|     } | ||||
|  | ||||
|     function editLayout(info) { | ||||
|         $('#right_popup').load('js/modules/layouts/addlayout.html?v=2', function () { | ||||
|             var modified = false; | ||||
|             var deleteIcon = false; | ||||
|             var content = $(this).applyFleetLanguageText(true); | ||||
|             content.find('.button-exit').on('click', function () { | ||||
|                 if (modified) { | ||||
|                     showConfirm( | ||||
|                         GetTextByKey('P_LAYOUT_CONFIRMSAVE', 'The inspection layout has been modified, are you sure you want to discard the modifications and exit?'), | ||||
|                         GetTextByKey('P_LAYOUT_EDITINSPECTLAYOUT', 'Edit Inspection Layout'), | ||||
|                         function () { | ||||
|                             showRightPopup(false); | ||||
|                             if (layouts.changed) { | ||||
|                                 layouts.refresh(); | ||||
|                             } | ||||
|                         } | ||||
|                     ); | ||||
|                 } else { | ||||
|                     showRightPopup(false); | ||||
|                     if (layouts.changed) { | ||||
|                         layouts.refresh(); | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|             content.find('.button-icon-upload').on('click', function () { | ||||
|                 content.find('.icon-file file').remove(); | ||||
|                 $('<input type="file" accept="image/png,image/jpeg" />') | ||||
|                     .hide().appendTo(content.find('.icon-file')) | ||||
|                     .on('change', function () { | ||||
|                         if (!/image\/\w+/.test(this.files[0].type)) { | ||||
|                             showAlert(GetTextByKey("P_LAYOUT_UPLOADICONTIPS", 'The file type for the logo is invalid. The file must be JPG or PNG.'), GetTextByKey('P_LAYOUT_SAVEINSPECTLAYOUT', 'Save Inspection Layout')); | ||||
|                             $(this).remove(); | ||||
|                             return; | ||||
|                         } | ||||
|                         var file = this.files[0]; | ||||
|                         var reader = new FileReader(); | ||||
|                         reader.readAsDataURL(file); | ||||
|                         reader.onload = function (e) { | ||||
|                             setTimeout(function () { | ||||
|                                 content.find('.img-icon-filename').remove(); | ||||
|                                 $('<img class="img-icon-filename" />').attr('src', e.target.result).insertAfter(content.find('.icon-file-title')); | ||||
|                             }); | ||||
|                         }; | ||||
|                     }).click(); | ||||
|             }); | ||||
|             content.find('.button-icon-delete').on('click', function () { | ||||
|                 deleteIcon = true; | ||||
|                 content.find('.img-icon-filename').remove(); | ||||
|             }); | ||||
|             var save = function (exit) { | ||||
|                 return function () { | ||||
|                     var title = GetTextByKey('P_LAYOUT_SAVEINSPECTLAYOUT', 'Save Inspection Layout'); | ||||
|                     var name = content.find('.text-layout-name').val(); | ||||
|                     name = name && name.trim(); | ||||
|                     if (name == null || name.length === 0) { | ||||
|                         showAlert( | ||||
|                             GetTextByKey('P_LAYOUT_NAMEISEQUIRED', 'Layout name is required.'), | ||||
|                             title, null, | ||||
|                             function () { content.find('.text-layout-name').focus() } | ||||
|                         ); | ||||
|                         return; | ||||
|                     } | ||||
|  | ||||
|                     var layout = { | ||||
|                         Id: info && info.Id, | ||||
|                         Target: layouts.isteam ? 1 : 0, | ||||
|                         Name: name, | ||||
|                         IncludeLOGO: content.find('#layout-include-logo').prop('checked'), | ||||
|                         Notes: content.find('.text-layout-notes').val(), | ||||
|                         PageHeaderLeft: content.find('.layout-headers-left .editor-content').val(), | ||||
|                         PageHeaderCenter: content.find('.layout-headers-middle .editor-content').val(), | ||||
|                         PageHeaderRight: content.find('.layout-headers-right .editor-content').val(), | ||||
|                         PageFooterLeft: content.find('.layout-footers-left .editor-content').val(), | ||||
|                         PageFooterCenter: content.find('.layout-footers-middle .editor-content').val(), | ||||
|                         PageFooterRight: content.find('.layout-footers-right .editor-content').val() | ||||
|                     }; | ||||
|                     var data = new FormData(); | ||||
|                     var files = content.find('.icon-file input[type="file"]').prop('files'); | ||||
|                     if (files && files[0]) { | ||||
|                         data.append('iconFile', files && files[0]); | ||||
|                     } else if (!deleteIcon) { | ||||
|                         var logo = content.find('.img-icon-filename').prop('src'); | ||||
|                         layout.LOGO = logo.substr(logo.indexOf(';base64,') + 8); | ||||
|                     } | ||||
|                     data.append('MethodName', 'SaveInspectLayout'); | ||||
|                     data.append('ClientData', encodeURIComponent(JSON.stringify(layout))); | ||||
|                     $.ajax({ | ||||
|                         url: window.location.href, | ||||
|                         type: 'POST', | ||||
|                         dataType: 'json', | ||||
|                         processData: false, | ||||
|                         contentType: false, | ||||
|                         data: data, | ||||
|                         success: function (data) { | ||||
|                             if ($.isArray(data)) { | ||||
|                                 if (data[1] !== 'Failed') { | ||||
|                                     if (exit) { | ||||
|                                         showRightPopup(false); | ||||
|                                         layouts.refresh(); | ||||
|                                         return; | ||||
|                                     } | ||||
|                                     if (info == null) { | ||||
|                                         info = layout; | ||||
|                                     } | ||||
|                                     info.Id = data[0]; | ||||
|                                     showAlert(data[1], title, null, function () { | ||||
|                                         layouts.changed = true; | ||||
|                                         modified = false; | ||||
|                                     }); | ||||
|                                 } else { | ||||
|                                     showAlert(GetTextByKey('P_MA_PAGEERROR', 'An unknown error occurred.  Please refresh page.'), title); | ||||
|                                 } | ||||
|                             } else { | ||||
|                                 showAlert(data, title); | ||||
|                             } | ||||
|                         }, | ||||
|                         error: function (err) { | ||||
|                             showAlert(GetTextByKey('P_MA_PAGEERROR', 'An unknown error occurred.  Please refresh page.'), title); | ||||
|                         } | ||||
|                     }); | ||||
|                 } | ||||
|             } | ||||
|             content.find('.button-save').on('click', save()); | ||||
|             content.find('.button-save-exit').on('click', save(true)); | ||||
|             showRightPopup(true); | ||||
|  | ||||
|             //new Editor(appendToolbar($(this).find('.layout-headers-left'))); | ||||
|             //new Editor(appendToolbar($(this).find('.layout-headers-middle'))); | ||||
|             //new Editor(appendToolbar($(this).find('.layout-headers-right'))); | ||||
|             //new Editor(appendToolbar($(this).find('.layout-footers-left'))); | ||||
|             //new Editor(appendToolbar($(this).find('.layout-footers-middle'))); | ||||
|             //new Editor(appendToolbar($(this).find('.layout-footers-right'))); | ||||
|             initEditor(content, '.layout-headers-left'); | ||||
|             initEditor(content, '.layout-headers-middle'); | ||||
|             initEditor(content, '.layout-headers-right'); | ||||
|             initEditor(content, '.layout-footers-left'); | ||||
|             initEditor(content, '.layout-footers-middle'); | ||||
|             initEditor(content, '.layout-footers-right'); | ||||
|  | ||||
|             var onchange = function () { modified = true }; | ||||
|             if (info != null) { | ||||
|                 content.find('.text-layout-name').val(info.Name); | ||||
|                 content.find('#layout-include-logo').prop('checked', info.IncludeLOGO); | ||||
|                 if (info.LOGO != null) { | ||||
|                     content.find('.img-icon-filename').attr('src', 'data:image/png;base64,' + info.LOGO); | ||||
|                 } | ||||
|                 content.find('.text-layout-notes').val(info.Notes); | ||||
|                 content.find('.layout-headers-left .editor-content').val(info.PageHeaderLeft); | ||||
|                 content.find('.layout-headers-middle .editor-content').val(info.PageHeaderCenter); | ||||
|                 content.find('.layout-headers-right .editor-content').val(info.PageHeaderRight); | ||||
|                 content.find('.layout-footers-left .editor-content').val(info.PageFooterLeft); | ||||
|                 content.find('.layout-footers-middle .editor-content').val(info.PageFooterCenter); | ||||
|                 content.find('.layout-footers-right .editor-content').val(info.PageFooterRight); | ||||
|             } | ||||
|             content.find('.text-layout-name').on('change', onchange); | ||||
|             content.find('#layout-include-logo').on('change', onchange); | ||||
|             content.find('.text-layout-notes').on('change', onchange); | ||||
|             content.find('.layout-headers-left .editor-content').on('change', onchange); | ||||
|             content.find('.layout-headers-middle .editor-content').on('change', onchange); | ||||
|             content.find('.layout-headers-right .editor-content').on('change', onchange); | ||||
|             content.find('.layout-footers-left .editor-content').on('change', onchange); | ||||
|             content.find('.layout-footers-middle .editor-content').on('change', onchange); | ||||
|             content.find('.layout-footers-right .editor-content').on('change', onchange); | ||||
|  | ||||
|             content.find('.text-layout-name').focus(); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     Object.defineProperty(layouts, 'onadd', { | ||||
|         value: function () { | ||||
|             editLayout(); | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     function doedit(id) { | ||||
|         showmaskbg(true); | ||||
|         var p = [layouts.isteam ? 1 : 0, id]; | ||||
|         inspectionrequest('GetInspectLayout', JSON.stringify(p), function (data) { | ||||
|             editLayout(data); | ||||
|         }, function () { | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     Object.defineProperty(layouts, 'onedit', { | ||||
|         value: function () { | ||||
|             if (layouts.grid && layouts.grid.selectedIndex >= 0) { | ||||
|                 var id = layouts.grid.source[layouts.grid.selectedIndex].Values.Id; | ||||
|                 doedit(id); | ||||
|             } | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     return layouts; | ||||
| }); | ||||
							
								
								
									
										91
									
								
								Site/Inspection/js/modules/layouts/addlayout.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								Site/Inspection/js/modules/layouts/addlayout.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,91 @@ | ||||
| <!DOCTYPE html> | ||||
| <html> | ||||
| <body> | ||||
|     <div> | ||||
|         <div class="function_title"> | ||||
|             <span class="sbutton iconsave button-save" data-lgid="P_IPT_SAVE">Save</span> | ||||
|             <span class="sbutton iconsave button-save-exit" data-lgid="P_IPT_SAVE1">Save and Exit</span> | ||||
|             <span class="sbutton iconexit button-exit" data-lgid="P_IPT_SAVE2">Exit Without Saving</span> | ||||
|         </div> | ||||
|         <div class="page_title" data-lgid="P_LAYOUT_GENERAL">General</div> | ||||
|         <div style="display: flex"> | ||||
|             <div class="settings-line"> | ||||
|                 <span> | ||||
|                     <span data-lgid="P_LAYOUT_NAMECOLON">Layout Name:</span> | ||||
|                     <b style="color: red">*</b> | ||||
|                     <input type="text" class="text-layout-name" maxlength="200" /> | ||||
|                 </span> | ||||
|                 <span> | ||||
|                     <label for="layout-include-logo" data-lgid="P_LAYOUT_INCLUDELOGO">Include Logo:</label> | ||||
|                     <input type="checkbox" id="layout-include-logo" /> | ||||
|                 </span> | ||||
|                 <span class="icon-file"> | ||||
|                     <span class="icon-file-title" data-lgid="P_LAYOUT_ICONFILENAME">Logo file:</span> | ||||
|                     <img class="img-icon-filename" /> | ||||
|                     <span class="svg-button button-icon-upload"><svg><use href="#symbol-upload"></use></svg></span> | ||||
|                     <span class="svg-button button-icon-delete"><svg><use href="#symbol-close"></use></svg></span> | ||||
|                 </span> | ||||
|             </div> | ||||
|             <div class="settings-line" style="flex: 1 1 auto"> | ||||
|                 <span style="display: flex"> | ||||
|                     <span data-lgid="P_LAYOUT_NOTESCOLON" style="vertical-align:top; white-space:nowrap">Notes:</span> | ||||
|                     <textarea class="text-layout-notes" style="height:100px; width:100%; box-sizing:border-box; margin-left:8px"></textarea> | ||||
|                 </span> | ||||
|             </div> | ||||
|         </div> | ||||
|  | ||||
|         <div class="page_title" data-lgid="P_IPT_FUELRPT_HEADER">Page Headers</div> | ||||
|         <div class="settings-line"> | ||||
|             <div class="editor-top"> | ||||
|                 <span data-lgid="P_IPT_FUELRPT_LEFT">Left</span> | ||||
|                 <div class="layout-headers-left-vars"></div> | ||||
|             </div> | ||||
|             <div class="layout-headers-left"></div> | ||||
|             <div class="editor-top"> | ||||
|                 <span data-lgid="P_IPT_FUELRPT_MIDDLE">Middle</span> | ||||
|                 <div class="layout-headers-middle-vars"></div> | ||||
|             </div> | ||||
|             <div class="layout-headers-middle"></div> | ||||
|             <div class="editor-top"> | ||||
|                 <span data-lgid="P_IPT_FUELRPT_RIGHT">Right</span> | ||||
|                 <div class="layout-headers-right-vars"></div> | ||||
|             </div> | ||||
|             <div class="layout-headers-right"></div> | ||||
|         </div> | ||||
|  | ||||
|         <div class="page_title" data-lgid="P_IPT_FUELRPT_FOOTER">Page Footers</div> | ||||
|         <div class="settings-line" style="padding-bottom: 20px"> | ||||
|             <div class="editor-top"> | ||||
|                 <span data-lgid="P_IPT_FUELRPT_LEFT">Left</span> | ||||
|                 <div class="layout-footers-left-vars"></div> | ||||
|             </div> | ||||
|             <div class="layout-footers-left"></div> | ||||
|             <div class="editor-top"> | ||||
|                 <span data-lgid="P_IPT_FUELRPT_MIDDLE">Middle</span> | ||||
|                 <div class="layout-footers-middle-vars"></div> | ||||
|             </div> | ||||
|             <div class="layout-footers-middle"></div> | ||||
|             <div class="editor-top"> | ||||
|                 <span data-lgid="P_IPT_FUELRPT_RIGHT">Right</span> | ||||
|                 <div class="layout-footers-right-vars"></div> | ||||
|             </div> | ||||
|             <div class="layout-footers-right"></div> | ||||
|         </div> | ||||
|  | ||||
|         <div id="svg-container" style="width: 0; height: 0; overflow: hidden"> | ||||
|             <svg> | ||||
|                 <defs> | ||||
|                     <symbol id="symbol-undo" role="presentation" focusable="false" xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><g><path d="M212.333 224.333H12c-6.627 0-12-5.373-12-12V12C0 5.373 5.373 0 12 0h48c6.627 0 12 5.373 12 12v78.112C117.773 39.279 184.26 7.47 258.175 8.007c136.906.994 246.448 111.623 246.157 248.532C504.041 393.258 393.12 504 256.333 504c-64.089 0-122.496-24.313-166.51-64.215-5.099-4.622-5.334-12.554-.467-17.42l33.967-33.967c4.474-4.474 11.662-4.717 16.401-.525C170.76 415.336 211.58 432 256.333 432c97.268 0 176-78.716 176-176 0-97.267-78.716-176-176-176-58.496 0-110.28 28.476-142.274 72.333h98.274c6.627 0 12 5.373 12 12v48c0 6.627-5.373 12-12 12z" /></g></symbol> | ||||
|                     <symbol id="symbol-redo" role="presentation" focusable="false" xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><g><path d="M500.33 0h-47.41a12 12 0 0 0-12 12.57l4 82.76A247.42 247.42 0 0 0 256 8C119.34 8 7.9 119.53 8 256.19 8.1 393.07 119.1 504 256 504a247.1 247.1 0 0 0 166.18-63.91 12 12 0 0 0 .48-17.43l-34-34a12 12 0 0 0-16.38-.55A176 176 0 1 1 402.1 157.8l-101.53-4.87a12 12 0 0 0-12.57 12v47.41a12 12 0 0 0 12 12h200.33a12 12 0 0 0 12-12V12a12 12 0 0 0-12-12z" /></g></symbol> | ||||
|                     <symbol id="symbol-bold" role="presentation" focusable="false" xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><g><path d="M333.49 238a122 122 0 0 0 27-65.21C367.87 96.49 308 32 233.42 32H34a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h31.87v288H34a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h209.32c70.8 0 134.14-51.75 141-122.4 4.74-48.45-16.39-92.06-50.83-119.6zM145.66 112h87.76a48 48 0 0 1 0 96h-87.76zm87.76 288h-87.76V288h87.76a56 56 0 0 1 0 112z" /></g></symbol> | ||||
|                     <symbol id="symbol-italic" role="presentation" focusable="false" xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><g><path d="M320 48v32a16 16 0 0 1-16 16h-62.76l-80 320H208a16 16 0 0 1 16 16v32a16 16 0 0 1-16 16H16a16 16 0 0 1-16-16v-32a16 16 0 0 1 16-16h62.76l80-320H112a16 16 0 0 1-16-16V48a16 16 0 0 1 16-16h192a16 16 0 0 1 16 16z" /></g></symbol> | ||||
|                     <symbol id="symbol-underline" role="presentation" focusable="false" xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><g><path d="M32 64h32v160c0 88.22 71.78 160 160 160s160-71.78 160-160V64h32a16 16 0 0 0 16-16V16a16 16 0 0 0-16-16H272a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h32v160a80 80 0 0 1-160 0V64h32a16 16 0 0 0 16-16V16a16 16 0 0 0-16-16H32a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16zm400 384H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16z" /></g></symbol> | ||||
|                     <symbol id="symbol-link" role="presentation" focusable="false" xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><g><path d="M326.612 185.391c59.747 59.809 58.927 155.698.36 214.59-.11.12-.24.25-.36.37l-67.2 67.2c-59.27 59.27-155.699 59.262-214.96 0-59.27-59.26-59.27-155.7 0-214.96l37.106-37.106c9.84-9.84 26.786-3.3 27.294 10.606.648 17.722 3.826 35.527 9.69 52.721 1.986 5.822.567 12.262-3.783 16.612l-13.087 13.087c-28.026 28.026-28.905 73.66-1.155 101.96 28.024 28.579 74.086 28.749 102.325.51l67.2-67.19c28.191-28.191 28.073-73.757 0-101.83-3.701-3.694-7.429-6.564-10.341-8.569a16.037 16.037 0 0 1-6.947-12.606c-.396-10.567 3.348-21.456 11.698-29.806l21.054-21.055c5.521-5.521 14.182-6.199 20.584-1.731a152.482 152.482 0 0 1 20.522 17.197zM467.547 44.449c-59.261-59.262-155.69-59.27-214.96 0l-67.2 67.2c-.12.12-.25.25-.36.37-58.566 58.892-59.387 154.781.36 214.59a152.454 152.454 0 0 0 20.521 17.196c6.402 4.468 15.064 3.789 20.584-1.731l21.054-21.055c8.35-8.35 12.094-19.239 11.698-29.806a16.037 16.037 0 0 0-6.947-12.606c-2.912-2.005-6.64-4.875-10.341-8.569-28.073-28.073-28.191-73.639 0-101.83l67.2-67.19c28.239-28.239 74.3-28.069 102.325.51 27.75 28.3 26.872 73.934-1.155 101.96l-13.087 13.087c-4.35 4.35-5.769 10.79-3.783 16.612 5.864 17.194 9.042 34.999 9.69 52.721.509 13.906 17.454 20.446 27.294 10.606l37.106-37.106c59.271-59.259 59.271-155.699.001-214.959z" /></g></symbol> | ||||
|                     <symbol id="symbol-upload" role="presentation" focusable="false" xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><g><path d="M452 432c0 11-9 20-20 20s-20-9-20-20 9-20 20-20 20 9 20 20zm-84-20c-11 0-20 9-20 20s9 20 20 20 20-9 20-20-9-20-20-20zm144-48v104c0 24.3-19.7 44-44 44H44c-24.3 0-44-19.7-44-44V364c0-24.3 19.7-44 44-44h124v-99.3h-52.7c-35.6 0-53.4-43.1-28.3-68.3L227.7 11.7c15.6-15.6 40.9-15.6 56.6 0L425 152.4c25.2 25.2 7.3 68.3-28.3 68.3H344V320h124c24.3 0 44 19.7 44 44zM200 188.7V376c0 4.4 3.6 8 8 8h96c4.4 0 8-3.6 8-8V188.7h84.7c7.1 0 10.7-8.6 5.7-13.7L261.7 34.3c-3.1-3.1-8.2-3.1-11.3 0L109.7 175c-5 5-1.5 13.7 5.7 13.7H200zM480 364c0-6.6-5.4-12-12-12H344v24c0 22.1-17.9 40-40 40h-96c-22.1 0-40-17.9-40-40v-24H44c-6.6 0-12 5.4-12 12v104c0 6.6 5.4 12 12 12h424c6.6 0 12-5.4 12-12V364z" /></g></symbol> | ||||
|                     <symbol id="symbol-close" role="presentation" focusable="false" xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><g><path d="M193.94 256L296.5 153.44l21.15-21.15c3.12-3.12 3.12-8.19 0-11.31l-22.63-22.63c-3.12-3.12-8.19-3.12-11.31 0L160 222.06 36.29 98.34c-3.12-3.12-8.19-3.12-11.31 0L2.34 120.97c-3.12 3.12-3.12 8.19 0 11.31L126.06 256 2.34 379.71c-3.12 3.12-3.12 8.19 0 11.31l22.63 22.63c3.12 3.12 8.19 3.12 11.31 0L160 289.94 262.56 392.5l21.15 21.15c3.12 3.12 8.19 3.12 11.31 0l22.63-22.63c3.12-3.12 3.12-8.19 0-11.31L193.94 256z" /></g></symbol> | ||||
|                 </defs> | ||||
|             </svg> | ||||
|         </div> | ||||
|     </div> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										72
									
								
								Site/Inspection/js/modules/pageloader.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								Site/Inspection/js/modules/pageloader.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | ||||
| /* | ||||
|  module - | ||||
|    description: 模块描述 | ||||
|    version: 模块版本 | ||||
|    createContent: 产生模块正文 | ||||
|  */ | ||||
|  | ||||
| define(function () { | ||||
|     var _loader = { | ||||
|         links: '', | ||||
|         content: '', | ||||
|         init: function () { | ||||
|             $(function () { | ||||
|                 $(window).on('hashchange', function (e) { | ||||
|                     var hash = location.hash; | ||||
|                     if (hash == null || hash.length <= 1) { | ||||
|                         $(_loader.links).filter('[data-module]').removeClass('selected'); | ||||
|                         $(_loader.content).empty(); | ||||
|                         return; | ||||
|                     } | ||||
|                     hash = hash.substring(1); | ||||
|                     _loader.jump(hash); | ||||
|                 }); | ||||
|  | ||||
|                 // page loaded | ||||
|                 var hash = location.hash; | ||||
|                 if (hash != null && hash.length > 1) { | ||||
|                     hash = hash.substring(1); | ||||
|                     //$(_loader.links).filter('[data-module="' + hash + '"]').addClass('selected'); | ||||
|                     _loader.jump(hash); | ||||
|                 } | ||||
|                 else { | ||||
|                     //$(_loader.links).first().addClass('selected'); | ||||
|                     hash = $(_loader.links).filter('[data-module]').first().addClass('selected').attr("data-module"); | ||||
|                     _loader.jump(hash); | ||||
|                 } | ||||
|  | ||||
|                 //var links = $(_loader.links).filter('[data-module]'); | ||||
|                 //links.click(function (e) { | ||||
|                 //    // load module | ||||
|                 //    var module = $(e.target).data('module'); | ||||
|                 //    location.hash = module; | ||||
|                 //}); | ||||
|             }); | ||||
|         }, | ||||
|         jump: function (hash) { | ||||
|             var module = null; | ||||
|             var ps = undefined; | ||||
|             if (hash && hash.indexOf('/') > 0) { | ||||
|                 ps = hash.split('/'); | ||||
|                 module = ps[0]; | ||||
|                 ps.splice(0, 1); | ||||
|             } | ||||
|             else | ||||
|                 module = hash; | ||||
|  | ||||
|             if (module) { | ||||
|                 $(_loader.links).filter('[data-module]').removeClass('selected'); | ||||
|                 $(_loader.links).filter('[data-module="' + hash + '"]').addClass('selected'); | ||||
|                 require(['modules/' + module], function (m) { | ||||
|                     $(_loader.content).empty().append(m.createContent(ps)); | ||||
|                 }); | ||||
|             } | ||||
|             //else { | ||||
|             //    require(['modules/' + module], function (m) { | ||||
|             //        $(_loader.content).empty().append(m.createContent()); | ||||
|             //    }); | ||||
|             //} | ||||
|         } | ||||
|     }; | ||||
|     return _loader; | ||||
| }); | ||||
							
								
								
									
										508
									
								
								Site/Inspection/js/modules/sections/addquestion.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										508
									
								
								Site/Inspection/js/modules/sections/addquestion.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,508 @@ | ||||
| define(['common'], function (Common) { | ||||
|  | ||||
|     var aq = function (p, sectionid, question) { | ||||
|         this.sectionid = sectionid; | ||||
|         this.question = question; | ||||
|         this.holder = null; | ||||
|         this.sectionmodule = p; | ||||
|         this.datasaved = false; | ||||
|     }; | ||||
|     aq.prototype.description = "Add or edit question"; | ||||
|     aq.prototype.version = "1.0.0.0"; | ||||
|     aq.prototype.onsave = null; | ||||
|  | ||||
|     var namecontrol = undefined; | ||||
|     var questiontypecontrol = undefined; | ||||
|     var isrequiredcontrol = undefined; | ||||
|     var cancommentcontrol = undefined; | ||||
|     var severitylevelcontrol = undefined; | ||||
|     var isimportantcontrol = undefined; | ||||
|     var displaytextcontrol = undefined; | ||||
|     var notescontrol = undefined; | ||||
|     var optiontr = undefined; | ||||
|     var optiontd = undefined; | ||||
|     var options = []; | ||||
|     var questiontype = undefined; | ||||
|     aq.prototype.createContent = function () { | ||||
|         options = []; | ||||
|         var _this = this; | ||||
|         var content = $('<div></div>'); | ||||
|  | ||||
|         function createHeader() { | ||||
|             var header = $('<div></div>'); | ||||
|  | ||||
|             var funcs = $('<div class="function_title"></div>'); | ||||
|             if (sectiontype == 0) { | ||||
|                 var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE", "Save") + '</span>').click(function () { | ||||
|                     saveData(0); | ||||
|                 }); | ||||
|                 funcs.append(btn); | ||||
|                 btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE1", "Save and Exit") + '</span>').click(function () { | ||||
|                     saveData(1); | ||||
|                 }); | ||||
|                 funcs.append(btn); | ||||
|                 btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_SAVE2", "Exit Without Saving") + '</span>').click(function () { | ||||
|                     showRightPopup(false); | ||||
|                     if (_this.datasaved) | ||||
|                         _this.sectionmodule.refresh(); | ||||
|                 }); | ||||
|                 funcs.append(btn); | ||||
|             } | ||||
|             else { | ||||
|                 header.append($('<div class="function_title" style="background-color:#ddd;font-size:16px;"></div>').text(_this.question ? GetTextByKey("P_IPT_EDITQUESTION", 'Edit Question') : GetTextByKey("P_IPT_ADDQUESTION", 'Add Question'))); | ||||
|                 if (!templatereadonly && (!_this.question || (_this.question && !_this.question.IsLink))) { | ||||
|                     //if (!_this.question || (_this.question && !_this.question.IsLink)) { | ||||
|                     var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_OK", "OK") + '</span>').click(function () { | ||||
|                         var item = getData(); | ||||
|                         if (!item) | ||||
|                             return; | ||||
|                         if (_this.onsave) | ||||
|                             _this.onsave(item); | ||||
|                         $('#right_popup1').empty().hide(); | ||||
|                     }); | ||||
|                     funcs.append(btn); | ||||
|                 } | ||||
|                 btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_CANCEL", "Cancel") + '</span>').click(function () { | ||||
|                     $('#right_popup1').empty().hide(); | ||||
|                 }); | ||||
|                 funcs.append(btn); | ||||
|             } | ||||
|             header.append(funcs) | ||||
|  | ||||
|             return header; | ||||
|         } | ||||
|  | ||||
|         function createQuestionContent() { | ||||
|             var div_main = $('<div class="content_main" style="overflow: auto;"></div>'); | ||||
|             var div_content = $('<div class="edit-content"></div>'); | ||||
|             div_main.append(div_content); | ||||
|             var tb = $('<table style="line-height: 35px;"></table>'); | ||||
|             div_content.append(tb); | ||||
|  | ||||
|             var tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label">' + GetTextByKey("P_IPT_NAME_COLON", "Name:") + '<span class="redasterisk">*</span></td>'); | ||||
|             namecontrol = $('<input type="text" maxlength="100"/>'); | ||||
|             var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|             addiText.click(function () { | ||||
|                 Common.createMultiTextDialog(namecontrol, _this.question); | ||||
|             }); | ||||
|             tr.append($('<td></td>').append(namecontrol).append(addiText)); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label">' + GetTextByKey("P_IPT_DISPLAYTEXT_COLON", "Display Text:") + '<span  class="redasterisk">*</span></td>'); | ||||
|             displaytextcontrol = $('<input type="text" maxlength="1000" />'); | ||||
|             addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|             addiText.click(function () { | ||||
|                 Common.createMultiTextDialog(displaytextcontrol, _this.question); | ||||
|             }); | ||||
|             tr.append($('<td></td>').append(displaytextcontrol).append(addiText)); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label">Type:</td>'); | ||||
|             questiontypecontrol = createQuestionType(); | ||||
|             questiontypecontrol.change(function () { | ||||
|                 questionTypeChange(); | ||||
|             }); | ||||
|             tr.append($('<td></td>').append(questiontypecontrol)); | ||||
|  | ||||
|             optiontr = $('<tr style="display:none;"></tr>'); | ||||
|             tb.append(optiontr); | ||||
|             optiontr.append('<td class="label"></td>'); | ||||
|             var btn_additem = $('<span class="sbutton iconadd">Add</span>').click(function () { | ||||
|                 addOption(); | ||||
|             }); | ||||
|             optiontd = $('<td></td>').append(btn_additem); | ||||
|             optiontr.append(optiontd); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="vertical-align:inherit;">Is Required:</td>'); | ||||
|             var table = $('<table></table>'); | ||||
|             tr.append($('<td></td>').append(table)); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             table.append(tr); | ||||
|             isrequiredcontrol = $('<input type="checkbox"/>'); | ||||
|             tr.append($('<td style="width:75px;"></td>').append(isrequiredcontrol)); | ||||
|             cancommentcontrol = $('<input type="checkbox" style="margin-left:10px;"  />'); | ||||
|             tr.append($('<td style="width:155px;"><label style="">Can Comment:</label></td>').append(cancommentcontrol)); | ||||
|             isimportantcontrol = $('<input type="checkbox" style="margin-left:10px;" />'); | ||||
|             tr.append($('<td><label>Is Important:</label></td>').append(isimportantcontrol)); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label">Severity Level:</td>') | ||||
|             severitylevelcontrol = createSeverityLevel(); | ||||
|             tr.append($('<td></td>').append(severitylevelcontrol)); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label">Notes:</td>'); | ||||
|             notescontrol = $('<textarea id="dialog_notes" class="inputbox" maxlength="1000" style="width: 400px; margin-top: 6px;"></textarea>'); | ||||
|             tr.append($('<td></td>').append(notescontrol)); | ||||
|  | ||||
|             return div_main; | ||||
|         } | ||||
|  | ||||
|         var option = function (op) { | ||||
|             this.option = op; | ||||
|             this.dialog_text = null; | ||||
|             this.dialog_bgcolor = null; | ||||
|             this.dialog_severitylevel = null; | ||||
|             this.holder = null; | ||||
|             this.removable = true; | ||||
|             if (op) { | ||||
|                 if (op.removable == false) | ||||
|                     this.removable = false; | ||||
|                 else | ||||
|                     this.removable = true; | ||||
|             } | ||||
|         }; | ||||
|  | ||||
|         option.prototype.getContentValue = function () { | ||||
|             var option = this.option || {}; | ||||
|             option.Text = this.dialog_text.val(); | ||||
|             var texts = this.dialog_text.data("texts"); | ||||
|             if (texts) { | ||||
|                 option.LocalTexts = texts; | ||||
|             } | ||||
|             option.BackgroundColor = this.dialog_bgcolor.val(); | ||||
|             option.SeverityLevel = this.dialog_severitylevel.val(); | ||||
|             return option; | ||||
|         } | ||||
|  | ||||
|         option.prototype.removeOption = function () { | ||||
|             this.holder.remove(); | ||||
|             options.splice(options.indexOf(this), 1); | ||||
|         } | ||||
|  | ||||
|         option.prototype.createContent = function () { | ||||
|             var _thisop = this; | ||||
|             var tb = $('<table style="border: 1px solid #a8a8a8; width:700px;margin-top:2px;"></table>'); | ||||
|             this.holder = tb; | ||||
|             var tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             var optext = $('<input type="text" style="width:240px;margin-left:5px;"/>'); | ||||
|             this.dialog_text = optext; | ||||
|             var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|             addiText.click(function () { | ||||
|                 Common.createMultiTextDialog(optext, _this.question); | ||||
|             }); | ||||
|             tr.append($('<td style="width:295px;"><span class="redasterisk">*</span></td>').append(this.dialog_text).append(addiText)); | ||||
|  | ||||
|             td = $('<td style="width:76px;"></td>'); | ||||
|             tr.append(td); | ||||
|             td.append($('<label>' + GetTextByKey("P_IPT_SEVERITYLEVEL", "Severity Level") + '</label>')); | ||||
|             this.dialog_severitylevel = createSeverityLevel(); | ||||
|             this.dialog_severitylevel.css('width', 100); | ||||
|             tr.append($('<td></td>').append(this.dialog_severitylevel)); | ||||
|             var bg_label = $('<label>' + GetTextByKey("P_IPT_BACKGROUNDCOLOR", "Background Color") + '</label>'); | ||||
|             td = $('<td style="width:100px;"></td>').append(bg_label); | ||||
|             tr.append(td); | ||||
|             this.dialog_bgcolor = $('<input style="width:100px;"/>'); | ||||
|             var bgcolor = $('<div></div>') | ||||
|             bgcolor.append(this.dialog_bgcolor); | ||||
|             td = $('<td></td>').append(bgcolor); | ||||
|             tr.append(td); | ||||
|             initColorCtrl(this.dialog_bgcolor); | ||||
|  | ||||
|             td = $('<td></td>'); | ||||
|             tr.append(td); | ||||
|             if (_thisop.removable) { | ||||
|                 var deleteoptionbtn = $('<em class="spanbtn icondelete"></em>'); | ||||
|                 td.append(deleteoptionbtn.click(function () { | ||||
|                     _thisop.removeOption(); | ||||
|                 })); | ||||
|             } | ||||
|  | ||||
|             if (questiontype === "5") { | ||||
|                 this.dialog_text.attr('disabled', 'disabled'); | ||||
|             } | ||||
|             //else if (questiontype === "8") { | ||||
|             //    bg_label.hide(); | ||||
|             //    bgcolor.hide(); | ||||
|             //    tb.css('width', 324); | ||||
|             //} | ||||
|  | ||||
|  | ||||
|             function updateOptionContent() { | ||||
|                 var op = _thisop.option; | ||||
|                 if (op) { | ||||
|                     _thisop.dialog_text.val(op.Text).data("texts", op.LocalTexts); | ||||
|                     _thisop.dialog_bgcolor.spectrum("set", op.BackgroundColor); | ||||
|                     _thisop.dialog_severitylevel.val(op.SeverityLevel); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             updateOptionContent(); | ||||
|             return tb; | ||||
|         } | ||||
|  | ||||
|         function updateContent() { | ||||
|             var question = _this.question; | ||||
|             if (question) { | ||||
|                 namecontrol.val(question.Name).data("texts", question.LocalNames); | ||||
|                 displaytextcontrol.val(question.DisplayText).data("texts", question.LocalDisplayTexts); | ||||
|                 questiontypecontrol.val(question.QuestionType); | ||||
|                 questionTypeChange(); | ||||
|                 isrequiredcontrol.attr('checked', question.IsRequired); | ||||
|                 cancommentcontrol.attr('checked', question.CanComment); | ||||
|                 isimportantcontrol.attr('checked', question.IsImportant); | ||||
|                 severitylevelcontrol.val(question.SeverityLevel); | ||||
|                 notescontrol.val(question.Notes); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function setDisabled() { | ||||
|             namecontrol.prop('disabled', true); | ||||
|             displaytextcontrol.prop('disabled', true); | ||||
|             questiontypecontrol.prop('disabled', true); | ||||
|             isrequiredcontrol.prop('disabled', true); | ||||
|             cancommentcontrol.prop('disabled', true); | ||||
|             isimportantcontrol.prop('disabled', true); | ||||
|             severitylevelcontrol.prop('disabled', true); | ||||
|             notescontrol.prop('disabled', true); | ||||
|         } | ||||
|  | ||||
|         function questionTypeChange() { | ||||
|             options = []; | ||||
|             optiontd.find('table').remove(); | ||||
|             var type = questiontypecontrol.val(); | ||||
|             questiontype = type; | ||||
|             if (['5', '8', '9'].indexOf(type) >= 0) { | ||||
|                 optiontr.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; | ||||
|                         addOption(op); | ||||
|                     } | ||||
|                     optiontr.find('.sbutton').hide(); | ||||
|                 } | ||||
|                 else { | ||||
|                     optiontr.find('.sbutton').show(); | ||||
|                     if (_this.question) { | ||||
|                         for (var i = 0; i < _this.question.SelectItems.length; i++) { | ||||
|                             addOption(_this.question.SelectItems[i]); | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                         addOption(); | ||||
|                 } | ||||
|             } | ||||
|             else { | ||||
|                 optiontr.hide(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function addOption(item) { | ||||
|             var op = new option(item); | ||||
|             var tb = op.createContent(); | ||||
|             options.push(op); | ||||
|             optiontd.append(tb); | ||||
|         } | ||||
|  | ||||
|         function getData() { | ||||
|             var item = { | ||||
|                 'Name': namecontrol.val(), | ||||
|                 'QuestionType': questiontypecontrol.val(), | ||||
|                 'IsRequired': isrequiredcontrol.prop('checked'), | ||||
|                 'CanComment': cancommentcontrol.prop('checked'), | ||||
|                 'IsImportant': isimportantcontrol.prop('checked'), | ||||
|                 'SeverityLevel': severitylevelcontrol.val(), | ||||
|                 'DisplayText': displaytextcontrol.val(), | ||||
|                 'Notes': notescontrol.val() | ||||
|             }; | ||||
|  | ||||
|             var alerttitle; | ||||
|             if (_this.question) { | ||||
|                 item.Id = _this.question.Id; | ||||
|                 alerttitle = GetTextByKey("P_IPT_EDITQUESTION", "Edit Question"); | ||||
|             } else { | ||||
|                 alerttitle = GetTextByKey("P_IPT_ADDQUESTION", "Add Question"); | ||||
|             } | ||||
|  | ||||
|             var texts = namecontrol.data("texts"); | ||||
|             if (texts) { | ||||
|                 item.LocalNames = texts; | ||||
|             } | ||||
|             texts = displaytextcontrol.data("texts"); | ||||
|             if (texts) { | ||||
|                 item.LocalDisplayTexts = texts; | ||||
|             } | ||||
|  | ||||
|             item.SelectItems = []; | ||||
|             if (options.length > 0) { | ||||
|                 for (var i = 0; i < options.length; i++) { | ||||
|                     var selectitem = options[i].getContentValue(); | ||||
|                     if (!selectitem.Text || selectitem.Text.length == 0) { | ||||
|                         showAlert(GetTextByKey("P_IPT_OPTIONNAMECANNOTBEEMPTY", 'Option name cannot be empty.'), alerttitle); | ||||
|                         return false; | ||||
|                     } | ||||
|                     item.SelectItems.push(selectitem) | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             if (!item.Name || item.Name.length == 0) { | ||||
|                 showAlert(GetTextByKey("P_IPT_NAMENOTBEEMPTY", 'Name cannot be empty.'), alerttitle); | ||||
|                 return false; | ||||
|             } | ||||
|             if (!item.DisplayText || item.DisplayText.length == 0) { | ||||
|                 showAlert(GetTextByKey("P_IPT_DISPLAYTEXTNOTBEEMPTY", 'Display Text cannot be empty.'), alerttitle); | ||||
|                 return false; | ||||
|             } | ||||
|             if ((item.QuestionType === "8" || item.QuestionType === "9") && item.SelectItems.length == 0) { | ||||
|                 showAlert(GetTextByKey("P_IPT_THEREMUSTBEATLEASTONECHOICE", 'There must be at least one choice.'), alerttitle); | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             return item; | ||||
|         } | ||||
|  | ||||
|         saveData = function (exit) { | ||||
|             var item = getData(); | ||||
|             if (!item) return; | ||||
|  | ||||
|             var param = htmlencode(JSON.stringify(item)); | ||||
|             param = JSON.stringify([teamintelligence, _this.sectionid, param]); | ||||
|  | ||||
|             inspectionrequest("SaveGlobalQuestion", param, function (data) { | ||||
|                 if (typeof (data) === "string") { | ||||
|                     showAlert(data, GetTextByKey("P_IPT_SAVEQUESTION", 'Save Question')); | ||||
|                 } else { | ||||
|                     if (!_this.question) { | ||||
|                         _this.question = { 'Id': data[0] }; | ||||
|                     } | ||||
|                     if (exit == 0) { | ||||
|                         _this.datasaved = true; | ||||
|                         showAlert(GetTextByKey("P_IPT_SAVSUCCESSFULLY", 'Saved successfully.'), GetTextByKey("P_IPT_SAVEQUESTION", 'Save Question')); | ||||
|                     } | ||||
|                     if (exit == 1) { | ||||
|                         _this.sectionmodule.refresh(); | ||||
|                         showRightPopup(false); | ||||
|                     } | ||||
|                 } | ||||
|             }, function (err) { | ||||
|                 showAlert(GetTextByKey("P_IPT_FAILEDTOSAVEQUESTION", 'Failed to save question.'), GetTextByKey("P_IPT_SAVEQUESTION", 'Save Question')); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         content.append(createHeader()); | ||||
|         content.append(createQuestionContent()); | ||||
|         updateContent(); | ||||
|         if (templatereadonly) | ||||
|             setDisabled(); | ||||
|         return content; | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     function initColorCtrl(ipt_color) { | ||||
|         ipt_color.spectrum({ | ||||
|             allowEmpty: true, | ||||
|             color: "#FFF", | ||||
|             showInput: true, | ||||
|             containerClassName: "full-spectrum", | ||||
|             showInitial: true, | ||||
|             showPalette: true, | ||||
|             showSelectionPalette: true, | ||||
|             showAlpha: true, | ||||
|             maxPaletteSize: 10, | ||||
|             preferredFormat: "hex", | ||||
|             localStorageKey: "spectrum.demo", | ||||
|             chooseText: GetTextByKey("P_IPT_OK", "OK"), | ||||
|             cancelText: GetTextByKey("P_IPT_CANCEL", "Cancel"), | ||||
|             clearText: GetTextByKey("P_SPECTRUM_CLEARCOLORSELECTION", "Clear Color Selection"), | ||||
|             noColorSelectedText: GetTextByKey("P_SPECTRUM_NOCOLORSELECTED", "No Color Selected"), | ||||
|             move: function (color) { | ||||
|                 if (color) | ||||
|                     ipt_color.val(color.toHexString().toUpperCase()); // #ff0000 | ||||
|             }, | ||||
|             show: function () { | ||||
|  | ||||
|             }, | ||||
|             beforeShow: function () { | ||||
|  | ||||
|             }, | ||||
|             hide: function (color) { | ||||
|                 if (color) { | ||||
|                     ipt_color.val(color.toHexString().toUpperCase()); // #ff0000 | ||||
|                 } | ||||
|             }, | ||||
|  | ||||
|             palette: [ | ||||
|                 ["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)", /*"rgb(153, 153, 153)","rgb(183, 183, 183)",*/ | ||||
|                     "rgb(204, 204, 204)", "rgb(217, 217, 217)", /*"rgb(239, 239, 239)", "rgb(243, 243, 243)",*/ "rgb(255, 255, 255)"], | ||||
|                 ["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)", | ||||
|                     "rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"], | ||||
|                 ["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)", | ||||
|                     "rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)", | ||||
|                     "rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)", | ||||
|                     "rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)", | ||||
|                     "rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)", | ||||
|                     "rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)", | ||||
|                     "rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)", | ||||
|                     "rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)", | ||||
|                     /*"rgb(133, 32, 12)", "rgb(153, 0, 0)", "rgb(180, 95, 6)", "rgb(191, 144, 0)", "rgb(56, 118, 29)", | ||||
|                     "rgb(19, 79, 92)", "rgb(17, 85, 204)", "rgb(11, 83, 148)", "rgb(53, 28, 117)", "rgb(116, 27, 71)",*/ | ||||
|                     "rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)", | ||||
|                     "rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"] | ||||
|             ] | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     function createQuestionType() { | ||||
|         var items = []; | ||||
|         items.push({ 'Key': 0, "Value": "Single Line Text" }); | ||||
|         items.push({ 'Key': 1, "Value": "Multiple Line Text" }); | ||||
|         items.push({ 'Key': 2, "Value": "Email (Manual)" }); | ||||
|         items.push({ 'Key': 14, "Value": "Email (Drop Down)" }); | ||||
|         items.push({ 'Key': 3, "Value": "Number" }); | ||||
|         items.push({ 'Key': 4, "Value": "Integer" }); | ||||
|         items.push({ 'Key': 5, "Value": "Yes Or No" }); | ||||
|         items.push({ 'Key': 6, "Value": "Date" }); | ||||
|         items.push({ 'Key': 7, "Value": "Date And Time" }); | ||||
|         items.push({ 'Key': 8, "Value": "Drop Down" }); | ||||
|         items.push({ 'Key': 9, "Value": "List" }); | ||||
|         items.push({ 'Key': 10, "Value": "Picture" }); | ||||
|         if (!teamintelligence) { | ||||
|             items.push({ 'Key': 11, "Value": "Odometer" }); | ||||
|             items.push({ 'Key': 12, "Value": "Engine Hours" }); | ||||
|             items.push({ 'Key': 13, "Value": "Fuel Remaining" }); | ||||
|         } | ||||
|         var sel = $('<select style="width:324px; height:22px;"></select>'); | ||||
|         for (var i = 0; i < items.length; i++) { | ||||
|             var item = items[i]; | ||||
|             sel.append('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|         } | ||||
|         return sel; | ||||
|     } | ||||
|  | ||||
|     function createSeverityLevel() { | ||||
|         var items = []; | ||||
|         items.push({ 'Key': 0, "Value": "None" }); | ||||
|         items.push({ 'Key': 1, "Value": "Low" }); | ||||
|         items.push({ 'Key': 2, "Value": "Medium" }); | ||||
|         items.push({ 'Key': 3, "Value": "High" }); | ||||
|         var sel = $('<select style="width:324px;height:22px;"></select>'); | ||||
|         for (var i = 0; i < items.length; i++) { | ||||
|             var item = items[i]; | ||||
|             sel.append('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|         } | ||||
|         return sel; | ||||
|     } | ||||
|  | ||||
|     return aq; | ||||
| }); | ||||
							
								
								
									
										186
									
								
								Site/Inspection/js/modules/sections/addsection.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										186
									
								
								Site/Inspection/js/modules/sections/addsection.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,186 @@ | ||||
| define(['common'], function (Common) { | ||||
|     var s = function (gs, section) { | ||||
|         this.section = section; | ||||
|         this.dialog = null; | ||||
|         this.gsmodule = gs; | ||||
|         this.datasaved = false; | ||||
|     }; | ||||
|     s.prototype.description = "Add or edit section"; | ||||
|     s.prototype.version = "1.0.0.0"; | ||||
|     s.prototype.onsave = null; | ||||
|  | ||||
|     var namecontrol = undefined; | ||||
|     var displaytextcontrol = undefined; | ||||
|     var notescontrol = undefined; | ||||
|     s.prototype.createContent = function () { | ||||
|         var _this = this; | ||||
|         editable = true; | ||||
|         var content = $('<div></div>'); | ||||
|  | ||||
|         function createHeader() { | ||||
|             var header = $('<div></div>'); | ||||
|  | ||||
|             var func = $('<div class="function_title"></div>'); | ||||
|             if (sectiontype == 0) { | ||||
|                 var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE","Save") + '</span>').click(function () { | ||||
|                     saveData(0); | ||||
|                 }); | ||||
|                 func.append(btn); | ||||
|                 btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE1", "Save and Exit") + '</span>').click(function () { | ||||
|                     saveData(1); | ||||
|                 }); | ||||
|                 func.append(btn); | ||||
|                 btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_SAVE2", "Exit Without Saving") + '</span>').click(function () { | ||||
|                     showRightPopup(false); | ||||
|                     if (_this.datasaved) | ||||
|                         _this.gsmodule.refresh(); | ||||
|                 }); | ||||
|                 func.append(btn); | ||||
|             } | ||||
|             else { | ||||
|                 header.append($('<div class="function_title" style="background-color:#ddd;font-size:16px;"></div>').text(_this.section ? 'Edit Section' : 'Add Section')); | ||||
|                 if (!templatereadonly && (!_this.section || (_this.section && !_this.section.IsLink))) { | ||||
|                     //if (!_this.section || (_this.section && !_this.section.IsLink)) { | ||||
|                     var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_OK", "OK") + '</span>').click(function () { | ||||
|                         var item = getData(); | ||||
|                         if (!item) | ||||
|                             return; | ||||
|                         if (_this.onsave) | ||||
|                             _this.onsave(item); | ||||
|                         $('#right_popup1').empty().hide(); | ||||
|                     }); | ||||
|                     func.append(btn); | ||||
|                 } | ||||
|                 btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_CANCEL", "Cancel") + '</span>').click(function () { | ||||
|                     $('#right_popup1').empty().hide(); | ||||
|                 }); | ||||
|                 func.append(btn); | ||||
|             } | ||||
|             header.append(func) | ||||
|  | ||||
|             return header; | ||||
|         } | ||||
|  | ||||
|         function createSectionContent() { | ||||
|             var div_main = $('<div class="content_main" style="overflow: auto;"></div>'); | ||||
|             var div_content = $('<div class="edit-content"></div>'); | ||||
|             div_main.append(div_content); | ||||
|             var tb = $('<table style="line-height:40px;"></table>'); | ||||
|             div_content.append(tb); | ||||
|  | ||||
|             var tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="vertical-align:middle;">' + GetTextByKey("P_IPT_NAME_COLON", "Name:") + '<span class="redasterisk">*</span></td>'); | ||||
|             namecontrol = $('<input type="text" maxlength="100" autocomplete="off"/>'); | ||||
|             var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title=""/>'); | ||||
|             addiText.click(function () { | ||||
|                 Common.createMultiTextDialog(namecontrol, _this.section); | ||||
|             }); | ||||
|             tr.append($('<td></td>').append(namecontrol).append(addiText)); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="vertical-align:middle;">' + GetTextByKey("P_IPT_DISPLAYTEXT_COLON", "Display Text:") + '<span class="redasterisk">*</span></td>'); | ||||
|             displaytextcontrol = $('<input type="text" maxlength="200"  autocomplete="off"/>'); | ||||
|             addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|             addiText.click(function () { | ||||
|                 Common.createMultiTextDialog(displaytextcontrol, _this.section); | ||||
|             }); | ||||
|             tr.append($('<td></td>').append(displaytextcontrol).append(addiText)); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label">' + GetTextByKey("P_IPT_NOTES_COLON", "Notes:") + '</td>'); | ||||
|             notescontrol = $('<textarea id="dialog_notes" class="inputbox" maxlength="500" autocomplete="off" style="width: 400px; margin-top: 6px;"></textarea>'); | ||||
|             tr.append($('<td></td>').append(notescontrol)); | ||||
|  | ||||
|             return div_main; | ||||
|         } | ||||
|  | ||||
|         function updateContent() { | ||||
|             var section = _this.section; | ||||
|             if (section) { | ||||
|                 namecontrol.val(section.Name).data("texts", section.LocalNames); | ||||
|                 displaytextcontrol.val(section.DisplayText).data("texts", section.LocalDisplayTexts); | ||||
|                 notescontrol.val(section.Notes); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function setDisabled() { | ||||
|             namecontrol.prop('disabled', true); | ||||
|             displaytextcontrol.prop('disabled', true); | ||||
|             notescontrol.prop('disabled', true); | ||||
|         } | ||||
|  | ||||
|         function getData() { | ||||
|             var item = { | ||||
|                 'Name': namecontrol.val(), | ||||
|                 'DisplayText': displaytextcontrol.val(), | ||||
|                 'Notes': notescontrol.val() | ||||
|             }; | ||||
|             var texts = namecontrol.data("texts"); | ||||
|             if (texts) { | ||||
|                 item.LocalNames = texts; | ||||
|             } | ||||
|             texts = displaytextcontrol.data("texts"); | ||||
|             if (texts) { | ||||
|                 item.LocalDisplayTexts = texts; | ||||
|             } | ||||
|             var alerttitle; | ||||
|             if (_this.section) { | ||||
|                 item.Id = _this.section.Id; | ||||
|                 alerttitle = GetTextByKey("P_IPT_EDITSECTION","Edit Section"); | ||||
|             } else { | ||||
|                 alerttitle = GetTextByKey("P_IPT_ADDSECTION","Add Section"); | ||||
|             } | ||||
|  | ||||
|             if (!item.Name || item.Name.length == 0) { | ||||
|                 showAlert(GetTextByKey("P_IPT_NAMENOTBEEMPTY",'Name cannot be empty.'), alerttitle); | ||||
|                 return false; | ||||
|             } | ||||
|             if (!item.DisplayText || item.DisplayText.length == 0) { | ||||
|                 showAlert(GetTextByKey("P_IPT_DISPLAYTEXTNOTBEEMPTY",'Display Text cannot be empty.'), alerttitle); | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             return item; | ||||
|         } | ||||
|  | ||||
|         function saveData(exit) { | ||||
|             var item = getData(); | ||||
|             if (!item) return; | ||||
|  | ||||
|             var param = JSON.stringify(item); | ||||
|             param = htmlencode(param); | ||||
|             var p = JSON.stringify([teamintelligence, param]); | ||||
|             var alerttitle = GetTextByKey("P_IPT_SAVESECTION", 'Save Section'); | ||||
|             inspectionrequest("SaveGlobalSection", p, function (data) { | ||||
|                 if (typeof (data) === "string") { | ||||
|                     showAlert(data, alerttitle); | ||||
|                 } else { | ||||
|                     if (!_this.section) { | ||||
|                         _this.section = { 'Id': data[0] }; | ||||
|                     } | ||||
|                     if (exit == 0) { | ||||
|                         showAlert(GetTextByKey("P_IPT_SAVSUCCESSFULLY",'Saved successfully.'), alerttitle); | ||||
|                         _this.datasaved = true; | ||||
|                     } | ||||
|                     if (exit == 1) { | ||||
|                         _this.gsmodule.refresh(); | ||||
|                         showRightPopup(false); | ||||
|                     } | ||||
|                 } | ||||
|             }, function (err) { | ||||
|                     showAlert(GetTextByKey("P_IPT_FAILEDTOSAVESECTION",'Failed to save Section.'), alerttitle); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         content.append(createHeader()); | ||||
|         content.append(createSectionContent()); | ||||
|         updateContent(); | ||||
|         if (templatereadonly) | ||||
|             setDisabled(); | ||||
|         return content; | ||||
|     } | ||||
|     return s; | ||||
| }); | ||||
							
								
								
									
										200
									
								
								Site/Inspection/js/modules/sections/option.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										200
									
								
								Site/Inspection/js/modules/sections/option.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,200 @@ | ||||
| define(['common'], function (Common) { | ||||
|     var option = function (q, op) { | ||||
|         this.questionmodule = q; | ||||
|         this.option = op; | ||||
|         this.dialog_text = null; | ||||
|         this.dialog_bgcolor = null; | ||||
|         this.dialog_severitylevel = null; | ||||
|         this.holder = null; | ||||
|         this.texteditable = true; | ||||
|         this.removable = true; | ||||
|         if (op) { | ||||
|             if (op.removable == false) | ||||
|                 this.removable = false; | ||||
|             else | ||||
|                 this.removable = true; | ||||
|         } | ||||
|         this.onremove = null; | ||||
|     }; | ||||
|  | ||||
|     option.prototype.getOptionValue = function () { | ||||
|         var option = this.option || {}; | ||||
|         option.Text = this.dialog_text.val(); | ||||
|         var texts = this.dialog_text.data("texts"); | ||||
|         if (texts) { | ||||
|             option.LocalTexts = texts; | ||||
|         } | ||||
|         option.BackgroundColor = this.dialog_bgcolor.val(); | ||||
|         option.SeverityLevel = this.dialog_severitylevel.val(); | ||||
|         return option; | ||||
|     } | ||||
|  | ||||
|     option.prototype.removeOption = function () { | ||||
|         this.holder.remove(); | ||||
|         if (this.onremove) | ||||
|             this.onremove(this); | ||||
|         this.onsave(); | ||||
|     } | ||||
|  | ||||
|     option.prototype.onsave = function () { | ||||
|         this.questionmodule.onsave(); | ||||
|     } | ||||
|  | ||||
|     option.prototype.createContent = function () { | ||||
|         var _this = this; | ||||
|         var tb = $('<table style="border: 1px solid #a8a8a8; margin-top:2px;line-height:32px;"></table>'); | ||||
|         this.holder = tb; | ||||
|         var tr = $('<tr></tr>'); | ||||
|         tb.append(tr); | ||||
|         var optext = $('<input type="text" class="form-control" style="width:226px;margin-left:5px;"/>'); | ||||
|         this.dialog_text = optext; | ||||
|         var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|         addiText.click(function () { | ||||
|             Common.createMultiTextDialog(optext); | ||||
|         }); | ||||
|         var td = $('<td colspan="2"><span class="redasterisk">*</span></td>'); | ||||
|         td.append(this.dialog_text).append(addiText) | ||||
|         tr.append(td); | ||||
|  | ||||
|         //tr = $('<tr></tr>'); | ||||
|         //tb.append(tr); | ||||
|         td = $('<td style="width:76px;"></td>'); | ||||
|         tr.append(td); | ||||
|         td.append($('<label>' + GetTextByKey("P_IPT_SEVERITYLEVEL", "Severity Level") + '</label>')); | ||||
|         this.dialog_severitylevel = createSeverityLevel().addClass('form-control'); | ||||
|         this.dialog_severitylevel.css('width', 100); | ||||
|         tr.append($('<td></td>').append(this.dialog_severitylevel)); | ||||
|  | ||||
|         //tr = $('<tr></tr>'); | ||||
|         //tb.append(tr); | ||||
|         var bg_label = $('<label>' + GetTextByKey("P_IPT_BACKGROUNDCOLOR", "Background Color") + '</label>'); | ||||
|         td = $('<td style="width:100px;"></td>').append(bg_label); | ||||
|         tr.append(td); | ||||
|         this.dialog_bgcolor = $('<input style="width:100px;"/>'); | ||||
|         var bgcolor = $('<div></div>') | ||||
|         bgcolor.append(this.dialog_bgcolor); | ||||
|         td = $('<td></td>').append(bgcolor); | ||||
|         tr.append(td); | ||||
|         initColorCtrl(this.dialog_bgcolor); | ||||
|  | ||||
|         if (!this.texteditable) { | ||||
|             this.dialog_text.attr('disabled', 'disabled'); | ||||
|         } | ||||
|         if (this.removable) { | ||||
|             td = $('<td style="width:30px;"></td>'); | ||||
|             tr.append(td); | ||||
|             var deleteoptionbtn = $('<em class="spanbtn icondelete"></em>'); | ||||
|             td.append(deleteoptionbtn.click(function () { | ||||
|                 _this.removeOption(); | ||||
|             })); | ||||
|  | ||||
|             if (templatereadonly || !editable) | ||||
|                 deleteoptionbtn.hide(); | ||||
|         } | ||||
|  | ||||
|         function updateOptionContent() { | ||||
|             var op = _this.option; | ||||
|             if (op) { | ||||
|                 _this.dialog_text.val(op.Text).data("texts", op.LocalTexts); | ||||
|                 if (op.BackgroundColor && op.BackgroundColor != '') | ||||
|                     _this.dialog_bgcolor.spectrum("set", op.BackgroundColor); | ||||
|                 _this.dialog_severitylevel.val(op.SeverityLevel); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function controlSaveEvent() { | ||||
|             _this.dialog_text.change(function () { | ||||
|                 _this.onsave(); | ||||
|             }); | ||||
|             _this.dialog_severitylevel.change(function () { | ||||
|                 _this.onsave(); | ||||
|             }); | ||||
|             _this.dialog_bgcolor.change(function () { | ||||
|                 _this.onsave(); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         function setDisabled() { | ||||
|             _this.dialog_text.prop('disabled', true); | ||||
|             _this.dialog_bgcolor.prop('disabled', true); | ||||
|             _this.dialog_severitylevel.prop('disabled', true); | ||||
|         } | ||||
|  | ||||
|         updateOptionContent(); | ||||
|         if (templatereadonly || !editable) | ||||
|             setDisabled(); | ||||
|         controlSaveEvent(); | ||||
|         return tb; | ||||
|     } | ||||
|  | ||||
|     function initColorCtrl(ipt_color) { | ||||
|         ipt_color.spectrum({ | ||||
|             allowEmpty: true, | ||||
|             color: "#FFF", | ||||
|             showInput: true, | ||||
|             containerClassName: "full-spectrum", | ||||
|             showInitial: true, | ||||
|             showPalette: true, | ||||
|             showSelectionPalette: true, | ||||
|             showAlpha: true, | ||||
|             maxPaletteSize: 10, | ||||
|             preferredFormat: "hex", | ||||
|             localStorageKey: "spectrum.demo", | ||||
|             chooseText: GetTextByKey("P_IPT_OK", "OK"), | ||||
|             cancelText: GetTextByKey("P_IPT_CANCEL", "Cancel"), | ||||
|             clearText: GetTextByKey("P_SPECTRUM_CLEARCOLORSELECTION", "Clear Color Selection"), | ||||
|             noColorSelectedText: GetTextByKey("P_SPECTRUM_NOCOLORSELECTED", "No Color Selected"), | ||||
|             disabled: (templatereadonly && !editable), | ||||
|             move: function (color) { | ||||
|                 if (color) | ||||
|                     ipt_color.val(color.toHexString().toUpperCase()); // #ff0000 | ||||
|             }, | ||||
|             show: function () { | ||||
|  | ||||
|             }, | ||||
|             beforeShow: function () { | ||||
|  | ||||
|             }, | ||||
|             hide: function (color) { | ||||
|                 if (color) { | ||||
|                     ipt_color.val(color.toHexString().toUpperCase()); // #ff0000 | ||||
|                 } | ||||
|             }, | ||||
|  | ||||
|             palette: [ | ||||
|                 ["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)", /*"rgb(153, 153, 153)","rgb(183, 183, 183)",*/ | ||||
|                     "rgb(204, 204, 204)", "rgb(217, 217, 217)", /*"rgb(239, 239, 239)", "rgb(243, 243, 243)",*/ "rgb(255, 255, 255)"], | ||||
|                 ["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)", | ||||
|                     "rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"], | ||||
|                 ["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)", | ||||
|                     "rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)", | ||||
|                     "rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)", | ||||
|                     "rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)", | ||||
|                     "rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)", | ||||
|                     "rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)", | ||||
|                     "rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)", | ||||
|                     "rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)", | ||||
|                     /*"rgb(133, 32, 12)", "rgb(153, 0, 0)", "rgb(180, 95, 6)", "rgb(191, 144, 0)", "rgb(56, 118, 29)", | ||||
|                     "rgb(19, 79, 92)", "rgb(17, 85, 204)", "rgb(11, 83, 148)", "rgb(53, 28, 117)", "rgb(116, 27, 71)",*/ | ||||
|                     "rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)", | ||||
|                     "rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"] | ||||
|             ] | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     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 = $('<select style="width:324px;height:22px;"></select>'); | ||||
|         for (var i = 0; i < items.length; i++) { | ||||
|             var item = items[i]; | ||||
|             sel.append('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|         } | ||||
|         return sel; | ||||
|     } | ||||
|  | ||||
|     return option; | ||||
| }); | ||||
							
								
								
									
										940
									
								
								Site/Inspection/js/modules/sections/question.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										940
									
								
								Site/Inspection/js/modules/sections/question.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,940 @@ | ||||
| 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 = $('<div class="questionitem"></div>'); | ||||
|         _this.holder = holder; | ||||
|         var qholder = $('<div class="question-holder"></div>');//question holder | ||||
|         holder.append(qholder); | ||||
|         _this.questionholder = qholder; | ||||
|         var oholder = $('<div style="display:none;"></div>');//option holder | ||||
|         holder.append(oholder); | ||||
|         _this.optionholder = oholder; | ||||
|  | ||||
|         if (this.index % 2 == 1) | ||||
|             qholder.addClass('holder-even'); | ||||
|         var drag = $('<div class="question-icon" style="width:30px;"><em class="spanbtn iconmove rowdrag"></em></div>'); | ||||
|         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('<div class="question-icon" style="width:30px;"><em class="fa"></em></div>'); | ||||
|         _this.txtName = $('<input type="text" class="question-input"  maxlength="100" autocomplete="off" style="width:146px;" />'); | ||||
|         var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|         addiText.click(function () { | ||||
|             Common.createMultiTextDialog(_this.txtName, _this.question); | ||||
|         }); | ||||
|         qholder.append($('<div class="question-cell question-name" style="width: 190px;padding-left:10px;"></div>').append(this.txtName).append(addiText)); | ||||
|  | ||||
|         _this.txtDisplayText = $('<input type="text" class="question-input"  maxlength="200" autocomplete="off" style="width:236px;" />'); | ||||
|         addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|         addiText.click(function () { | ||||
|             Common.createMultiTextDialog(_this.txtDisplayText, _this.question); | ||||
|         }); | ||||
|         var imgicon = $('<span class="spanbtn iconimage" style="font-size:14px;" title="' + GetTextByKey("P_IPT_PICTURES", "Pictures") + '"/>'); | ||||
|         imgicon.click(function (e) { | ||||
|             var picturemodule = new Picture(false, _this.question, function () { _this.onsave() }); | ||||
|             picturemodule.createContent(); | ||||
|             //Common.createImageDialog(_this.txtDisplayText, _this.question); | ||||
|         }); | ||||
|         qholder.append($('<div class="question-cell question-display" style="width: 310px;"></div>').append(this.txtDisplayText).append(addiText).append(imgicon)); | ||||
|  | ||||
|  | ||||
|         //this.selQuestionType<70><65>createQuestionTypeCtrl<72>и<EFBFBD>ֵ | ||||
|         var qt = createQuestionTypeCtrl().css('width', 140); | ||||
|         qholder.append($('<div class="question-cell question-type" style="width: 408px"></div>').append(qt)); | ||||
|         createOptions(); | ||||
|  | ||||
|         _this.chkIsRequired = $('<input type="checkbox" />'); | ||||
|         qholder.append($('<div class="question-cell question-required" style="width: 80px; text-align: center"></div>').append(this.chkIsRequired)); | ||||
|  | ||||
|         _this.chkCanComment = $('<input type="checkbox" />'); | ||||
|         qholder.append($('<div class="question-cell question-comment" style="width: 100px; text-align: center"></div>').append(this.chkCanComment)); | ||||
|  | ||||
|         _this.chkIsImportant = $('<input type="checkbox" />'); | ||||
|         qholder.append($('<div class="question-cell question-important" style="width: 100px; text-align: center"></div>').append(this.chkIsImportant)); | ||||
|  | ||||
|         _this.chkCustomerVisible = $('<input type="checkbox" />'); | ||||
|         qholder.append($('<div class="question-cell question-important" style="width: 140px; text-align: center"></div>').append(this.chkCustomerVisible)); | ||||
|  | ||||
|         _this.selSeverityLevel = createSeverityLevel().addClass('question-input').css('width', 130); | ||||
|         qholder.append($('<div class="question-cell question-security" style="width: 140px"></div>').append(this.selSeverityLevel)); | ||||
|  | ||||
|         _this.txtNotes = $('<textarea class="question-input"  maxlength="500" autocomplete="off" style="width:95%;margin-top:5px;"></textarea>'); | ||||
|         qholder.append($('<div class="question-cell question-notes" style="width: 160px;white-space:normal;"></div>').append(this.txtNotes)); | ||||
|         var funcs = $('<div class="question-cell question-func" style="width: 90px;text-align:right;padding-right:20px;"></div>'); | ||||
|         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('<em class="spanbtn iconlink" style="cursor:default;margin:0;padding-left:0;padding-right:2px;font-size:10px;"></em>'); | ||||
|             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($('<em class="spanbtn iconcopy"></em>').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($('<em class="spanbtn iconedit"></em>').click(function () { | ||||
|             //        _this.onedit(); | ||||
|             //    }).attr('title', 'Edit Question')); | ||||
|             //} | ||||
|             if (!_this.section.IsLink) { | ||||
|                 funcs.append($('<em class="spanbtn icondelete"></em>').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 = $('<table style="line-height:unset;"></table>'); | ||||
|             var tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             var td = $('<td></td>'); | ||||
|             tr.append(td); | ||||
|             _this.selQuestionType = createQuestionType().addClass('question-input'); | ||||
|             td.append(_this.selQuestionType); | ||||
|             _this.selQuestionType.change(function () { | ||||
|                 _this.questionTypeChange(true); | ||||
|             }); | ||||
|  | ||||
|             td = $('<td></td>'); | ||||
|             tr.append(td); | ||||
|             _this.btnoption = $('<span class="spanbtn iconangleleft" style="font-size:18px;"></span>'); | ||||
|             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 = $('<td></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 = $('<td></td>'); | ||||
|             tr.append(td); | ||||
|  | ||||
|             _this.txtTransactionDate = $('<input type="text" class="question-input"  maxlength="20" autocomplete="off" />').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 = $('<td></td>'); | ||||
|             tr.append(td); | ||||
|             _this.txtBarCodeValidate = $('<input type="text" class="question-input"  maxlength="200" autocomplete="off" isValue="0" promptText="' + GetTextByKey("P_IPT_TEXTTOCOMPARE", "Text to compare") + '" style="width:112px;margin-left:3px;" />'); | ||||
|             _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 = $('<table style="line-height:unset;"></table>'); | ||||
|             //_this.multipleselectdiv = $('<span style="margin-left:50px;"><label>Multiple Select:</label></span>'); | ||||
|             //_this.chkMultipleSelect = $('<input type="checkbox" style="margin-left:10px;" />'); | ||||
|             //_this.multipleselectdiv.append(_this.chkMultipleSelect); | ||||
|  | ||||
|             //_this.optiontr = $('<tr style="display:none;"></tr>'); | ||||
|             //tb.append(_this.optiontr); | ||||
|             //var btn_additem = $('<span class="sbutton iconadd">Add Item</span>').click(function () { | ||||
|             //    _this.addOption(); | ||||
|             //}); | ||||
|             //_this.optiontd = $('<td colspan="2"></td>'); | ||||
|             //_this.optiontd.append('<span style="font-weight:bold;margin-right:5px;">Options</span>'); | ||||
|             //_this.optiontd.append(btn_additem); | ||||
|             //_this.optiontd.append(_this.multipleselectdiv); | ||||
|             //_this.optiontr.append(_this.optiontd); | ||||
|             return tb; | ||||
|         } | ||||
|  | ||||
|         function createOptions() { | ||||
|             _this.optiondiv = $('<div style="width:680px;margin-left:540px;padding-left:5px;padding-bottom:5px; border: 1px solid #a8a8a8;line-height:32px;"></div>'); | ||||
|             _this.optionholder.append(_this.optiondiv); | ||||
|             _this.multipleselectdiv = $('<span style="margin-left:50px;"><label>' + GetTextByKey("P_IPT_MULTIPLESELECT_COLON", "Multiple Select:") + '</label></span>'); | ||||
|             _this.chkMultipleSelect = $('<input type="checkbox" style="margin-left:10px;" />'); | ||||
|             _this.multipleselectdiv.append(_this.chkMultipleSelect); | ||||
|             _this.additemspan = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADDITEM", "Add Item") + '</span>').click(function () { | ||||
|                 _this.addOption(); | ||||
|             }); | ||||
|  | ||||
|             _this.lookupsourcespan = $('<span style="margin-left:50px;"><label>' + GetTextByKey("P_IPT_LOOKUPSOURCE_COLON", "Lookup Source:") + '</label></span>'); | ||||
|             _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('<span style="font-weight:bold;margin-right:5px;">' + GetTextByKey("P_IPT_OPTIONS", "Options") + '</span>'); | ||||
|             _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 = $('<select style="width:140px; height:26px;"></select>'); | ||||
|             for (var i = 0; i < items.length; i++) { | ||||
|                 var item = items[i]; | ||||
|                 sel.append('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|             } | ||||
|             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 = $('<select style="width:125px; height:26px;"></select>'); | ||||
|             for (var i = 0; i < items.length; i++) { | ||||
|                 var item = items[i]; | ||||
|                 sel.append('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|             } | ||||
|             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 = $('<select style="width:125px; height:26px;"></select>'); | ||||
|             for (var i = 0; i < items.length; i++) { | ||||
|                 var item = items[i]; | ||||
|                 sel.append('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|             } | ||||
|             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 = $('<select style="width:125px; height:26px;"></select>'); | ||||
|             for (var i = 0; i < items.length; i++) { | ||||
|                 var item = items[i]; | ||||
|                 sel.append('<option value="' + item + '">' + item + '</option>'); | ||||
|             } | ||||
|             return sel; | ||||
|         } | ||||
|  | ||||
|         function createFuelType() { | ||||
|             var sel = $('<select style="width:125px; height:26px;"></select>'); | ||||
|             sel.append('<option value=""></option>'); | ||||
|             if (typeof fuelTypes !== 'undefined') { | ||||
|                 if (fuelTypes && fuelTypes.length > 0) { | ||||
|                     for (var i = 0; i < fuelTypes.length; i++) { | ||||
|                         var item = fuelTypes[i]; | ||||
|                         sel.append('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|                     } | ||||
|                 } | ||||
|                 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('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|                     } | ||||
|                 } | ||||
|                 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 = $('<select style="width:324px;height:26px;"></select>'); | ||||
|             for (var i = 0; i < items.length; i++) { | ||||
|                 var item = items[i]; | ||||
|                 sel.append('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|             } | ||||
|             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 = $('<select style="width:324px;height:26px;"></select>'); | ||||
|             for (var i = 0; i < items.length; i++) { | ||||
|                 var item = items[i]; | ||||
|                 sel.append('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|             } | ||||
|             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; | ||||
| }); | ||||
							
								
								
									
										410
									
								
								Site/Inspection/js/modules/sections/section.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										410
									
								
								Site/Inspection/js/modules/sections/section.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,410 @@ | ||||
| define(['modules/sections/question', 'modules/sections/addsection', 'modules/sections/addquestion', 'common', 'modules/templates/picture'] | ||||
|     , function (Question, AddSection, AddQuestion, Common, Picture) { | ||||
|         var s = function (section, gsm, pm) { | ||||
|             this.section = section; | ||||
|             this.content = null; | ||||
|             this.holder = null; | ||||
|             this.gsmodule = gsm; | ||||
|             this.pagemodule = pm; | ||||
|  | ||||
|             this.txtName = null; | ||||
|             this.txtDisplayText = null; | ||||
|  | ||||
|             if (!this.section.Questions) | ||||
|                 this.section.Questions = []; | ||||
|             this.questionmodules = []; | ||||
|         }; | ||||
|         s.prototype.moduletype = "section"; | ||||
|         s.prototype.description = "Section Module"; | ||||
|         s.prototype.version = "1.0.0.0"; | ||||
|         s.prototype.ondelete = null; | ||||
|  | ||||
|         s.prototype.createContent = function () { | ||||
|             var content = $('<div></div>'); | ||||
|             this.content = content; | ||||
|             var holder = $('<div class="section-holder"></div>'); | ||||
|             content.append(holder); | ||||
|             var _this = this; | ||||
|             if (sectiontype === 0) { | ||||
|                 if (!_this.section.IssueId || _this.section.IssueId == "") | ||||
|                     editable = true; | ||||
|                 else | ||||
|                     editable = false; | ||||
|             } | ||||
|  | ||||
|             if (sectiontype === 0) { | ||||
|                 var package = $('<div class="question-icon section-packages" style="width:30px;padding-left:10px;"><em class="fa icon-menu icon-packages"></em></div>'); | ||||
|                 holder.append(package); | ||||
|             } | ||||
|  | ||||
|             if (sectiontype == 1) { | ||||
|                 var drag = $('<div class="question-icon" style="width:30px;"><em class="spanbtn iconmove rowdrag"></em></div>'); | ||||
|                 holder.append(drag); | ||||
|                 if (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") { | ||||
|                             if (_this.section.IsLink) | ||||
|                                 return; | ||||
|                             $(this).after(draggingobj.holder); | ||||
|                             draggingobj.sectionmodule.dragOutQuestion(draggingobj); | ||||
|                             _this.dragInQuestion(null, draggingobj, true); | ||||
|                         } | ||||
|                         else { | ||||
|                             var t = $(this); | ||||
|                             var after = e.originalEvent.clientY > t.offset().top + t.height() / 2; | ||||
|                             if (after) | ||||
|                                 t.parent().after(draggingobj.holder.parent()); | ||||
|                             else | ||||
|                                 t.parent().before(draggingobj.holder.parent()); | ||||
|  | ||||
|                             draggingobj.pagemodule.dragOutSection(draggingobj); | ||||
|                             _this.pagemodule.dragInSection(_this.section, draggingobj, after); | ||||
|                         } | ||||
|                     }); | ||||
|                 } | ||||
|                 else | ||||
|                     drag.children().remove(); | ||||
|  | ||||
|                 if ((templatereadonly || !editable)) | ||||
|                     drag.hide(); | ||||
|             } | ||||
|  | ||||
|             var btnsection = $('<div class="section-icon" style="width: 30px;"><em class="spanbtn iconangleright" style="font-size:18px;"></em></div>'); | ||||
|             btnsection.click(function () { | ||||
|                 var icon = btnsection.find('.spanbtn'); | ||||
|                 if (icon.hasClass('iconangleright')) { | ||||
|                     icon.removeClass('iconangleright').addClass('iconangledown'); | ||||
|  | ||||
|                     if (sectiontype == 0) { | ||||
|                         _this.getQuestions(); | ||||
|                     } | ||||
|                     else | ||||
|                         _this.updateQuestions(_this.section.Questions); | ||||
|                 } | ||||
|                 else { | ||||
|                     if (sectiontype == 1) | ||||
|                         _this.getSectionValue(true, true); | ||||
|                     icon.removeClass('iconangledown').addClass('iconangleright'); | ||||
|                     _this.content.children('.questionitem').remove(); | ||||
|                 } | ||||
|             }); | ||||
|             holder.append(btnsection); | ||||
|             this.txtName = $('<input type="text" class="section-input"  maxlength="100" autocomplete="off" style="width:156px;" />'); | ||||
|             this.txtName.change(function () { | ||||
|                 _this.onsave(); | ||||
|             }); | ||||
|             var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|             addiText.click(function () { | ||||
|                 Common.createMultiTextDialog(_this.txtName, _this.section); | ||||
|             }); | ||||
|             holder.append($('<div class="section-cell section-name" style="width:200px;flex-grow:0;"></div>').append(this.txtName).append(addiText)); | ||||
|  | ||||
|             this.txtDisplayText = $('<input type="text" class="section-input"  maxlength="200" autocomplete="off" style="width:236px;" />'); | ||||
|             this.txtDisplayText.change(function () { | ||||
|                 _this.onsave(); | ||||
|             }); | ||||
|             addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|             addiText.click(function () { | ||||
|                 Common.createMultiTextDialog(_this.txtDisplayText, _this.section); | ||||
|             }); | ||||
|             var imgicon = $('<span class="spanbtn iconimage" style="font-size:14px;" title="' + GetTextByKey("P_IPT_PICTURES", "Pictures") + '"/>'); | ||||
|             imgicon.click(function (e) { | ||||
|                 var picturemodule = new Picture(false, _this.section, function () { _this.onsave() }); | ||||
|                 picturemodule.createContent(); | ||||
|             }); | ||||
|             holder.append($('<div class="section-cell section-display" style="width:230px;flex-grow: 1;"><span></span></div>').append(this.txtDisplayText).append(addiText).append(imgicon)); | ||||
|             if (sectiontype === 0) | ||||
|                 holder.append($('<div class="section-cell section-createdby" style="text-align:center;"><span></span></div>')); | ||||
|  | ||||
|             var funcs = $('<div class="section-cell section-func" style="width: 120px;text-align:right;padding-right:20px;"></div>'); | ||||
|             holder.append(funcs); | ||||
|  | ||||
|             //holder.find('.section-name span').click(function () { | ||||
|             //    _this.onedit(); | ||||
|             //}); | ||||
|             //holder.find('.section-display span').click(function () { | ||||
|             //    _this.onedit(); | ||||
|             //}); | ||||
|             if (_this.section.IsLink) { | ||||
|                 holder.find('.section-name input').before('<em class="spanbtn iconlink" style="cursor:default;margin:0;padding-left:0;padding-right:2px;font-size:10px;"></em>'); | ||||
|                 holder.find('input').prop('disabled', true); | ||||
|                 holder.find('.iconmultitext').remove(); | ||||
|                 holder.find('.iconimage').remove(); | ||||
|             } | ||||
|  | ||||
|             if (!templatereadonly && editable) { | ||||
|                 if (!_this.section.IsLink) { | ||||
|                     funcs.append($('<em class="spanbtn iconadd"></em>').click(function () { | ||||
|                         //var aq = new AddQuestion(_this, _this.section.Id); | ||||
|                         //if (sectiontype == 0) { | ||||
|                         //    $('#right_popup').empty().append(aq.createContent()); | ||||
|                         //    showRightPopup(true); | ||||
|                         //} | ||||
|                         //else { | ||||
|                         //    aq.onsave = function (question) { | ||||
|                         //        if (!_this.section.Questions) | ||||
|                         //            _this.section.Questions = []; | ||||
|                         //        _this.section.Questions.push(question); | ||||
|  | ||||
|                         //        _this.updateQuestions(_this.section.Questions); | ||||
|                         //    } | ||||
|                         //    $('#right_popup1').empty().append(aq.createContent()).show(); | ||||
|                         //} | ||||
|                         var question = { QuestionType: '0', IsRequired: false, CanComment: false, IsImportant: false, SeverityLevel: 0, LookupSource: 0, SelectItems: [] }; | ||||
|                         _this.section.Questions.push(question); | ||||
|                         _this.addQuestionModule(question); | ||||
|                     }).attr('title', GetTextByKey("P_IPT_ADDQUESTION", 'Add Question'))); | ||||
|                 } | ||||
|                 if (sectiontype == 1 && !_this.section.IsLink) { | ||||
|                     funcs.append($('<em class="spanbtn iconcopy"></em>').click(function () { | ||||
|                         if (_this.oncopy) | ||||
|                             _this.oncopy(_this.getSectionValue(true, true)); | ||||
|                     }).attr('title', GetTextByKey("P_IPT_COPYSECTION", 'Copy Section'))); | ||||
|                 } | ||||
|                 //if (!_this.section.IsLink) { | ||||
|                 //    funcs.append($('<em class="spanbtn iconedit"></em>').click(function () { | ||||
|                 //        _this.onedit(); | ||||
|                 //    }).attr('title', 'Edit Section')); | ||||
|                 //} | ||||
|             } | ||||
|             if ((sectiontype === 0 && !templatereadonly) || (sectiontype === 1 && !templatereadonly && editable)) { | ||||
|                 funcs.append($('<em class="spanbtn icondelete"></em>').click(function () { | ||||
|                     if (sectiontype == 0) { | ||||
|                         _this.delete(); | ||||
|                     } | ||||
|                     else { | ||||
|                         showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISSECTION", 'Are you sure you want to delete this section?'), GetTextByKey("P_IPT_DELETESECTION", 'Delete Section'), function () { | ||||
|                             if (_this.ondelete) { | ||||
|                                 _this.content.remove(); | ||||
|                                 _this.ondelete(_this); | ||||
|                             } | ||||
|                         }); | ||||
|                     } | ||||
|                 }).attr('title', GetTextByKey("P_IPT_DELETESECTION", 'Delete Section'))); | ||||
|             } | ||||
|  | ||||
|             this.holder = holder; | ||||
|             this.updateContent(this.section); | ||||
|             if (sectiontype == 1) | ||||
|                 btnsection.click(); | ||||
|  | ||||
|             //this.holder.find('input').attr('draggable', true).bind('dragstart', function (e) {//<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD> | ||||
|             //    e.originalEvent.preventDefault(); | ||||
|             //}); | ||||
|             if (templatereadonly || !editable) { | ||||
|                 this.txtName.prop('disabled', true); | ||||
|                 this.txtDisplayText.prop('disabled', true); | ||||
|  | ||||
|                 this.holder.find(".iconmultitext").hide(); | ||||
|                 this.holder.find(".iconimage").hide(); | ||||
|             } | ||||
|             return content; | ||||
|         }; | ||||
|         s.prototype.onedit = function () { | ||||
|             var _this = this; | ||||
|             var s = new AddSection(_this.gsmodule, _this.section); | ||||
|             if (sectiontype == 0) { | ||||
|                 $('#right_popup').empty().append(s.createContent()); | ||||
|                 showRightPopup(true); | ||||
|             } | ||||
|             else { | ||||
|                 s.onsave = function (section) { | ||||
|                     _this.section.Name = section.Name; | ||||
|                     _this.section.DisplayText = section.DisplayText; | ||||
|                     _this.section.Notes = section.Notes; | ||||
|                     _this.section.LocalNames = section.LocalNames; | ||||
|                     _this.section.LocalDisplayTexts = section.LocalDisplayTexts; | ||||
|  | ||||
|                     _this.updateContent(_this.section); | ||||
|                 } | ||||
|                 $('#right_popup1').empty().append(s.createContent()).show(); | ||||
|             } | ||||
|         } | ||||
|         s.prototype.updateContent = function (section) { | ||||
|             if (section) { | ||||
|                 if (sectiontype === 0) { | ||||
|                     if (!section.IssueId || section.IssueId == "") { | ||||
|                         this.holder.find('.section-packages em').hide(); | ||||
|                         this.holder.find('.section-createdby span').text(''); | ||||
|                     } | ||||
|                     else { | ||||
|                         this.holder.find('.section-packages em').show(); | ||||
|                         this.holder.find('.section-createdby span').text(section.IssueName); | ||||
|                     } | ||||
|                 } | ||||
|                 this.txtName.val(section.Name).data("texts", section.LocalNames); | ||||
|                 this.txtDisplayText.val(section.DisplayText).data("texts", section.LocalDisplayTexts);; | ||||
|             } | ||||
|         }; | ||||
|         s.prototype.getSectionValue = function (noalert, nocheck) { | ||||
|             var section = this.section; | ||||
|             section.Name = this.txtName.val(); | ||||
|             section.DisplayText = this.txtDisplayText.val(); | ||||
|             var alerttitle = GetTextByKey("P_IPT_SECTION", "Section"); | ||||
|             if (!nocheck) { | ||||
|                 if (!section.Name || section.Name.length == 0) { | ||||
|                     if (!noalert) | ||||
|                         showAlert(GetTextByKey("P_IPT_SETIONNAMENOTBEEMPTY", 'Section Name cannot be empty.'), alerttitle); | ||||
|                     return false; | ||||
|                 } | ||||
|                 if (!section.DisplayText || section.DisplayText.length == 0) { | ||||
|                     if (!noalert) | ||||
|                         showAlert(GetTextByKey("P_IPT_SECTIONDISPLAYTEXTNOTBEEMPTY", 'Section Display Text cannot be empty.'), alerttitle); | ||||
|                     return false; | ||||
|                 } | ||||
|             } | ||||
|             var texts = this.txtName.data("texts"); | ||||
|             if (texts) { | ||||
|                 section.LocalNames = texts; | ||||
|             } | ||||
|             texts = this.txtDisplayText.data("texts"); | ||||
|             if (texts) { | ||||
|                 section.LocalDisplayTexts = texts; | ||||
|             } | ||||
|             section.Questions = []; | ||||
|             if (this.questionmodules.length > 0) { | ||||
|                 for (var i = 0; i < this.questionmodules.length; i++) { | ||||
|                     var q = this.questionmodules[i].getQuestionValue(noalert, nocheck); | ||||
|                     if (!q) return false; | ||||
|                     section.Questions.push(q); | ||||
|                 } | ||||
|             } | ||||
|             return section; | ||||
|         }; | ||||
|         s.prototype.updateQuestions = function (questions) { | ||||
|             if (questions == null) { | ||||
|                 return; | ||||
|             } | ||||
|             this.questionmodules = []; | ||||
|             this.content.children('.question-holder').remove(); | ||||
|             for (var i = 0; i < questions.length; i++) { | ||||
|                 this.addQuestionModule(questions[i]); | ||||
|             } | ||||
|         }; | ||||
|         s.prototype.addQuestionModule = function (q) { | ||||
|             var _this = this; | ||||
|             if (this.section.IsLink) | ||||
|                 q.IsLink = true; | ||||
|             var qmodule = new Question(this, q, this.section.Questions.indexOf(q)); | ||||
|             qmodule.oncopy = function (question) { | ||||
|                 _this.oncopyquestion(question); | ||||
|             } | ||||
|             qmodule.ondelete = function (qm) {//qm:question module | ||||
|                 _this.section.Questions.splice(_this.section.Questions.indexOf(qm.question), 1); | ||||
|                 _this.questionmodules.splice(_this.questionmodules.indexOf(qm), 1); | ||||
|             } | ||||
|             this.questionmodules.push(qmodule); | ||||
|             this.content.append(qmodule.createContent()); | ||||
|         }; | ||||
|         s.prototype.oncopyquestion = function (question) { | ||||
|             question = JSON.parse(JSON.stringify(question)); | ||||
|             question.Id = ""; | ||||
|             //question.IsLink = false; | ||||
|             //question.ReferenceId = ""; | ||||
|             if (!this.section.Questions) | ||||
|                 this.section.Questions = []; | ||||
|             this.section.Questions.push(question); | ||||
|             this.addQuestionModule(question); | ||||
|         }; | ||||
|         s.prototype.getQuestions = function () { | ||||
|             var _this = this; | ||||
|             var p = JSON.stringify([teamintelligence, htmlencode(this.section.Id)]); | ||||
|             inspectionrequest("GetGlobalQuestions", p, function (data) { | ||||
|                 if (data) { | ||||
|                     _this.section.Questions = data; | ||||
|                     _this.content.children('.questionitem').remove(); | ||||
|                     _this.updateQuestions(data); | ||||
|                 } | ||||
|             }, function (err) { | ||||
|             }); | ||||
|         }; | ||||
|         s.prototype.delete = function () { | ||||
|             var _this = this; | ||||
|             showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISSECTION", 'Are you sure you want to delete this section?'), GetTextByKey("P_IPT_DELETESECTION", 'Delete Section'), function () { | ||||
|                 var p = JSON.stringify([teamintelligence, htmlencode(_this.section.Id)]); | ||||
|                 inspectionrequest("DeleteGlobalSection", p, function (data) { | ||||
|                     if (data !== 'OK') | ||||
|                         showAlert(data, GetTextByKey("P_IPT_DELETESECTION", 'Delete Section')); | ||||
|                     else if (_this.gsmodule && typeof _this.gsmodule.refresh === "function") | ||||
|                         _this.gsmodule.refresh(); | ||||
|                 }, function (err) { | ||||
|                     showAlert(GetTextByKey("P_IPT_FAILEDTODELETESECTION", 'Failed to delete section.'), GetTextByKey("P_IPT_DELETESECTION", 'Delete Section')); | ||||
|                 }); | ||||
|             }); | ||||
|         }; | ||||
|         s.prototype.refresh = function () { | ||||
|             var icon = this.content.find('.spanbtn'); | ||||
|             if (icon.hasClass('iconangledown')) { | ||||
|                 this.getQuestions(); | ||||
|             } | ||||
|         }; | ||||
|         s.prototype.dragOutQuestion = function (qm) {//called when question dragged end at question | ||||
|             var index = this.section.Questions.indexOf(qm.question) | ||||
|             if (index >= 0) { | ||||
|                 this.section.Questions.splice(index, 1); | ||||
|                 this.questionmodules.splice(index, 1); | ||||
|             } | ||||
|         }; | ||||
|         s.prototype.dragInQuestion = function (target, qm, after) {//called when question dragged end at question | ||||
|             qm.sectionmodule = this; | ||||
|             qm.section = this.section; | ||||
|             if (!this.section.Questions) | ||||
|                 this.section.Questions = []; | ||||
|             if (this.section.Questions.length == 0) { | ||||
|                 this.section.Questions.push(qm.question); | ||||
|                 this.questionmodules.push(qm); | ||||
|                 return; | ||||
|             } | ||||
|             var tindex = 0; | ||||
|             if (target) { | ||||
|                 tindex = this.section.Questions.indexOf(target); | ||||
|                 if (after) | ||||
|                     tindex = tindex + 1; | ||||
|             } | ||||
|             if (tindex >= 0) { | ||||
|                 this.section.Questions.splice(tindex, 0, qm.question); | ||||
|                 this.questionmodules.splice(tindex, 0, qm); | ||||
|             } | ||||
|         }; | ||||
|         s.prototype.dragInSection = function () {//called when section dragged end at question | ||||
|             this.holder.parent().after(draggingobj.holder.parent()); | ||||
|             draggingobj.pagemodule.dragOutSection(draggingobj); | ||||
|             this.pagemodule.dragInSection(this.section, draggingobj, true); | ||||
|         }; | ||||
|  | ||||
|         s.prototype.onsave = function () { | ||||
|             if (sectiontype == 1) return; | ||||
|             var item = this.getSectionValue(true); | ||||
|             if (!item) return; | ||||
|             var param = JSON.stringify(item); | ||||
|             param = htmlencode(param); | ||||
|             var p = JSON.stringify([teamintelligence, param]); | ||||
|             var _this = this; | ||||
|             inspectionrequest("SaveGlobalSection", p, function (data) { | ||||
|                 if (typeof (data) === "string") { | ||||
|                     showAlert(data, GetTextByKey("P_IPT_SAVESECTION", 'Save Section')); | ||||
|                 } | ||||
|                 else { | ||||
|                     if (!_this.section) | ||||
|                         _this.section = {}; | ||||
|                     _this.section.Id = data[0]; | ||||
|                 } | ||||
|             }, function (err) { | ||||
|                 showAlert(GetTextByKey("P_IPT_FAILEDTOSAVESECTION", 'Failed to save Section.'), GetTextByKey("P_IPT_SAVESECTION", 'Save Section')); | ||||
|             }); | ||||
|         } | ||||
|         return s; | ||||
|     }); | ||||
							
								
								
									
										202
									
								
								Site/Inspection/js/modules/templates.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										202
									
								
								Site/Inspection/js/modules/templates.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,202 @@ | ||||
| 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; | ||||
| }); | ||||
							
								
								
									
										673
									
								
								Site/Inspection/js/modules/templates/addtemplate.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										673
									
								
								Site/Inspection/js/modules/templates/addtemplate.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,673 @@ | ||||
| define(['modules/templates/pages', 'modules/templates/filters', 'modules/templates/picture'], function (Pages, Filters, Picture) { | ||||
|     var s = function (gs, template) { | ||||
|         this.template = template || {}; | ||||
|         currenttemplate = this.template; | ||||
|         this.gsmodule = gs; | ||||
|         this.datasaved = false; | ||||
|         this.content = null; | ||||
|     }; | ||||
|     s.prototype.description = "Add or edit template"; | ||||
|     s.prototype.version = "1.0.0.0"; | ||||
|  | ||||
|     var namecontrol = undefined; | ||||
|     var locationenabledcontrol = undefined; | ||||
|     var needsignaturecontrol = undefined; | ||||
|     var forworkordercontrol = undefined; | ||||
|     var displaycommittimecontrol = undefined; | ||||
|     var displaycommitbycontrol = undefined; | ||||
|     var displayinspectiontitlecontrol = undefined; | ||||
|     var layoutcontrol = undefined; | ||||
|     var lockedcontrol = undefined; | ||||
|     var notescontrol = undefined; | ||||
|     var otheremailcontrol = undefined; | ||||
|     var pages = undefined; | ||||
|     var filtertd = undefined; | ||||
|     var filtersmodule = undefined; | ||||
|     var picturesdiv = undefined; | ||||
|     var picturesadd = undefined; | ||||
|     var grid_contactdt; | ||||
|     var pagesicon = undefined; | ||||
|     var pagescontent = undefined; | ||||
|  | ||||
|  | ||||
|     s.prototype.createContent = function () { | ||||
|         var content = $('<div style="min-width:1350px;"></div>'); | ||||
|         this.content = content; | ||||
|         var _this = this; | ||||
|         function createHeader() { | ||||
|             var header = $('<div></div>'); | ||||
|  | ||||
|             var func = $('<div class="function_title"></div>'); | ||||
|             if (!templatereadonly) { | ||||
|                 var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE", "Save") + '</span>').click(function () { | ||||
|                     onSave(0, 0); | ||||
|                 }); | ||||
|                 func.append(btn); | ||||
|                 btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE1", "Save and Exit") + '</span>').click(function () { | ||||
|                     onSave(1, 0); | ||||
|                 }); | ||||
|                 func.append(btn); | ||||
|                 if ((templatestatus == 0 || (!_this.template.Id && templatestatus == 1)) | ||||
|                     && (!_this.template.Id || _this.template.Editable || IsForesight)) { | ||||
|                     btn = $('<span class="sbutton iconshare">' + GetTextByKey("P_IPT_SAVEANDPUBLISH", "Save and Publish") + '</span>').click(function () { | ||||
|                         onSave(1, 1); | ||||
|                     }); | ||||
|                     func.append(btn); | ||||
|                 } | ||||
|             } | ||||
|             btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_SAVE2", "Exit Without Saving") + '</span>').click(function () { | ||||
|                 showRightPopup(false); | ||||
|                 if (_this.datasaved) | ||||
|                     _this.gsmodule.refresh(); | ||||
|             }); | ||||
|             func.append(btn); | ||||
|             header.append(func) | ||||
|  | ||||
|             return header; | ||||
|         } | ||||
|  | ||||
|         function createTemplateContent() { | ||||
|             var div_main = $('<div class="content_main" style="overflow: auto;margin-top:5px;"></div>'); | ||||
|             var div_content = $('<div class="edit-content"></div>'); | ||||
|             div_main.append(div_content); | ||||
|             var tb = $('<table></table>'); | ||||
|             div_content.append(tb); | ||||
|  | ||||
|             var tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             var td = $('<td class="label" style="width:160px;"></td>'); | ||||
|             tr.append(td); | ||||
|             //tr.append('<td class="label" style="width:100px;">Name:<span class="redasterisk">*</span></td>'); | ||||
|  | ||||
|             var btnsummary = $('<span class="section-icon" style="width:30px;margin-left:8px;margin-right:10px;font-size:18px;color:#666;cursor:pointer;">' + GetTextByKey("P_IPT_SUMMARY", "Summary") + '<em class="spanbtn iconangledown" style="font-size:18px;color:#666;"></em></span>'); | ||||
|             btnsummary.click(function () { | ||||
|                 var icon = btnsummary.find('.spanbtn'); | ||||
|                 if (icon.hasClass('iconangledown')) { | ||||
|                     icon.removeClass('iconangledown').addClass('iconangleright'); | ||||
|                     _this.content.find('.templatetr').hide(); | ||||
|                 } | ||||
|                 else { | ||||
|                     icon.removeClass('iconangleright').addClass('iconangledown'); | ||||
|                     _this.content.find('.templatetr').show(); | ||||
|                 } | ||||
|             }); | ||||
|             td.append(btnsummary).append('<span>' + GetTextByKey("P_IPT_NAME_COLON", "Name:") + '</span><span class="redasterisk">*</span>'); | ||||
|  | ||||
|             namecontrol = $('<input type="text" class="form-control" maxlength="100" autocomplete="off"/>'); | ||||
|             tr.append($('<td></td>').append(namecontrol)); | ||||
|  | ||||
|             tr = $('<tr class="templatetr"></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="width:160px;">' + GetTextByKey("P_IPT_LOCATIONENABLED_COLON", "Location Enabled:") + '</td>'); | ||||
|             locationenabledcontrol = $('<input type="checkbox"/>'); | ||||
|             needsignaturecontrol = $('<input type="checkbox"/>'); | ||||
|             var td = $('<td></td>').append( | ||||
|                 locationenabledcontrol, | ||||
|                 $('<span style="margin-left:40px"></span>').text(GetTextByKey("P_IPT_SIGNATUREREQUIRED_COLON", "Signature Required:")), | ||||
|                 needsignaturecontrol | ||||
|             ); | ||||
|             if (!teamintelligence) { | ||||
|                 td.append($('<span style="margin-left:40px"></span>').text(GetTextByKey("P_IPT_FORWORKORDER_COLON", "For Work Order:"))); | ||||
|                 forworkordercontrol = $('<input type="checkbox"/>'); | ||||
|                 td.append(forworkordercontrol); | ||||
|             } | ||||
|             tr.append(td); | ||||
|  | ||||
|             tr = $('<tr class="templatetr"></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="width:160px;">' + GetTextByKey("P_IPT_XXXXX_COLON", "Display Commit Time:") + '</td>'); | ||||
|             displaycommittimecontrol = $('<input type="checkbox" checked="checked"/>'); | ||||
|             displaycommitbycontrol = $('<input type="checkbox" checked="checked"/>'); | ||||
|             displayinspectiontitlecontrol = $('<input type="checkbox" checked="checked"/>'); | ||||
|             var td = $('<td></td>').append( | ||||
|                 displaycommittimecontrol, | ||||
|                 $('<span style="margin-left:40px"></span>').text(GetTextByKey("P_IPT_XXXXXX_COLON", "Display Commit By:")), | ||||
|                 displaycommitbycontrol, | ||||
|                 $('<span style="margin-left:40px"></span>').text(GetTextByKey("P_IPT_XXXXXX_COLON", "Display Inspection Title:")), | ||||
|                 displayinspectiontitlecontrol | ||||
|             ); | ||||
|             tr.append(td); | ||||
|  | ||||
|             tr = $('<tr class="templatetr"></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append($('<td class="label" style="width:160px;"></td>').text(GetTextByKey("P_LAYOUT_COLON", "Layout:"))); | ||||
|             layoutcontrol = $('<select id="select-layout" class="form-control" style="height: 24px"></select>'); | ||||
|             tr.append($('<td></td>').append(layoutcontrol)); | ||||
|  | ||||
|             if (!teamintelligence) { | ||||
|                 tr = $('<tr class="templatetr" style="height:30px;"></tr>'); | ||||
|                 tb.append(tr); | ||||
|                 tr.append('<td class="label" style="width:160px;vertical-align:top;">' + GetTextByKey("P_IPT_FILTER_COLON", "Filter:") + '</td>') | ||||
|                     .attr("title", GetTextByKey("P_IPT_FILTERTOOLTIPS", "Multiple filters can be applied that act as independent assignments")); | ||||
|                 filtertd = $('<td></td>'); | ||||
|                 tr.append(filtertd); | ||||
|             } | ||||
|  | ||||
|             picturesdiv = $('<div style="width:540px;"><div>'); | ||||
|             tr = $('<tr class="templatetr" style="height:30px;"></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="width:160px;vertical-align:top;">' + GetTextByKey("P_IPT_PICTURE_COLON", "Picture:") + '</td>'); | ||||
|             picturesadd = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADD", "Add") + '</span>').click(function () { | ||||
|                 var picturemodule = new Picture(true, _this.template, setPictures); | ||||
|                 picturemodule.createContent(); | ||||
|             }); | ||||
|             tr.append($('<td></td>').append(picturesadd)); | ||||
|             tr = $('<tr class="templatetr" style="height:30px;"></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="width:160px;vertical-align:top;"></td>'); | ||||
|             tr.append($('<td></td>').append(picturesdiv)); | ||||
|  | ||||
|             if (IsForesight) { | ||||
|                 tr = $('<tr class="templatetr"></tr>'); | ||||
|                 tb.append(tr); | ||||
|                 tr.append('<td class="label" style="width:160px;">' + GetTextByKey("P_IPT_LOCKED_COLON", "Locked:") + '</td>'); | ||||
|                 lockedcontrol = $('<input type="checkbox"/>'); | ||||
|                 lockedcontrol.prop('checked', false); | ||||
|                 tr.append($('<td></td>').append(lockedcontrol)); | ||||
|                 lockedcontrol.click(function () { | ||||
|                     editable = !$(this).prop("checked"); | ||||
|                     _this.template.Editable = editable; | ||||
|                     updateContent(); | ||||
|                 }); | ||||
|             } | ||||
|  | ||||
|             tr = $('<tr class="templatetr"></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="width:160px;">' + GetTextByKey("P_IPT_NOTES_COLON", "Notes:") + '</td>'); | ||||
|             notescontrol = $('<textarea id="dialog_notes" class="inputbox form-control" maxlength="500" autocomplete="off" style="width: 540px; margin-top: 6px;height:80px;"></textarea>'); | ||||
|             tr.append($('<td></td>').append(notescontrol)); | ||||
|  | ||||
|             //Email  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             td = $('<td class="label" style="width:160px;"></td>'); | ||||
|             tr.append(td); | ||||
|             var btnemail = $('<span class="section-icon" style="float:left;width:65px;margin-left:42px;margin-top:10px;margin-right:10px;font-size:18px;color:#666;cursor:pointer;">' + GetTextByKey("P_IPT_EMAIL", "Email") + '<em class="spanbtn iconangledown" style="font-size:18px;color:#666;"></em></span>'); | ||||
|             btnemail.click(function () { | ||||
|                 var icon = btnemail.find('.spanbtn'); | ||||
|                 if (icon.hasClass('iconangledown')) { | ||||
|                     icon.removeClass('iconangledown').addClass('iconangleright'); | ||||
|                     _this.content.find('.emailtd').hide(); | ||||
|                 } | ||||
|                 else { | ||||
|                     icon.removeClass('iconangleright').addClass('iconangledown'); | ||||
|                     _this.content.find('.emailtd').show(); | ||||
|                 } | ||||
|             }); | ||||
|             td.append(btnemail); | ||||
|  | ||||
|             tr.append($('<td class="emailtd"></td>').append(createEmailContent())); | ||||
|  | ||||
|  | ||||
|             return div_main; | ||||
|         } | ||||
|  | ||||
|         function createEmailContent() { | ||||
|             var tb = $('<table style="line-height:25px;margin-top:10px;"></table>'); | ||||
|  | ||||
|             var tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append($('<td>' + GetTextByKey('P_IPT_SENDTHISTO', 'Who do you want to send this to? Select from existing relationships or manual entry.') + '</td>')); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append($('<td></td>').append(InitContactGridData())); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append($('<td>' + GetTextByKey("P_IPT_EMAILADDRESSESTIPS", "Separate multiple manually entered email addresses with a semi-colon (;).") + '</td>')); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             otheremailcontrol = $('<input type="text" class="form-control" maxlength="1000" autocomplete="off" style="margin-left:5px;width: 312px;" autocomplete="off" />'); | ||||
|             tr.append($('<td><span>' + GetTextByKey("P_IPT_OTHEREMAILADDRESS", "Other Email Address") + '</span></td>').append(otheremailcontrol)); | ||||
|  | ||||
|             td = $('<td></td>'); | ||||
|             tr.append(td); | ||||
|  | ||||
|             return tb; | ||||
|         } | ||||
|  | ||||
|         function InitContactGridData() { | ||||
|             var div_grid = $('<div style="width:430px;height:160px;"></div>'); | ||||
|             grid_contactdt = new GridView(div_grid); | ||||
|             grid_contactdt.lang = { | ||||
|                 all: GetTextByKey("P_GRID_ALL", "(All)"), | ||||
|                 ok: GetTextByKey("P_GRID_OK", "OK"), | ||||
|                 reset: GetTextByKey("P_GRID_RESET", "Reset") | ||||
|             }; | ||||
|             var list_columns = [ | ||||
|                 { name: 'UserName', caption: GetTextByKey("P_IPT_CONTACTNAME", "Contact Name"), valueIndex: 'UserName', css: { 'width': 180, 'text-align': 'left' } }, | ||||
|                 { name: 'ContactType', caption: GetTextByKey("P_IPT_CONTACTTYPE", "Contact Type"), valueIndex: 'ContactType', css: { 'width': 180, 'text-align': 'left' } }, | ||||
|                 //{ name: 'Text', caption: "Text", valueIndex: 'Text', type: 3, css: { 'width': 45, 'text-align': 'center' } }, | ||||
|                 { name: 'Selected', caption: GetTextByKey("P_IPT_EMAIL", "Email"), valueIndex: 'Selected', type: 3, css: { 'width': 45, 'text-align': 'center' } } | ||||
|             ]; | ||||
|             var columns = []; | ||||
|             // head | ||||
|             for (var hd in list_columns) { | ||||
|                 var col = {}; | ||||
|                 col.name = list_columns[hd].name; | ||||
|                 col.caption = list_columns[hd].caption; | ||||
|                 col.visible = true; | ||||
|                 col.sortable = true; | ||||
|                 col.width = list_columns[hd].css.width; | ||||
|                 col.align = list_columns[hd].css["text-align"] | ||||
|                 col.key = list_columns[hd].valueIndex; | ||||
|                 if (list_columns[hd].type) { | ||||
|                     col.type = list_columns[hd].type; | ||||
|                 } | ||||
|                 columns.push(col); | ||||
|                 if (col.name === "Email") { | ||||
|                     col.attrs = function (item) { | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             grid_contactdt.canMultiSelect = false; | ||||
|             grid_contactdt.columns = columns; | ||||
|             grid_contactdt.init(); | ||||
|  | ||||
|             grid_contactdt.selectedrowchanged = function (rowindex) { | ||||
|                 var rowdata = grid_contactdt.source[rowindex]; | ||||
|                 if (rowdata) { | ||||
|                 } | ||||
|             } | ||||
|             return div_grid; | ||||
|         } | ||||
|  | ||||
|         function GetInspectEmailList() { | ||||
|             inspectionrequest("GetInspectEmailList", teamintelligence, function (data) { | ||||
|                 if (typeof (data) !== "string") { | ||||
|                     showInspectEmailList(data); | ||||
|                 } | ||||
|             }, function (err) { | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         function getReportLayouts() { | ||||
|             inspectionrequest('GetInspectLayouts', JSON.stringify([teamintelligence ? 1 : 0, '']), function (data) { | ||||
|                 if ($.isArray(data)) { | ||||
|                     var sid = _this.template && _this.template.ReportLayoutId; | ||||
|                     layoutcontrol.empty().append($('<option value=""> </option>').prop('selected', sid == null || sid == '')); | ||||
|                     for (var l of data) { | ||||
|                         layoutcontrol.append($('<option></option>').val(l.Id).text(l.Name).prop('selected', sid == l.Id)); | ||||
|                     } | ||||
|                 } | ||||
|             }, function () { }); | ||||
|         } | ||||
|  | ||||
|         function showInspectEmailList(data) { | ||||
|             var rows = []; | ||||
|             for (var i = 0; i < data.length; i++) { | ||||
|                 var r = data[i]; | ||||
|                 r.Selected = false; | ||||
|                 if (_this.template && _this.template.EmailList) { | ||||
|                     for (var j = 0; j < _this.template.EmailList.length; j++) { | ||||
|                         if (r.UserIID.toLowerCase() == _this.template.EmailList[j].UserIID.toLowerCase()) { | ||||
|                             r.Selected = true; | ||||
|                             break; | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 var fr = { Values: r }; | ||||
|                 rows.push(fr); | ||||
|             } | ||||
|  | ||||
|             grid_contactdt.setData(rows); | ||||
|         } | ||||
|  | ||||
|         function getTemplateInfo(id) { | ||||
|             var p = JSON.stringify([teamintelligence, htmlencode(id)]); | ||||
|             inspectionrequest("GetTemplate", p, function (data) { | ||||
|                 if (typeof (data) !== "string") { | ||||
|                     _this.template = data; | ||||
|                     currenttemplate = _this.template; | ||||
|                     getReportLayouts(); | ||||
|                     GetInspectEmailList(); | ||||
|                     updateContent(); | ||||
|                 } | ||||
|             }, function (err) { | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         function updateContent() { | ||||
|             if (pagesicon) { | ||||
|                 pagesicon.remove(); | ||||
|                 pagesicon = undefined; | ||||
|             } | ||||
|             if (pagescontent) { | ||||
|                 pagescontent.remove(); | ||||
|                 pagescontent = undefined; | ||||
|             } | ||||
|             if (filtertd) | ||||
|                 filtertd.empty(); | ||||
|  | ||||
|             pagesicon = $('<div class="section-icon" style="width:30px;margin:10px 0 5px 15px;font-size:18px;color:#666;">' + GetTextByKey("P_IPT_PAGES", "Pages") + '</div>'); | ||||
|             content.append(pagesicon); | ||||
|             var template = _this.template; | ||||
|  | ||||
|             if (template.Id) { | ||||
|                 if ((!template.IssueId || template.IssueId == "") && (template.Editable)) | ||||
|                     editable = true; | ||||
|                 else | ||||
|                     editable = false; | ||||
|  | ||||
|                 namecontrol.val(template.Name); | ||||
|                 locationenabledcontrol.prop('checked', template.LocationEnabled); | ||||
|                 needsignaturecontrol.prop('checked', template.NeedSignature); | ||||
|                 if (forworkordercontrol) | ||||
|                     forworkordercontrol.prop('checked', template.ForWorkOrder); | ||||
|  | ||||
|                 displaycommittimecontrol.prop('checked', template.DisplayCommitTime); | ||||
|                 displaycommitbycontrol.prop('checked', template.DisplayCommitBy); | ||||
|                 displayinspectiontitlecontrol.prop('checked', template.DisplayInspectionTitle); | ||||
|  | ||||
|                 layoutcontrol.val(template.ReportLayoutId); | ||||
|                 if (IsForesight) { | ||||
|                     lockedcontrol.prop('checked', !template.Editable); | ||||
|                     if (template.IssueId && template.IssueId != "") | ||||
|                         lockedcontrol.prop('disabled', true); | ||||
|                 } | ||||
|  | ||||
|                 notescontrol.val(template.Notes); | ||||
|                 otheremailcontrol.val(template.Emails); | ||||
|                 setPictures(); | ||||
|                 var next = function () { | ||||
|                     pages = new Pages(template.Pages); | ||||
|                     pagescontent = pages.createContent(); | ||||
|                     content.append(pagescontent); | ||||
|                     if (!teamintelligence) { | ||||
|                         filtersmodule = new Filters(template.Filters) | ||||
|                         filtertd.append(filtersmodule.createContent(template)); | ||||
|                     } | ||||
|                 }; | ||||
|                 inspectionrequest("GetFuelTypes", '', function (data) { | ||||
|                     if ($.isArray(data)) { | ||||
|                         window.fuelTypes = data; | ||||
|                     } | ||||
|                     next(); | ||||
|                 }, function () { | ||||
|                     // TODO: network error | ||||
|                 }); | ||||
|             } | ||||
|             else { | ||||
|                 var next = function () { | ||||
|                     pages = new Pages(); | ||||
|                     pagescontent = pages.createContent(); | ||||
|                     content.append(pagescontent); | ||||
|                     if (!teamintelligence) { | ||||
|                         filtersmodule = new Filters() | ||||
|                         filtertd.append(filtersmodule.createContent()); | ||||
|                     } | ||||
|                 }; | ||||
|                 inspectionrequest("GetFuelTypes", '', function (data) { | ||||
|                     if ($.isArray(data)) { | ||||
|                         window.fuelTypes = data; | ||||
|                     } | ||||
|                     next(); | ||||
|                 }, function () { | ||||
|                     // TODO: network error | ||||
|                 }); | ||||
|             } | ||||
|  | ||||
|             setEditable(); | ||||
|         } | ||||
|  | ||||
|         function setPictures() { | ||||
|             $(picturesdiv).empty(); | ||||
|             if (_this.template.StaticPictures && _this.template.StaticPictures.length > 0) { | ||||
|                 for (var i = 0; i < _this.template.StaticPictures.length; i++) { | ||||
|                     var p = _this.template.StaticPictures[i]; | ||||
|                     var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', p.Url).attr('title', p.Name); | ||||
|                     $(picturesdiv).append(img); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function setEditable() { | ||||
|             if (editable) { | ||||
|                 namecontrol.prop('disabled', false); | ||||
|                 locationenabledcontrol.prop('disabled', false); | ||||
|                 needsignaturecontrol.prop('disabled', false); | ||||
|  | ||||
|                 if (forworkordercontrol) | ||||
|                     forworkordercontrol.prop('disabled', false); | ||||
|  | ||||
|                 displaycommittimecontrol.prop('disabled', false); | ||||
|                 displaycommitbycontrol.prop('disabled', false); | ||||
|                 displayinspectiontitlecontrol.prop('disabled', false); | ||||
|  | ||||
|                 layoutcontrol.prop('disabled', false); | ||||
|                 notescontrol.prop('disabled', false); | ||||
|                 picturesadd.show(); | ||||
|             } | ||||
|             else { | ||||
|                 namecontrol.prop('disabled', true); | ||||
|                 locationenabledcontrol.prop('disabled', true); | ||||
|                 needsignaturecontrol.prop('disabled', true); | ||||
|                 if (forworkordercontrol) | ||||
|                     forworkordercontrol.prop('disabled', true); | ||||
|  | ||||
|                 displaycommittimecontrol.prop('disabled', true); | ||||
|                 displaycommitbycontrol.prop('disabled', true); | ||||
|                 displayinspectiontitlecontrol.prop('disabled', true); | ||||
|  | ||||
|                 layoutcontrol.prop('disabled', true); | ||||
|                 notescontrol.prop('disabled', true); | ||||
|                 picturesadd.hide(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function setDisabled() { | ||||
|             namecontrol.prop('disabled', true); | ||||
|             locationenabledcontrol.prop('disabled', true); | ||||
|             needsignaturecontrol.prop('disabled', true); | ||||
|             if (forworkordercontrol) | ||||
|                 forworkordercontrol.prop('disabled', true); | ||||
|  | ||||
|             displaycommittimecontrol.prop('disabled', true); | ||||
|             displaycommitbycontrol.prop('disabled', true); | ||||
|             displayinspectiontitlecontrol.prop('disabled', true); | ||||
|  | ||||
|             layoutcontrol.prop('disabled', true); | ||||
|             notescontrol.prop('disabled', true); | ||||
|             otheremailcontrol.prop('disabled', true); | ||||
|             if (IsForesight) | ||||
|                 lockedcontrol.prop('disabled', true); | ||||
|         } | ||||
|  | ||||
|         function CheckEmail(mail) { | ||||
|             var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; | ||||
|             if (mail.length == 0) | ||||
|                 return true; | ||||
|             return filter.test(mail); | ||||
|         } | ||||
|  | ||||
|         function getSubTypeName(type) { | ||||
|             var typename = ""; | ||||
|             if (type === "0") | ||||
|                 typename = GetTextByKey("P_IPT_ST_TRANSACTIONDATE", "Transaction Date"); | ||||
|             if (type === "1") | ||||
|                 typename = GetTextByKey("P_IPT_ST_TICKETRECEIPTNUMBER", "Ticket/Receipt Number"); | ||||
|             if (type === "2") | ||||
|                 typename = GetTextByKey("P_IPT_ST_DRIVERNAME", "Driver Name"); | ||||
|             else if (type === "3") | ||||
|                 typename = GetTextByKey("P_IPT_ST_RETAILERNAME", "Retailer Name"); | ||||
|             else if (type === "4") | ||||
|                 typename = GetTextByKey("P_IPT_ST_RETAILERADDRESS", "Retailer Address"); | ||||
|             else if (type === "5") | ||||
|                 typename = GetTextByKey("P_IPT_ST_CITY", "City"); | ||||
|             else if (type === "6") | ||||
|                 typename = GetTextByKey("P_IPT_ST_STATE", "State"); | ||||
|             else if (type === "7") | ||||
|                 typename = GetTextByKey("P_IPT_ST_ZIP", "Zip"); | ||||
|             else if (type === "8") | ||||
|                 typename = GetTextByKey("P_IPT_ST_ODOMETER", "Odometer"); | ||||
|             else if (type === "9") | ||||
|                 typename = GetTextByKey("P_IPT_ST_FUELTYPE", "Fuel Type"); | ||||
|             else if (type === "10") | ||||
|                 typename = GetTextByKey("P_IPT_ST_QUANTITY", "Quantity"); | ||||
|             else if (type === "11") | ||||
|                 typename = GetTextByKey("P_IPT_ST_UOMCOST", "Unit Cost"); | ||||
|             else if (type === "12") | ||||
|                 typename = GetTextByKey("P_IPT_ST_TOTALCOST", "Total Cost"); | ||||
|             else if (type === "13") | ||||
|                 typename = GetTextByKey("P_IPT_ST_BRANDNAME", "Brand Name"); | ||||
|             else if (type === "14") | ||||
|                 typename = GetTextByKey("P_IPT_ST_NOTES", "Notes"); | ||||
|             else if (type === "15") | ||||
|                 typename = GetTextByKey("P_IPT_ST_PICTURE", "Picture"); | ||||
|             else if (type === "16") | ||||
|                 typename = GetTextByKey("P_IPT_ST_DISTRIBUTEDBY", "Distributed By"); | ||||
|             return typename; | ||||
|         } | ||||
|  | ||||
|         function onSave(exit, publish) { | ||||
|             var item = { | ||||
|                 'Name': namecontrol.val(), | ||||
|                 'LocationEnabled': locationenabledcontrol.prop('checked'), | ||||
|                 'NeedSignature': needsignaturecontrol.prop('checked'), | ||||
|                 'ReportLayoutId': layoutcontrol.val(), | ||||
|                 'DisplayCommitTime': displaycommittimecontrol.prop('checked'), | ||||
|                 'DisplayCommitBy': displaycommitbycontrol.prop('checked'), | ||||
|                 'DisplayInspectionTitle': displayinspectiontitlecontrol.prop('checked'), | ||||
|                 'Notes': notescontrol.val() | ||||
|             }; | ||||
|             if (forworkordercontrol) | ||||
|                 item.ForWorkOrder = forworkordercontrol.prop('checked'); | ||||
|  | ||||
|             if (teamintelligence) | ||||
|                 item.Target = 1; | ||||
|  | ||||
|             var alerttitle; | ||||
|             if (_this.template.Id) { | ||||
|                 item.Id = _this.template.Id; | ||||
|                 item.Editable = _this.template.Editable; | ||||
|                 item.IssueId = _this.template.IssueId; | ||||
|                 alerttitle = GetTextByKey("P_IPT_EDITTEMPLATE", "Edit Template"); | ||||
|             } else { | ||||
|                 item.Id = -1; | ||||
|                 item.Editable = true; | ||||
|                 alerttitle = GetTextByKey("P_IPT_ADDTEMPLATE", "Add Template"); | ||||
|             } | ||||
|  | ||||
|             if (IsForesight) | ||||
|                 item.Editable = !lockedcontrol.prop('checked'); | ||||
|  | ||||
|             if (publish === 1) | ||||
|                 item.Status = 1; | ||||
|             else if (_this.template && _this.template.Status == 1) | ||||
|                 item.Status = 1; | ||||
|             else | ||||
|                 item.Status = 0; | ||||
|  | ||||
|             if (!item.Name || item.Name.length == 0) { | ||||
|                 showAlert(GetTextByKey("P_IPT_NAMENOTBEEMPTY", 'Name cannot be empty.'), alerttitle); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             //email | ||||
|             var emailaddress = []; | ||||
|             var otheremailaddressstr = otheremailcontrol.val(); | ||||
|             if (otheremailaddressstr !== "") | ||||
|                 emailaddress = otheremailaddressstr.split(';'); | ||||
|             item.Emails = ""; | ||||
|             for (var i = 0; i < emailaddress.length; i++) { | ||||
|                 var email = $.trim(emailaddress[i]); | ||||
|                 if (!CheckEmail(email)) { | ||||
|                     showAlert(GetTextByKey('P_IPT_OTHEREMAILADDRESSISINVALID', 'The other email address {0} is invalid.').replace('{0}', emailaddress[i]), alerttitle); | ||||
|                     return; | ||||
|                 } | ||||
|                 if (item.Emails === "") | ||||
|                     item.Emails = email; | ||||
|                 else | ||||
|                     item.Emails = item.Emails + ";" + email; | ||||
|             } | ||||
|             item.Emails = otheremailaddressstr; | ||||
|             item.EmailList = []; | ||||
|             for (var i = 0; i < grid_contactdt.source.length; i++) { | ||||
|                 var ct = grid_contactdt.source[i].Values; | ||||
|                 if (ct.Selected) | ||||
|                     item.EmailList.push(ct); | ||||
|             } | ||||
|  | ||||
|             if (pages) { | ||||
|                 item.Pages = pages.getPagesValue(); | ||||
|                 if (!item.Pages) | ||||
|                     return; | ||||
|  | ||||
|                 var subtypes = []; | ||||
|                 for (var i = 0; i < item.Pages.length; i++) { | ||||
|                     var page = item.Pages[i]; | ||||
|                     for (var j = 0; j < page.Sections.length; j++) { | ||||
|                         var section = page.Sections[j]; | ||||
|                         for (var k = 0; k < section.Questions.length; k++) { | ||||
|                             var question = section.Questions[k]; | ||||
|                             if (question.QuestionType == "15" && question.SubType !== "15") { | ||||
|                                 var type = question.SubType; | ||||
|  | ||||
|                                 if (subtypes.indexOf(type) >= 0) { | ||||
|                                     var typename = getSubTypeName(type); | ||||
|                                     showAlert(GetTextByKey("P_IPT_ONLYONEQUESTIONCANBEINCLUDEDINTHETEMPLATE", "Only one {0} question can be included in the template.").replace('{0}', typename), GetTextByKey("P_IPT_SAVETEMPLATE", 'Save Template')); | ||||
|                                     return; | ||||
|                                 } | ||||
|                                 else | ||||
|                                     subtypes.push(type); | ||||
|                             } | ||||
|                             if (question.QuestionType == "17" && question.IsRequired == true && (!question.TextToCompare || question.TextToCompare.length == 0)) { | ||||
|                                 showAlert(GetTextByKey("P_IPT_TEXTTPCOMPARENOTBEEMPTY", "Text to compare cannot be empty."), GetTextByKey("P_IPT_SAVETEMPLATE", 'Save Template')); | ||||
|                                 return; | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             item.Filters = []; | ||||
|             if (!teamintelligence && filtersmodule) { | ||||
|                 item.Filters = filtersmodule.getFiltersValue(); | ||||
|             } | ||||
|  | ||||
|             item.StaticPictures = _this.template.StaticPictures; | ||||
|  | ||||
|             var param = JSON.stringify(item); | ||||
|             var p = JSON.stringify([teamintelligence, htmlencode(param)]); | ||||
|  | ||||
|             inspectionrequest("SaveTemplate", p, function (data) { | ||||
|                 if (typeof (data) === "string") { | ||||
|                     showAlert(data, GetTextByKey("P_IPT_SAVETEMPLATE", 'Save Template')); | ||||
|                 } else { | ||||
|                     if (!_this.template.Id) { | ||||
|                         _this.template.Id = data[0]; | ||||
|                     } | ||||
|                     if (exit == 0) { | ||||
|                         showAlert(GetTextByKey("P_IPT_SAVSUCCESSFULLY", 'Saved successfully.'), GetTextByKey("P_IPT_SAVETEMPLATE", 'Save Template')); | ||||
|                         _this.datasaved = true; | ||||
|                     } | ||||
|                     if (exit == 1) { | ||||
|                         _this.gsmodule.refresh(); | ||||
|                         showRightPopup(false); | ||||
|                     } | ||||
|                 } | ||||
|             }, function (err) { | ||||
|                 showAlert(GetTextByKey("P_IPT_FAILEDTOSAVETEMPLATE", 'Failed to save Template.'), GetTextByKey("P_IPT_SAVETEMPLATE", 'Save Template')); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         content.append(createHeader()); | ||||
|         content.append(createTemplateContent()); | ||||
|  | ||||
|         if (this.template.Id) | ||||
|             getTemplateInfo(this.template.Id); | ||||
|         else { | ||||
|             getReportLayouts(); | ||||
|             GetInspectEmailList(); | ||||
|             updateContent(); | ||||
|         } | ||||
|  | ||||
|         if (templatereadonly) | ||||
|             setDisabled(); | ||||
|         return content; | ||||
|     } | ||||
|     return s; | ||||
| }); | ||||
|  | ||||
							
								
								
									
										317
									
								
								Site/Inspection/js/modules/templates/filters.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										317
									
								
								Site/Inspection/js/modules/templates/filters.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,317 @@ | ||||
| define(['common'], function (Common) { | ||||
|     /************filters module***************/ | ||||
|     var addfilterctrl = null; | ||||
|  | ||||
|     var fsm = function (filters) { | ||||
|         this.filters = filters || []; | ||||
|         this.holder = null; | ||||
|         this.filterModules = []; | ||||
|     }; | ||||
|     fsm.prototype.description = "Template filters module"; | ||||
|     fsm.prototype.version = "1.0.0.0"; | ||||
|  | ||||
|     fsm.prototype.createContent = function () { | ||||
|         var _this = this; | ||||
|         this.holder = $('<div></div>'); | ||||
|  | ||||
|         if (!templatereadonly && editable) { | ||||
|             var btnAddfilter = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADD", "Add") + '</span>').click(function () { | ||||
|                 if (!addfilterctrl) | ||||
|                     addfilterctrl = new addfilter(); | ||||
|                 addfilterctrl.beginEdit(null, function (f) { | ||||
|                     _this.showFilter(f); | ||||
|                 }); | ||||
|             }); | ||||
|             this.holder.append($('<div style="margin-top:4px;"></div>').append(btnAddfilter)); | ||||
|         } | ||||
|  | ||||
|         if (this.filters) { | ||||
|             for (var i = 0; i < _this.filters.length; i++) { | ||||
|                 this.showFilter(_this.filters[i]); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return this.holder; | ||||
|     } | ||||
|  | ||||
|     fsm.prototype.getFiltersValue = function () { | ||||
|         var fs = []; | ||||
|         for (var i = 0; i < this.filterModules.length; i++) { | ||||
|             fs.push(this.filterModules[i].getFilterValue()); | ||||
|         } | ||||
|         return fs; | ||||
|     } | ||||
|  | ||||
|     fsm.prototype.showFilter = function (filter) { | ||||
|         var _this = this; | ||||
|         var temp = new fm(filter); | ||||
|         temp.ondelete = function (f) { | ||||
|             _this.filters.splice(_this.filters.indexOf(f.filter), 1); | ||||
|             _this.filterModules.splice(_this.filterModules.indexOf(f), 1); | ||||
|         } | ||||
|         _this.filterModules.push(temp); | ||||
|         this.holder.append(temp.createContent()); | ||||
|     } | ||||
|     /************end filters module***************/ | ||||
|  | ||||
|     /************filter module***************/ | ||||
|     var fm = function (filter) { | ||||
|         this.filter = filter; | ||||
|         this.holder = null; | ||||
|         this.txtvin = null; | ||||
|         this.txtmake = null; | ||||
|         this.txtmodel = null; | ||||
|         this.txttype = null; | ||||
|         this.ondelete = null; | ||||
|     }; | ||||
|     fm.prototype.description = "Template filter module"; | ||||
|     fm.prototype.version = "1.0.0.0"; | ||||
|  | ||||
|     fm.prototype.createContent = function () { | ||||
|         var _this = this; | ||||
|  | ||||
|         var tb = $('<table style="border:1px solid #a8a8a8;margin-top:2px; width:810px;line-height:30px;table-layout:fixed;white-space:nowrap;"></table>'); | ||||
|         _this.holder = tb; | ||||
|         var tr = $('<tr></tr>'); | ||||
|         tb.append(tr); | ||||
|  | ||||
|         tr.append($('<td style="width:90px;text-align:right;">' + GetTextByKey("P_IPT_VINSN_COLON", "VIN/SN:") + '</td>')); | ||||
|         this.txtvin = $('<td style="width:160px;padding-left:5px;overflow:hidden;"></td>'); | ||||
|         tr.append(this.txtvin); | ||||
|  | ||||
|         tr.append($('<td style="width:95px;text-align:right;">' + GetTextByKey("P_IPT_MAKE_COLON", "Make:") + '</td>')); | ||||
|         this.txtmake = $('<td style="width:120px;padding-left:5px;overflow:hidden;"></td>'); | ||||
|         tr.append(this.txtmake); | ||||
|  | ||||
|         tr.append($('<td style="width:100px;text-align:right;">' + GetTextByKey("P_IPT_MODEL_COLON", "Model:") + '</td>')); | ||||
|         this.txtmodel = $('<td style="width:120px;padding-left:5px;overflow:hidden;"></td>'); | ||||
|         tr.append(this.txtmodel); | ||||
|  | ||||
|         tr.append($('<td style="width:115px;text-align:right;">' + GetTextByKey("P_IPT_ASSETTYPE_COLON", "Asset Type:") + '</td>')); | ||||
|         this.txttype = $('<td style="width:120px;padding-left:5px;overflow:hidden;"></td>'); | ||||
|         tr.append(this.txttype); | ||||
|  | ||||
|         var btnedit = $('<em class="spanbtn iconedit"></em>').click(function () { | ||||
|             _this.editFilter(); | ||||
|         }).attr('title', GetTextByKey("P_IPT_EDIT", 'Edit')); | ||||
|  | ||||
|         if (!templatereadonly && editable) { | ||||
|             var btndelete = $('<em class="spanbtn icondelete"></em>').click(function () { | ||||
|                 _this.holder.remove(); | ||||
|                 if (_this.ondelete) | ||||
|                     _this.ondelete(_this); | ||||
|             }).attr('title', GetTextByKey("P_IPT_DELETE", 'Delete')); | ||||
|             tr.append($('<td style="width:55px;"></td>').append(btnedit).append(btndelete)); | ||||
|         } | ||||
|  | ||||
|         tr.append($('<td></td>')); | ||||
|  | ||||
|         this.updateFilterContent(); | ||||
|         return tb; | ||||
|     } | ||||
|     fm.prototype.updateFilterContent = function () { | ||||
|         var flt = this.filter; | ||||
|         if (flt) { | ||||
|             this.txtvin.text(flt.VIN); | ||||
|             this.txtmake.text(flt.MakeName); | ||||
|             this.txtmodel.text(flt.ModelName); | ||||
|             this.txttype.text(flt.TypeName); | ||||
|         } | ||||
|     } | ||||
|     fm.prototype.getFilterValue = function () { | ||||
|         return this.filter; | ||||
|     } | ||||
|     fm.prototype.editFilter = function () { | ||||
|         var _this = this; | ||||
|         if (!addfilterctrl) | ||||
|             addfilterctrl = new addfilter(); | ||||
|         addfilterctrl.beginEdit(_this.filter, function (f) { | ||||
|             _this.filter = f; | ||||
|             _this.updateFilterContent(); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /************end filter module***************/ | ||||
|  | ||||
|  | ||||
|     /************addfilter module***************/ | ||||
|     var addfilter = function () { | ||||
|         this.filter = null; | ||||
|         this.dialog = null; | ||||
|         this.onok = null; | ||||
|  | ||||
|         var txtVIN = null; | ||||
|         var selMake = null; | ||||
|         var selModel = null; | ||||
|         var selType = null; | ||||
|  | ||||
|         var _this = this; | ||||
|  | ||||
|         this.beginEdit = function (filter, onok) { | ||||
|             this.filter = filter; | ||||
|             this.onok = onok; | ||||
|             if (this.filter) { | ||||
|                 txtVIN.val(this.filter.VIN); | ||||
|                 selMake.val(this.filter.AssetMake); | ||||
|                 selModel.val(this.filter.AssetModel); | ||||
|                 selType.val(this.filter.AssetType); | ||||
|             } | ||||
|             else { | ||||
|                 txtVIN.val(''); | ||||
|                 selMake.val('-1'); | ||||
|                 selModel.val('-1'); | ||||
|                 selType.val('-1'); | ||||
|             } | ||||
|             showAssetModels(); | ||||
|  | ||||
|             if (this.dialog) { | ||||
|                 var title = _this.filter ? GetTextByKey("P_IPT_EDITFILTER", 'Edit Filter') : GetTextByKey("P_IPT_ADDFILTER", 'Add Filter'); | ||||
|                 this.dialog.find('.title').text(title); | ||||
|                 this.dialog.showDialogfixed(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         this.createContent = function () { | ||||
|             var tb = $('<table></table>'); | ||||
|             var tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label">' + GetTextByKey("P_IPT_VINSN_COLON", "VIN/SN:") + '</td>'); | ||||
|             txtVIN = $('<input type="text" class="form-control" maxlength="50" autocomplete="off"/>'); | ||||
|             tr.append($('<td></td>').append(txtVIN)); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label">' + GetTextByKey("P_IPT_MAKE_COLON", "Make:") + '</td>'); | ||||
|             selMake = $('<select class="form-control" style="width:204px;height:22px;"></select>'); | ||||
|             tr.append($('<td></td>').append(selMake)); | ||||
|             selMake.change(function () { | ||||
|                 showAssetModels(); | ||||
|             }); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label">' + GetTextByKey("P_IPT_MODEL_COLON", "Model:") + '</td>'); | ||||
|             selModel = $('<select class="form-control" style="width:204px;height:22px;"></select>'); | ||||
|             tr.append($('<td></td>').append(selModel)); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label">' + GetTextByKey("P_IPT_ASSETTYPE_COLON", "Asset Type:") + '</td>'); | ||||
|             selType = $('<select class="form-control" style="width:204px;height:22px;"></select>'); | ||||
|             tr.append($('<td></td>').append(selType)); | ||||
|  | ||||
|             getAssetMakes(); | ||||
|             getAssetModels(); | ||||
|             getAssetTypes(); | ||||
|  | ||||
|             function OnSave() { | ||||
|                 var item = { | ||||
|                     'VIN': $.trim(txtVIN.val()), | ||||
|                     'AssetMake': selMake.val(), | ||||
|                     'MakeName': selMake.find("option:selected").text(), | ||||
|                     'AssetModel': selModel.val(), | ||||
|                     'ModelName': selModel.find("option:selected").text(), | ||||
|                     'AssetType': selType.val(), | ||||
|                     'TypeName': selType.find("option:selected").text() | ||||
|                 }; | ||||
|                 if (!item.AssetMake || item.AssetMake == '') | ||||
|                     item.AssetMake = '-1'; | ||||
|                 if (!item.AssetModel || item.AssetModel == '') | ||||
|                     item.AssetModel = '-1'; | ||||
|                 if (!item.AssetType || item.AssetType == '') | ||||
|                     item.AssetType = '-1'; | ||||
|                 if (_this.onok) | ||||
|                     _this.onok(item); | ||||
|                 _this.dialog.hideDialog(); | ||||
|             } | ||||
|  | ||||
|             this.dialog = Common.createDialog('', tb, OnSave, false); | ||||
|         } | ||||
|         this.createContent(); | ||||
|  | ||||
|         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() { | ||||
|             selMake.append('<option value="-1">*</option>'); | ||||
|             if (makesdata && makesdata.length > 0) { | ||||
|                 for (var i = 0; i < makesdata.length; i++) { | ||||
|                     var item = makesdata[i]; | ||||
|                     selMake.append('<option value="' + item.ID + '">' + item.Name + '</option>'); | ||||
|                 } | ||||
|                 if (_this.filter) { | ||||
|                     selMake.val(_this.filter.AssetMake); | ||||
|                     showAssetModels(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function showAssetModels() { | ||||
|             selModel.empty(); | ||||
|             var makeid = selMake.val(); | ||||
|             selModel.append('<option value="-1">*</option>'); | ||||
|             if (!makeid || makeid == "-1") | ||||
|                 selModel.prop('disabled', true); | ||||
|             else | ||||
|                 selModel.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)) { | ||||
|                         selModel.append('<option value="' + item.ID + '">' + item.Name + '</option>'); | ||||
|                     } | ||||
|                 } | ||||
|                 if (_this.filter) | ||||
|                     selModel.val(_this.filter.AssetModel); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function showAssetTypes() { | ||||
|             selType.append('<option value="-1">*</option>'); | ||||
|             if (typesdata && typesdata.length > 0) { | ||||
|                 for (var i = 0; i < typesdata.length; i++) { | ||||
|                     var item = typesdata[i]; | ||||
|                     selType.append('<option value="' + item.Key + '">' + item.Value + '</option>'); | ||||
|                 } | ||||
|                 if (_this.filter) | ||||
|                     selType.val(_this.filter.AssetType); | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
|     /************end addfilter module***************/ | ||||
|  | ||||
|     return fsm; | ||||
| }); | ||||
							
								
								
									
										165
									
								
								Site/Inspection/js/modules/templates/linksection.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										165
									
								
								Site/Inspection/js/modules/templates/linksection.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,165 @@ | ||||
| define(['common'], function (Common) { | ||||
|  | ||||
|     var dialogSection = null; | ||||
|     var ls = function () { | ||||
|     }; | ||||
|  | ||||
|     ls.prototype.getDialogSection = function () { | ||||
|         if (!dialogSection) | ||||
|             dialogSection = new $sectionselector(); | ||||
|         return dialogSection; | ||||
|     } | ||||
|  | ||||
|     var $sectionselector = function () { | ||||
|         this.title = GetTextByKey("P_IPT_SELECTSECTION", 'Select Section'); | ||||
|         this.companyId = null; | ||||
|         this.exceptSource = null; | ||||
|         this.onOK = null; | ||||
|         this.onDialogClosed = null; | ||||
|     }; | ||||
|  | ||||
|     (function () { | ||||
|         var __proto = $sectionselector.prototype; | ||||
|  | ||||
|         function initGrid(parent) { | ||||
|             var grid = new GridView(parent); | ||||
|             var columns = []; | ||||
|             columns.push({ | ||||
|                 // checkbox | ||||
|                 name: 'check', | ||||
|                 key: 'Selected', | ||||
|                 width: 30, | ||||
|                 align: 'center', | ||||
|                 sortable: false, | ||||
|                 allcheck: true, | ||||
|                 type: 3 | ||||
|             }); | ||||
|             columns.push({ | ||||
|                 key: 'Name', | ||||
|                 caption: GetTextByKey("P_IPT_NAME", 'Name'), | ||||
|                 width: 200 | ||||
|             }, | ||||
|                 { | ||||
|                     key: 'DisplayText', | ||||
|                     caption: GetTextByKey("P_IPT_DISPLAYTEXT", 'DisplayText'), | ||||
|                     width: 320 | ||||
|                 }); | ||||
|             //grid.canMultiSelect = true; | ||||
|             grid.columns = columns; | ||||
|             grid.init(); | ||||
|  | ||||
|             this.gridctrl = grid; | ||||
|         } | ||||
|  | ||||
|         function createDialog() { | ||||
|             var dialog = $('<div class="dialog" style="display: none; width: 602px; height: 380px">'); | ||||
|  | ||||
|             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); | ||||
|  | ||||
|             this.listdiv = $('<div style="width: 580px; height: 290px;margin-bottom:5px;"></div>').appendTo(content); | ||||
|  | ||||
|             var dialogFunction = $('<div class="dialog-func"></div>').appendTo(dialog); | ||||
|             $('<input type="button" value="' + GetTextByKey("P_IPT_CANCEL", "Cancel") + '" class="dialog-close" />').appendTo(dialogFunction); | ||||
|             $('<input type="button" value="' + GetTextByKey("P_IPT_COPY", "Copy") + '" />').click(onCopyClick.bind(this)).appendTo(dialogFunction); | ||||
|             $('<input type="button" value="' + GetTextByKey("P_IPT_ADDASLINK", "Add as Link") + '" />').click(onLinkClick.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 | ||||
|             initGrid.call(this, this.listdiv); | ||||
|             $(document.body).append(dialog); | ||||
|             var mask = $('<div class="maskbg"></div>'); | ||||
|             dialog.data('mask', mask); | ||||
|             dialog.before(mask); | ||||
|  | ||||
|             var _this = this; | ||||
|             dialog.dialog(function () { | ||||
|                 if (_this.onDialogClosed) | ||||
|                     _this.onDialogClosed(); | ||||
|                 if (dialog.data('mask')) | ||||
|                     dialog.data('mask').hide(); | ||||
|             }); | ||||
|             return dialog; | ||||
|         } | ||||
|  | ||||
|         __proto.showSelector = function () { | ||||
|             if (!this.dialog) { | ||||
|                 this.dialog = createDialog.call(this); | ||||
|             } | ||||
|  | ||||
|             if (this.dialog.data('mask')) | ||||
|                 this.dialog.data('mask').show(); | ||||
|             this.dialog.showDialog(false); | ||||
|             this.gridctrl.setData([]); | ||||
|             onSearch.call(this); | ||||
|         }; | ||||
|  | ||||
|         function onKeyPress(e) { | ||||
|             if (e.keyCode === 13) { | ||||
|                 onSearch.call(this); | ||||
|             } | ||||
|         }; | ||||
|  | ||||
|         function excepted(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 excepts = this.exceptSource; | ||||
|             var gridctrl = this.gridctrl; | ||||
|             var title = this.title; | ||||
|             var companyId = this.companyId || ''; | ||||
|  | ||||
|             inspectionrequest("GetGlobalSections", teamintelligence, function (data) { | ||||
|                 if (typeof data === 'string') { | ||||
|                     showAlert(GetTextByKey("P_IPT_FAILEDTOGETTHESECTIONS", 'Failed to get the sections: ') + data, title); | ||||
|                     maskbg.hide(); | ||||
|                     return; | ||||
|                 } | ||||
|                 var items = []; | ||||
|                 for (var i = 0; i < data.length; i++) { | ||||
|                     var it = data[i]; | ||||
|                     if (excepts == null || !excepted(it.Id, excepts)) { | ||||
|                         items.push({ Values: it }); | ||||
|                     } | ||||
|                 } | ||||
|                 gridctrl.setData(items); | ||||
|                 maskbg.hide(); | ||||
|             }, function (err) { | ||||
|                     showAlert(GetTextByKey("P_IPT_FAILEDTOGETTHESECTIONS1",'Failed to get the sections.'), title); | ||||
|                 maskbg.hide(); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         function onCopyClick() { | ||||
|             //var index = this.gridctrl.selectedIndex; | ||||
|             this.onOK && this.onOK(this.gridctrl.source, true); | ||||
|             if (this.dialog.data('mask')) | ||||
|                 this.dialog.data('mask').hide(); | ||||
|             this.dialog.hideDialog(); | ||||
|         } | ||||
|  | ||||
|         function onLinkClick() { | ||||
|             //var index = this.gridctrl.selectedIndex; | ||||
|             this.onOK && this.onOK(this.gridctrl.source, false); | ||||
|             if (this.dialog.data('mask')) | ||||
|                 this.dialog.data('mask').hide(); | ||||
|             this.dialog.hideDialog(); | ||||
|         } | ||||
|     })(); | ||||
|  | ||||
|     return ls; | ||||
| }); | ||||
							
								
								
									
										313
									
								
								Site/Inspection/js/modules/templates/page.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										313
									
								
								Site/Inspection/js/modules/templates/page.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,313 @@ | ||||
| define(['modules/sections/section', 'modules/sections/addsection', 'common', 'modules/templates/linksection'], function (Section, AddSection, Common, LinkSection) { | ||||
|     var p = function (page, pagesmodule) { | ||||
|         this.page = page || {}; | ||||
|         this.pagesmodule = pagesmodule; | ||||
|         this.namecontrol = undefined; | ||||
|         this.displaytextcontrol = undefined; | ||||
|         this.notescontrol = undefined; | ||||
|         this.onNameChanged = undefined; | ||||
|         this.datacontent = null; | ||||
|  | ||||
|         this.sectionmodules = []; | ||||
|     }; | ||||
|     p.prototype.description = "Page"; | ||||
|     p.prototype.version = "1.0.0.0"; | ||||
|  | ||||
|     p.prototype.createContent = function () { | ||||
|         var _this = this; | ||||
|         var content = $('<div></div>'); | ||||
|  | ||||
|         function createPageContent() { | ||||
|             var div_main = $('<div class="content_main"></div>'); | ||||
|             var div_content = $('<div class="edit-content"></div>'); | ||||
|             div_main.append(div_content); | ||||
|             var tb = $('<table></table>'); | ||||
|             div_content.append(tb); | ||||
|  | ||||
|             var tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="width:154px;">' + GetTextByKey("P_IPT_NAME_COLON", "Name:") + '<span class="redasterisk">*</span></td>'); | ||||
|             _this.namecontrol = $('<input type="text" class="form-control" maxlength="100" autocomplete="off"/>'); | ||||
|             var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|             addiText.click(function () { | ||||
|                 Common.createMultiTextDialog(_this.namecontrol); | ||||
|             }); | ||||
|             tr.append($('<td style="white-space:nowrap;"></td>').append(_this.namecontrol).append(addiText)); | ||||
|             _this.namecontrol.change(function () { | ||||
|                 if (_this.onNameChanged) | ||||
|                     _this.onNameChanged($.trim(_this.namecontrol.val())) | ||||
|             }) | ||||
|  | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="width:154px;">' + GetTextByKey("P_IPT_NOTES_COLON", "Notes:") + '</td>'); | ||||
|             _this.notescontrol = $('<textarea id="dialog_notes" class="inputbox form-control" maxlength="500" autocomplete="off" style="width: 540px; margin-top:6px;height:55px;"></textarea>'); | ||||
|             tr.append($('<td rowspan="2"></td>').append(_this.notescontrol)); | ||||
|  | ||||
|             tr = $('<tr></tr>'); | ||||
|             tb.append(tr); | ||||
|             tr.append('<td class="label" style="width:154px;">' + GetTextByKey("P_IPT_DISPLAYTEXT_COLON", "Display Text:") + '<span class="redasterisk">*</span></td>'); | ||||
|             _this.displaytextcontrol = $('<input type="text" class="form-control" maxlength="200" autocomplete="off"/>'); | ||||
|             addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>'); | ||||
|             addiText.click(function () { | ||||
|                 Common.createMultiTextDialog(_this.displaytextcontrol); | ||||
|             }); | ||||
|             tr.append($('<td style="white-space:nowrap;"></td>').append(_this.displaytextcontrol).append(addiText)); | ||||
|  | ||||
|             var sectioncontent = createSectionContent(); | ||||
|             div_main.append(sectioncontent); | ||||
|             return div_main; | ||||
|         } | ||||
|  | ||||
|         function createSectionContent() { | ||||
|             var content = $('<div style="min-width:1820px;"></div>'); | ||||
|  | ||||
|             function createSectionHeader() { | ||||
|                 var header = $('<div></div>'); | ||||
|                 //header.append($('<div class="page_title"></div>').text(gs.title)); | ||||
|                 var func = $('<div class="function_title"></div>'); | ||||
|                 var iconAdd = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADD", "Add") + '</span>').click(function () { | ||||
|                     //var s = new AddSection(); | ||||
|                     //s.onsave = function (section) { | ||||
|                     //    _this.page.Sections.push(section); | ||||
|                     //    updateContent(true); | ||||
|                     //} | ||||
|                     //$('#right_popup1').empty().append(s.createContent()).show(); | ||||
|                     var section = {}; | ||||
|                     _this.page.Sections.push(section); | ||||
|                     addSectionModule(section); | ||||
|                 }); | ||||
|                 func.append(iconAdd); | ||||
|                 var iconRefresh = $('<span class="sbutton iconlink">' + GetTextByKey("P_ADDGLOBALSECTION", "Add Global Section") + '</span>').click(function () { | ||||
|                     addGlobalSection(); | ||||
|                 }); | ||||
|                 func.append(iconRefresh); | ||||
|                 header.append(func) | ||||
|  | ||||
|                 return header; | ||||
|             } | ||||
|  | ||||
|             if (!templatereadonly && editable) | ||||
|                 content.append(createSectionHeader()); | ||||
|  | ||||
|             var dataheader = $('<div class="question-holder no-hover" style="font-weight: bold;font-size:14px;"></div>'); | ||||
|             dataheader.append('<div style="width: 60px; flex-shrink: 0"></div>'); | ||||
|             dataheader.append('<div class="question-cell" style="width: 200px">' + GetTextByKey("P_IPT_NAME", "Name") + '</div>'); | ||||
|             dataheader.append('<div class="question-cell" style="width: 310px">' + GetTextByKey("P_IPT_DISPLAYTEXT", "Display Text") + '</div>'); | ||||
|             dataheader.append('<div class="question-cell" style="width: 400px">' + GetTextByKey("P_IPT_TYPE", "Type") + '</div>'); | ||||
|             dataheader.append('<div class="question-cell" style="width: 80px; text-align: center">' + GetTextByKey("P_IPT_REQUIRED", "Required") + '</div>'); | ||||
|             dataheader.append('<div class="question-cell" style="width: 100px; text-align: center">' + GetTextByKey("P_IPT_CANCOMMENT", "Can Comment") + '</div>'); | ||||
|             dataheader.append('<div class="question-cell" style="width: 100px; text-align: center">' + GetTextByKey("P_IPT_ISIMPORTANT", "Is Important") + '</div>'); | ||||
|             dataheader.append('<div class="question-cell" style="width: 140px">' + GetTextByKey("P_IPT_CUSTOMERVISIBLE", "Customer Visible") + '</div>'); | ||||
|             dataheader.append('<div class="question-cell" style="width: 140px">' + GetTextByKey("P_IPT_SEVERITYLEVEL", "Severity Level") + '</div>'); | ||||
|             dataheader.append('<div style="flex-grow: 1" style="width: 160px">' + GetTextByKey("P_IPT_ST_NOTES", "Notes") + '</div>'); | ||||
|             dataheader.append('<div class="question-cell" style="width: 90px;padding-right:20px;"></div>'); | ||||
|             content.append(dataheader); | ||||
|  | ||||
|             _this.datacontent = $('<div></div>'); | ||||
|             content.append(_this.datacontent); | ||||
|  | ||||
|             return content; | ||||
|         } | ||||
|  | ||||
|         function updateContent(sectiononly) { | ||||
|             if (!sectiononly) { | ||||
|                 _this.namecontrol.val(_this.page.Name).data("texts", _this.page.LocalNames); | ||||
|                 _this.displaytextcontrol.val(_this.page.DisplayText).data("texts", _this.page.LocalDisplayTexts); | ||||
|                 _this.notescontrol.val(_this.page.Notes); | ||||
|             } | ||||
|  | ||||
|             if (_this.page.Sections) { | ||||
|                 _this.sectionmodules = []; | ||||
|                 _this.datacontent.empty(); | ||||
|                 for (var i = 0; i < _this.page.Sections.length; i++) { | ||||
|                     //var s = new Section(_this.page.Sections[i], null, _this); | ||||
|                     addSectionModule(_this.page.Sections[i]); | ||||
|                 } | ||||
|             } else | ||||
|                 _this.page.Sections = []; | ||||
|         } | ||||
|  | ||||
|         function addSectionModule(s) { | ||||
|             var sectionmodule = new Section(s, null, _this); | ||||
|             sectionmodule.oncopy = function (section) { | ||||
|                 section = JSON.parse(JSON.stringify(section)); | ||||
|                 section.Id = ""; | ||||
|                 if (!section.IsLink && section.Questions) { | ||||
|                     for (var j = 0; j < section.Questions.length; j++) { | ||||
|                         section.Questions[j].Id = ""; | ||||
|                     } | ||||
|                 } | ||||
|                 _this.page.Sections.push(section); | ||||
|                 addSectionModule(section); | ||||
|             }; | ||||
|             sectionmodule.ondelete = function (sm) { | ||||
|                 _this.page.Sections.splice(_this.page.Sections.indexOf(sm.section), 1); | ||||
|                 _this.sectionmodules.splice(_this.sectionmodules.indexOf(sm), 1); | ||||
|             } | ||||
|             _this.sectionmodules.push(sectionmodule); | ||||
|             _this.datacontent.append(sectionmodule.createContent()); | ||||
|         } | ||||
|  | ||||
|         function setDisabled() { | ||||
|             _this.namecontrol.prop('disabled', true); | ||||
|             _this.displaytextcontrol.prop('disabled', true); | ||||
|             _this.notescontrol.prop('disabled', true); | ||||
|  | ||||
|             content.find(".iconmultitext").hide(); | ||||
|             content.find(".iconimage").hide(); | ||||
|         } | ||||
|  | ||||
|         function addGlobalSection() {//<2F><><EFBFBD><EFBFBD>Global Section | ||||
|             var dialogSection = new LinkSection().getDialogSection(); | ||||
|  | ||||
|             dialogSection.onDialogClosed = function () { | ||||
|             } | ||||
|             dialogSection.onOK = function (sections, iscopy) { | ||||
|                 if (!iscopy) { | ||||
|                     var linkedSectionIds = []; | ||||
|                     if (_this.pagesmodule && _this.pagesmodule.pages) { | ||||
|                         for (var i = 0; i < _this.pagesmodule.pages.length; i++) { | ||||
|                             var page = _this.pagesmodule.pages[i]; | ||||
|                             if (page.Sections) { | ||||
|                                 for (var j = 0; j < page.Sections.length; j++) { | ||||
|                                     var s = page.Sections[j]; | ||||
|                                     if (s.IsLink) | ||||
|                                         linkedSectionIds.push(s.ReferenceId); | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     if (sections && sections.length > 0) { | ||||
|                         for (var i = 0; i < sections.length; i++) { | ||||
|                             var it = sections[i].Values; | ||||
|                             if (it.Selected && linkedSectionIds.indexOf(it.Id) >= 0) { | ||||
|                                 showAlert(GetTextByKey("P_IPT_ALREADYLINKED", '{0} has already been linked to current template.').replace("{0}", it.Name), GetTextByKey("P_ADDGLOBALSECTION", "Add Global Section")); | ||||
|                                 return; | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 onAddGlobalSection(sections, iscopy); | ||||
|             } | ||||
|  | ||||
|             //var sections = []; | ||||
|             //for (var i = 0; i < _this.page.Sections.length; i++) { | ||||
|             //    if (_this.page.Sections[i].IsLink) | ||||
|             //        sections.push(_this.page.Sections[i].ReferenceId); | ||||
|             //} | ||||
|  | ||||
|             //dialogSection.exceptSource = sections; | ||||
|             dialogSection.showSelector(); | ||||
|         } | ||||
|  | ||||
|         function onAddGlobalSection(sections, iscopy) { | ||||
|             if (sections && sections.length > 0) { | ||||
|                 var sids = []; | ||||
|                 for (var i = 0; i < sections.length; i++) { | ||||
|                     var it = sections[i].Values; | ||||
|                     if (it.Selected) | ||||
|                         sids.push(it.Id); | ||||
|                 } | ||||
|                 var p = JSON.stringify([teamintelligence, JSON.stringify(sids)]); | ||||
|                 inspectionrequest("GetGlobalSectionsByID", p, function (data) { | ||||
|                     if (typeof data === 'string') | ||||
|                         return; | ||||
|                     for (var i = 0; i < data.length; i++) { | ||||
|                         var section = data[i]; | ||||
|                         if (iscopy) {//copy secton<6F><6E>reference its questions | ||||
|                             if (section.Questions) { | ||||
|                                 for (var j = 0; j < section.Questions.length; j++) { | ||||
|                                     var q = section.Questions[j]; | ||||
|                                     q.Id = ''; | ||||
|                                     //q.ReferenceId = q.Id; | ||||
|                                     //q.IsLink = true; | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                         else {//reference section | ||||
|                             section.ReferenceId = section.Id; | ||||
|                             section.IsLink = true; | ||||
|                         } | ||||
|                         section.Id = ''; | ||||
|                         _this.page.Sections.push(section); | ||||
|                         addSectionModule(section); | ||||
|  | ||||
|                     } | ||||
|                     //updateContent(true); | ||||
|                 }, function (err) { | ||||
|                 }); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         content.append(createPageContent()); | ||||
|         updateContent(); | ||||
|         if (templatereadonly || !editable) | ||||
|             setDisabled(); | ||||
|         return content; | ||||
|     } | ||||
|  | ||||
|     p.prototype.getPageValue = function (noalert, nocheck) { | ||||
|         var page = this.page; | ||||
|         page.Name = this.namecontrol.val(); | ||||
|         page.DisplayText = this.displaytextcontrol.val(); | ||||
|         page.Notes = this.notescontrol.val(); | ||||
|  | ||||
|         var texts = this.namecontrol.data("texts"); | ||||
|         if (texts) { | ||||
|             page.LocalNames = texts; | ||||
|         } | ||||
|         texts = this.displaytextcontrol.data("texts"); | ||||
|         if (texts) { | ||||
|             page.LocalDisplayTexts = texts; | ||||
|         } | ||||
|         if (!nocheck) { | ||||
|             var alerttitle = GetTextByKey("P_IPT_PAGE", 'Page'); | ||||
|             if (!noalert && (!page.Name || page.Name.length == 0)) { | ||||
|                 showAlert(GetTextByKey("P_IPT_PAGENAMENOTBEEMPTY", 'Page Name cannot be empty.'), alerttitle); | ||||
|                 return false; | ||||
|             } | ||||
|             if (!noalert && (!page.DisplayText || page.DisplayText.length == 0)) { | ||||
|                 showAlert(GetTextByKey("P_IPT_DISPLAYTEXTNOTBEEMPTY", 'Display Text cannot be empty.'), alerttitle); | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|         page.Sections = []; | ||||
|         if (this.sectionmodules.length > 0) { | ||||
|             for (var i = 0; i < this.sectionmodules.length; i++) { | ||||
|                 var s = this.sectionmodules[i].getSectionValue(noalert, nocheck); | ||||
|                 if (!s) return false; | ||||
|                 page.Sections.push(s); | ||||
|             } | ||||
|         } | ||||
|         return page; | ||||
|     } | ||||
|     p.prototype.dragOutSection = function (sm) {//called when end drag | ||||
|         var index = this.page.Sections.indexOf(sm.section) | ||||
|         if (index >= 0) { | ||||
|             this.page.Sections.splice(index, 1); | ||||
|             this.sectionmodules.splice(index, 1); | ||||
|         } | ||||
|     }; | ||||
|     p.prototype.dragInSection = function (target, sm, after) {//called when end drag | ||||
|         if (!this.page.Sections) | ||||
|             this.page.Sections = []; | ||||
|         if (this.page.Sections.length == 0) { | ||||
|             this.page.Sections.push(sm.section); | ||||
|             this.sectionmodules.push(sm); | ||||
|             return; | ||||
|         } | ||||
|         var tindex = 0; | ||||
|         if (target) { | ||||
|             tindex = this.page.Sections.indexOf(target); | ||||
|             if (after) | ||||
|                 tindex = tindex + 1; | ||||
|         } | ||||
|         if (tindex >= 0) { | ||||
|             this.page.Sections.splice(tindex, 0, sm.section); | ||||
|             this.sectionmodules.splice(tindex, 0, sm); | ||||
|         } | ||||
|     }; | ||||
|     return p; | ||||
| }); | ||||
|  | ||||
							
								
								
									
										164
									
								
								Site/Inspection/js/modules/templates/pages.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								Site/Inspection/js/modules/templates/pages.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,164 @@ | ||||
| define(['modules/templates/page'], function (Page) { | ||||
|     var q = function (pages) { | ||||
|         this.pages = pages || []; | ||||
|         this.pageModules = []; | ||||
|     }; | ||||
|     q.prototype.description = "Pages Module"; | ||||
|     q.prototype.version = "1.0.0.0"; | ||||
|  | ||||
|     q.prototype.createContent = function () { | ||||
|         var _this = this; | ||||
|         var pagescontent = $('<div></div>'); | ||||
|         var ul = $('<ul class="tab_header" style="padding-top: 5px;"></ul>'); | ||||
|         pagescontent.append(ul); | ||||
|  | ||||
|         var addli = $('<li data-disabled="1" data-href="add"></li>'); | ||||
|         ul.append(addli); | ||||
|         addli.append($('<span class="spanbtn iconadd"></span>')); | ||||
|         addli.append($('<span>' + GetTextByKey("P_IPT_ADD", "Add") + '</span>')); | ||||
|         addli.click(function () { | ||||
|             addTab(null, true); | ||||
|         }); | ||||
|         if (!templatereadonly && editable) | ||||
|             addli.show(); | ||||
|         else | ||||
|             addli.hide(); | ||||
|         ul.append($('<li style="clear: both;"></li>')); | ||||
|  | ||||
|         var tabIndex = 0; | ||||
|         for (var i = 0; i < this.pages.length; i++) { | ||||
|             var p = this.pages[i]; | ||||
|             addTab(p, false); | ||||
|         } | ||||
|         pagescontent.tab();//tab()<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>addli<6C><69>click<63>¼<EFBFBD> | ||||
|  | ||||
|         function addTab(p, newadd) { | ||||
|             if (!p) { | ||||
|                 p = {}; | ||||
|                 _this.pages.push(p); | ||||
|             } | ||||
|             var tabName = 'tab_' + tabIndex++; | ||||
|  | ||||
|             var pm = new Page(p, _this); | ||||
|             _this.pageModules.push(pm); | ||||
|             var pagecontent = pm.createContent().attr('data-page', tabName); | ||||
|  | ||||
|             var li = $('<li></li>').attr('data-href', tabName); | ||||
|             if (tabIndex == 1) | ||||
|                 li.addClass('selected'); | ||||
|             li.append($('<span></span>').text(p.Name || GetTextByKey("P_IPT_UNNAMED", 'Unnamed'))); | ||||
|             if (!templatereadonly && editable) { | ||||
|                 li.css('padding-right', 6); | ||||
|                 var btncopy = $('<span class="spanbtn iconcopy" style="margin-left:10px;padding-left:3px;padding-right:4px;"></span>'); | ||||
|                 btncopy.click(function () { | ||||
|                     var item = copyPage(pm.getPageValue(true, true)); | ||||
|                     _this.pages.push(item); | ||||
|                     addTab(item, true); | ||||
|                     return false; | ||||
|                 }).attr('title', GetTextByKey("P_IPT_COPYPAGE", 'Copy Page')); | ||||
|                 li.append(btncopy); | ||||
|                 var btndelete = $('<span class="spanbtn icondelete" style="padding-left:3px;"></span>'); | ||||
|                 btndelete.click(function () { | ||||
|                     showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTOREMOVETHISPAGE", 'Are you sure you want to remove this page?'), GetTextByKey("P_IPT_REMOVEPAGE", 'Remove Page'), function () { | ||||
|                         var next = li.next(); | ||||
|                         if (next.is(addli)) | ||||
|                             next = li.prev(); | ||||
|                         next.click(); | ||||
|  | ||||
|                         li.remove(); | ||||
|                         pagescontent.children('div[data-page="' + tabName + '"]').remove(); | ||||
|                         _this.pages.splice(_this.pages.indexOf(p), 1); | ||||
|                         _this.pageModules.splice(_this.pageModules.indexOf(pm), 1); | ||||
|                     }); | ||||
|                 }).attr('title', GetTextByKey("P_IPT_DELETEPAGE", 'Delete Page')); | ||||
|                 li.append(btndelete); | ||||
|  | ||||
|                 pm.onNameChanged = function (name) { | ||||
|                     if (name && name != '') | ||||
|                         li.children(":first").text(name); | ||||
|                     else | ||||
|                         li.children(":first").text(GetTextByKey("P_IPT_UNNAMED", 'Unnamed')); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|                 addli.hide(); | ||||
|  | ||||
|             binddrag(li, p); | ||||
|             addli.before(li); | ||||
|             if (newadd) { | ||||
|                 pagescontent.tab(); | ||||
|                 li.click(); | ||||
|             } | ||||
|  | ||||
|             pagescontent.append(pagecontent); | ||||
|         } | ||||
|  | ||||
|         var draggingtab = null; | ||||
|         var draggingpage = null; | ||||
|         function binddrag(li, p) { | ||||
|             li.attr('draggable', true); | ||||
|             li.bind('dragstart', function (e) { | ||||
|                 draggingtab = $(this); | ||||
|                 draggingpage = p; | ||||
|             }); | ||||
|             li.bind('dragend', function (e) { | ||||
|                 draggingtab = null; | ||||
|                 draggingpage = null; | ||||
|             }); | ||||
|             li.bind('dragover', function (e) { | ||||
|                 e.originalEvent.preventDefault() | ||||
|             }); | ||||
|             li.bind('drop', function (e) { | ||||
|                 var t = $(this); | ||||
|                 if (t.is(draggingtab)) | ||||
|                     return; | ||||
|                 var t = $(this); | ||||
|                 var after = e.originalEvent.clientX > t.offset().left + t.width() / 2; | ||||
|                 if (after) { | ||||
|                     t.after(draggingtab); | ||||
|                     _this.pages.splice(_this.pages.indexOf(draggingpage), 1); | ||||
|                     _this.pages.splice(_this.pages.indexOf(p) + 1, 0, draggingpage); | ||||
|                 } | ||||
|                 else { | ||||
|                     t.before(draggingtab); | ||||
|                     _this.pages.splice(_this.pages.indexOf(draggingpage), 1); | ||||
|                     _this.pages.splice(_this.pages.indexOf(p), 0, draggingpage); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         return pagescontent; | ||||
|     }; | ||||
|     q.prototype.getPagesValue = function () { | ||||
|         for (var i = 0; i < this.pageModules.length; i++) { | ||||
|             var p = this.pageModules[i].getPageValue();//getPageValueֱ<65><D6B1><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ö<EFBFBD><C3B6><EFBFBD> | ||||
|             if (!p) return false; | ||||
|         } | ||||
|         return this.pages; | ||||
|     } | ||||
|  | ||||
|     function copyPage(p) { | ||||
|         var p = JSON.parse(JSON.stringify(p)); | ||||
|         p.Id = ""; | ||||
|         if (p.Sections) { | ||||
|             for (var i = p.Sections.length - 1; i >= 0; i--) { | ||||
|                 var s = p.Sections[i]; | ||||
|                 if (s.IsLink) | ||||
|                     p.Sections.splice(i, 1); | ||||
|             } | ||||
|             for (var i = 0; i < p.Sections.length; i++) { | ||||
|                 var s = p.Sections[i]; | ||||
|                 s.Id = ""; | ||||
|                 if (s.Questions) { | ||||
|                     for (var j = 0; j < s.Questions.length; j++) { | ||||
|                         var q = s.Questions[j]; | ||||
|                         q.Id = ""; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         return p; | ||||
|     } | ||||
|  | ||||
|     return q; | ||||
| }); | ||||
							
								
								
									
										295
									
								
								Site/Inspection/js/modules/templates/picture.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										295
									
								
								Site/Inspection/js/modules/templates/picture.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,295 @@ | ||||
| define(['common', 'modules/templates/templatepicture'], function (Common, TemplatePicture) { | ||||
|     var fsm = function (istemplate, pageele, onok) { | ||||
|         this.pageele = pageele || {}; | ||||
|         this.holder = null; | ||||
|         this.dialog = null; | ||||
|         this.istemplate = istemplate; | ||||
|         this.onok = onok; | ||||
|         this.title = GetTextByKey("P_IPT_PICTURES", "Picture"); | ||||
|     }; | ||||
|     fsm.prototype.description = GetTextByKey("P_IPT_PICTURES", "Picture"); | ||||
|     fsm.prototype.version = "1.0.0.0"; | ||||
|  | ||||
|     fsm.prototype.createContent = function () { | ||||
|         var _this = this; | ||||
|         var input = null; | ||||
|         var nopictr = null; | ||||
|         var tabindex = 0; | ||||
|         if (sectiontype === 0) { | ||||
|             if (!_this.pageele.IssueId || _this.pageele.IssueId == "") | ||||
|                 editable = true; | ||||
|             else | ||||
|                 editable = false; | ||||
|         } | ||||
|  | ||||
|         var content = $('<div style="max-height: 200px;overflow-y: auto;"></div>'); | ||||
|         var tb = $('<table style="max-height:300px;line-height:30px;"></table>'); | ||||
|  | ||||
|         function createPictureContent() { | ||||
|             if (_this.pageele && _this.pageele.StaticPictures && _this.pageele.StaticPictures.length > 0) { | ||||
|                 for (var i = 0; i < _this.pageele.StaticPictures.length; i++) { | ||||
|                     var p = _this.pageele.StaticPictures[i]; | ||||
|                     if (!p.Id) | ||||
|                         p.Id = $.newGuid(); | ||||
|                     addpicturerow(p); | ||||
|                 } | ||||
|             } | ||||
|             //else { | ||||
|             //    addnopicrow(); | ||||
|             //} | ||||
|             return tb; | ||||
|         } | ||||
|  | ||||
|         function createAddButton() { | ||||
|             if (!templatereadonly && editable) { | ||||
|                 var addpicdiv = $('<div style="line-height: 30px;"></div>'); | ||||
|                 var addpicicon = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADDPICTURE", "Add Picture") + '</span>').click(function () { | ||||
|                     browsePicture(); | ||||
|                 }); | ||||
|                 addpicdiv.append(addpicicon); | ||||
|  | ||||
|                 if (!_this.istemplate && sectiontype == 1) { | ||||
|                     var addtemppicicon = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADDREFERENCE", "Add Reference") + '</span>').click(function () { | ||||
|  | ||||
|                         var dialogTemplatePicture = new TemplatePicture().getDialogPicture(); | ||||
|  | ||||
|                         dialogTemplatePicture.onDialogClosed = function () { | ||||
|                         } | ||||
|                         dialogTemplatePicture.onOK = function (pics, iscopy) { | ||||
|                             onTemplatePictures(pics, iscopy); | ||||
|                         } | ||||
|  | ||||
|                         dialogTemplatePicture.showSelector(); | ||||
|                     }); | ||||
|                 } | ||||
|                 addpicdiv.append(addtemppicicon); | ||||
|                 content.append(addpicdiv); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function onTemplatePictures(pics, iscopy) { | ||||
|             if (pics && pics.length > 0) { | ||||
|                 var sids = []; | ||||
|                 for (var i = 0; i < pics.length; i++) { | ||||
|                     var it = pics[i].Values; | ||||
|                     if (it.Selected) { | ||||
|                         var p = {}; | ||||
|                         p.Id = $.newGuid(); | ||||
|                         p.ReferenceId = it.Id; | ||||
|                         p.Name = it.Name; | ||||
|                         p.DataType = it.DataType; | ||||
|                         p.ContentId = it.ContentId; | ||||
|                         p.Url = it.Url; | ||||
|                         addpicturerow(p); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function addnopicrow() { | ||||
|             nopictr = $('<tr style="height:30px;"></tr>'); | ||||
|             var td = $('<td style="padding:5px;padding-left:10px;">' + GetTextByKey("P_IPT_NOPICTURE", "No Picture") + '</td>'); | ||||
|             nopictr.append(td); | ||||
|             tb.append(nopictr); | ||||
|         } | ||||
|  | ||||
|         function addpicturerow(p) { | ||||
|             if (nopictr) { | ||||
|                 nopictr.remove(); | ||||
|                 nopictr = null; | ||||
|             } | ||||
|             var tr = $('<tr class="pic"></tr>'); | ||||
|             tb.append(tr); | ||||
|             if (!templatereadonly && editable) | ||||
|                 createdragtd(tr); | ||||
|             createlinktd(tr, p); | ||||
|  | ||||
|             var td = $('<td style="width:50px;"></td>'); | ||||
|             var img = $('<img style="width:30px;height:30px;float:right;margin-right:10px;"/>').attr('src', p.Url); | ||||
|             td.append(img); | ||||
|             tr.append(td); | ||||
|             input = $('<input type="text" class="form-control" style="width:220px" maxlength="100" autocomplete="off"/>').attr("tabindex", ++tabindex); | ||||
|             if (templatereadonly || p.ReferenceId || !editable) | ||||
|                 input.prop('disabled', true); | ||||
|             input.val(p.Name); | ||||
|             tr.data("pic", p); | ||||
|  | ||||
|             tr.append($('<td></td>').append(input)); | ||||
|  | ||||
|             td = $('<td></td>'); | ||||
|             if (!templatereadonly && !IsReferenced(p.Id) && editable) { | ||||
|                 var del = $('<span class="spanbtn icondelete"></span>').click(tr, function (e) { | ||||
|                     showConfirm(GetTextByKey("P_IPT_DELETEFILECONFIRM", 'Are you sure you want to delete this file?'), GetTextByKey("P_IPT_DELETEFILE", 'Delete File'), function () { | ||||
|                         var p = e.data.data("pic"); | ||||
|                         e.data.remove(); | ||||
|                         //var p = JSON.stringify([teamintelligence, p.ContentId]); | ||||
|                         //inspectionrequest("DeleteStaticPicture", htmlencode(p), function (data) { | ||||
|                         //}, function (err) { | ||||
|                         //}); | ||||
|                     }); | ||||
|                 }); | ||||
|                 td.append(del) | ||||
|             } | ||||
|             tr.append(td); | ||||
|             tb.append(tr); | ||||
|         } | ||||
|  | ||||
|         var draggingpicobj | ||||
|         function createdragtd(tr) { | ||||
|             var td = $('<td style="width:32px;"></td>'); | ||||
|             var drag = $('<div class="question-icon" style="width:30px;"><em class="spanbtn iconmove rowdrag" style="font-size:14px;padding:0;"></em></div>'); | ||||
|             td.append(drag); | ||||
|             tr.append(td); | ||||
|  | ||||
|             drag.attr('draggable', true); | ||||
|             tr.bind('dragstart', function (e) { | ||||
|                 //var data = e.originalEvent.dataTransfer; | ||||
|                 draggingpicobj = tr; | ||||
|             }); | ||||
|             tr.bind('dragend', function (e) { | ||||
|                 draggingpicobj = null; | ||||
|             }); | ||||
|             tr.bind('dragover', function (e) { | ||||
|                 e.originalEvent.preventDefault() | ||||
|             }); | ||||
|             tr.bind('drop', function (e) { | ||||
|                 var t = $(this); | ||||
|                 if (!draggingpicobj || t.is(draggingpicobj)) | ||||
|                     return; | ||||
|                 var after = e.originalEvent.clientY > t.offset().top + t.height() / 2; | ||||
|                 if (after) | ||||
|                     t.after(draggingpicobj); | ||||
|                 else | ||||
|                     t.before(draggingpicobj); | ||||
|  | ||||
|                 //draggingobj.pagemodule.dragOutSection(draggingobj); | ||||
|                 //_this.pagemodule.dragInSection(_this.section, draggingobj, after); | ||||
|  | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         function createlinktd(tr, pic) { | ||||
|             var td = $('<td style="width:32px;"></td>'); | ||||
|             if (pic.ReferenceId) { | ||||
|                 var link = $('<div class="question-icon" style="width:30px;"><em class="spanbtn iconlink" style="cursor:default;margin:0;padding:0;font-size:10px;"></em></div>'); | ||||
|                 td.append(link); | ||||
|             } | ||||
|             else { | ||||
|                 td.text(" "); | ||||
|             } | ||||
|             tr.append(td); | ||||
|         } | ||||
|  | ||||
|         function IsReferenced(picid) {//check if template picture can be deleted | ||||
|             if (!_this.istemplate) | ||||
|                 return false; | ||||
|             if (currenttemplate && currenttemplate.Pages && currenttemplate.Pages.length > 0) { | ||||
|                 for (var i = 0; i < currenttemplate.Pages.length; i++) { | ||||
|                     var page = currenttemplate.Pages[i]; | ||||
|                     for (var j = 0; j < page.Sections.length; j++) { | ||||
|                         var section = page.Sections[j]; | ||||
|                         if (section.StaticPictures) { | ||||
|                             for (var m = 0; m < section.StaticPictures.length; m++) { | ||||
|                                 var p = section.StaticPictures[m]; | ||||
|                                 if (p.ReferenceId == picid) | ||||
|                                     return true; | ||||
|                             } | ||||
|                         } | ||||
|                         for (var k = 0; k < section.Questions.length; k++) { | ||||
|                             var question = section.Questions[k]; | ||||
|                             if (question.StaticPictures) { | ||||
|                                 for (var n = 0; n < question.StaticPictures.length; n++) { | ||||
|                                     var p = question.StaticPictures[n]; | ||||
|                                     if (p.ReferenceId == picid) | ||||
|                                         return true; | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         function browsePicture() { | ||||
|             var file = $('<input type="file" style="display: none;" accept="image/png,image/jpg,image/jpeg" />'); | ||||
|             file.change(function () { | ||||
|                 var files = this.files; | ||||
|                 var file = files[0]; | ||||
|                 if (file.size == 0) { | ||||
|                     alert(GetTextByKey("P_IPT_FILETIPS", "File size is 0kb, uploading failed.")); | ||||
|                     return false; | ||||
|                 } | ||||
|                 if (file.size > 1024 * 1024 * 2) { | ||||
|                     alert(GetTextByKey("P_IPT_FILETIPS1", "File is too large. Maximum size is 2MB.")); | ||||
|                     return false; | ||||
|                 } | ||||
|                 SavePicture(file); | ||||
|             }).click(); | ||||
|         } | ||||
|  | ||||
|         function SavePicture(file) { | ||||
|             var formData = new FormData(); | ||||
|             formData.append("pic", file); | ||||
|             formData.append("MethodName", "UploadStaticPicture"); | ||||
|             formData.append("ClientData", teamintelligence); | ||||
|             $.ajax({ | ||||
|                 url: 'Inspection.aspx', | ||||
|                 type: 'POST', | ||||
|                 dataType: 'json', | ||||
|                 processData: false, | ||||
|                 contentType: false, | ||||
|                 data: formData, | ||||
|                 async: true, | ||||
|                 success: function (data) { | ||||
|                     if (data) { | ||||
|                         var p = {}; | ||||
|                         p.Id = $.newGuid(); | ||||
|                         p.ContentId = data.Item1; | ||||
|                         p.Url = data.Item2; | ||||
|                         p.Name = file.name; | ||||
|                         p.DataType = file.name.substring(file.name.lastIndexOf(".")); | ||||
|                         addpicturerow(p); | ||||
|                     } | ||||
|                 }, | ||||
|                 error: function (err) { | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         function OnSave() { | ||||
|             if (!templatereadonly && editable) { | ||||
|                 var pics = []; | ||||
|  | ||||
|                 tb.find("tr.pic").each(function () { | ||||
|                     var tr = $(this); | ||||
|                     var p = tr.data("pic"); | ||||
|                     p.Name = tr.find("input").val(); | ||||
|                     pics.push(p); | ||||
|                 }) | ||||
|  | ||||
|                 //for (var i in inputs) { | ||||
|                 //    var input = inputs[i]; | ||||
|                 //    var p = input.data("pic"); | ||||
|                 //    p.Name = input.val(); | ||||
|                 //    pics.push(p); | ||||
|                 //} | ||||
|                 _this.pageele.StaticPictures = pics; | ||||
|                 _this.dialog.hideDialog(); | ||||
|                 if (_this.onok) | ||||
|                     _this.onok(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
|         content.append(createAddButton()); | ||||
|         content.append(createPictureContent()); | ||||
|  | ||||
|  | ||||
|         _this.dialog = Common.createDialog(GetTextByKey("P_IPT_PICTURE", "Picture"), content, OnSave, true); | ||||
|         _this.dialog.showDialogfixed(); | ||||
|     } | ||||
|  | ||||
|     return fsm; | ||||
| }); | ||||
							
								
								
									
										140
									
								
								Site/Inspection/js/modules/templates/template.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								Site/Inspection/js/modules/templates/template.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,140 @@ | ||||
| define(['modules/templates/addtemplate', 'common'], function (AddTemplate, Common) { | ||||
|     var q = function (tp, template, index) { | ||||
|         this.template = template; | ||||
|         this.templatemodule = tp; | ||||
|         this.index = index | ||||
|     }; | ||||
|     q.prototype.description = "Template Module"; | ||||
|     q.prototype.version = "1.0.0.0"; | ||||
|     var newnamecontrol = undefined; | ||||
|     var dialog = null; | ||||
|  | ||||
|     q.prototype.createContent = function () { | ||||
|         var holder = $('<div class="question-holder"></div>'); | ||||
|         if (this.index % 2 == 1) | ||||
|             holder.addClass('holder-even'); | ||||
|         holder.append('<div class="question-icon template-packages" style="width:30px;padding-left:10px; "><em class="fa icon-menu icon-packages"></em></div>'); | ||||
|         holder.append('<div class="question-cell template-name" style="width:390px;padding-left:10px;"><span></span></div>'); | ||||
|         //holder.append('<div class="question-cell template-display" style="width: 280px;"><span></span></div>'); | ||||
|         holder.append('<div class="question-cell template-notes" style="width:400px;"></div>'); | ||||
|         holder.append('<div class="question-cell template-createdby" style="width:200px;"><span></span></div>'); | ||||
|         var funcs = $('<div class="question-cell template-func" style="width:110px;padding-right:20px;"></div>'); | ||||
|         holder.append(funcs); | ||||
|         var _this = this; | ||||
|         holder.find('.template-name span').click(function () { | ||||
|             var aq = new AddTemplate(_this.templatemodule, _this.template); | ||||
|             $('#right_popup').empty().append(aq.createContent()); | ||||
|             showRightPopup(true); | ||||
|         }); | ||||
|  | ||||
|         if (!templatereadonly) { | ||||
|             funcs.append($('<em class="spanbtn iconedit"></em>').click(function () { | ||||
|                 var aq = new AddTemplate(_this.templatemodule, _this.template); | ||||
|                 $('#right_popup').empty().append(aq.createContent()); | ||||
|                 showRightPopup(true); | ||||
|             }).attr('title', GetTextByKey("P_IPT_EDITTEMPLATE", 'Edit Template'))); | ||||
|             if (templatestatus == 0) { | ||||
|                 funcs.append($('<em class="spanbtn iconshare"></em>').click(function () { | ||||
|                     _this.publish(); | ||||
|                 }).attr('title', GetTextByKey("P_IPT_PUBLISHTEMPLATE", 'Publish Template'))); | ||||
|             } | ||||
|             funcs.append($('<em class="spanbtn icondelete"></em>').click(function () { | ||||
|                 _this.delete(); | ||||
|             }).attr('title', GetTextByKey("P_IPT_DELETETEMPLATE", 'Delete Template'))); | ||||
|  | ||||
|             if (!_this.template.IssueId || _this.template.IssueId == "") { | ||||
|                 funcs.append($('<em class="spanbtn iconcopy"></em>').click(function () { | ||||
|                     _this.openSaveAs(); | ||||
|                 }).attr('title', GetTextByKey("P_IPT_SAVEAS", 'Save As'))); | ||||
|             } | ||||
|         } | ||||
|         this.holder = holder; | ||||
|         if (this.template != null) { | ||||
|             this.updateContent(this.template); | ||||
|         } | ||||
|         return holder; | ||||
|     }; | ||||
|     q.prototype.updateContent = function (template) { | ||||
|         if (this.template != template) { | ||||
|             this.template = template; | ||||
|         } | ||||
|         if (!template.IssueId || template.IssueId == "") | ||||
|             this.holder.find('.template-packages em').hide(); | ||||
|         else | ||||
|             this.holder.find('.template-packages em').show(); | ||||
|  | ||||
|         this.holder.find('.template-name span').text(template.Name); | ||||
|         this.holder.find('.template-name span').attr('title', template.Name); | ||||
|         this.holder.find('.template-display span').text(template.DisplayText); | ||||
|         this.holder.find('.template-display span').attr('title', template.DisplayText); | ||||
|         this.holder.children('.template-notes').html(replaceHtmlText(template.Notes)); | ||||
|         this.holder.children('.template-notes').attr('title', replaceHtmlText(template.Notes)); | ||||
|         this.holder.find('.template-createdby span').text(template.IssueName); | ||||
|         this.holder.find('.template-createdby span').attr('title', template.IssueName); | ||||
|     }; | ||||
|     q.prototype.delete = function () { | ||||
|         var _this = this; | ||||
|         showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISTEMPLATE", 'Are you sure you want to delete this template?'), GetTextByKey("P_IPT_DELETETEMPLATE", 'Delete Template'), function () { | ||||
|             var p = JSON.stringify([teamintelligence, htmlencode(_this.template.Id)]); | ||||
|             inspectionrequest("DeleteTemplate", p, function (data) { | ||||
|                 if (data !== 'OK') | ||||
|                     showAlert(data, GetTextByKey("P_IPT_DELETETEMPLATE", 'Delete Template')); | ||||
|                 else if (_this.templatemodule && typeof _this.templatemodule.refresh === "function") | ||||
|                     _this.templatemodule.refresh(); | ||||
|             }, function (err) { | ||||
|                 showAlert(GetTextByKey("P_IPT_FAILEDTODELETETEMPLATE", 'Failed to delete template.'), GetTextByKey("P_IPT_DELETETEMPLATE", 'Delete Template')); | ||||
|             }); | ||||
|         }); | ||||
|     }; | ||||
|     q.prototype.publish = function () { | ||||
|         var _this = this; | ||||
|         showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTOPUBLISHTHISTEMPLATE", 'Are you sure you want to publish the template?'), GetTextByKey("P_IPT_PUBLISHTEMPLATE", 'Publish Template'), function () { | ||||
|             var p = JSON.stringify([teamintelligence, htmlencode(_this.template.Id)]); | ||||
|             inspectionrequest("PublishTemplate", p, function (data) { | ||||
|                 if (data !== 'OK') | ||||
|                     showAlert(data, GetTextByKey("P_IPT_PUBLISHTEMPLATE", 'Publish Template')); | ||||
|                 else if (_this.templatemodule && typeof _this.templatemodule.refresh === "function") | ||||
|                     _this.templatemodule.refresh(); | ||||
|             }, function (err) { | ||||
|                 showAlert(GetTextByKey("P_IPT_FAILEDTOPUBLISHTEMPLATE", 'Failed to publish template.'), GetTextByKey("P_IPT_PUBLISHTEMPLATE", 'Publish Template')); | ||||
|             }); | ||||
|         }); | ||||
|     }; | ||||
|     q.prototype.openSaveAs = function () { | ||||
|         var _this = this; | ||||
|         var tb = $('<table style="line-height:40px;"></table>'); | ||||
|         var tr = $('<tr></tr>'); | ||||
|         tb.append(tr); | ||||
|         tr.append('<td class="label" style="vertical-align:middle;">' + GetTextByKey("P_IPT_TEMPLATENAME_COLON", "Template Name:") + '<span class="redasterisk">*</span></td>'); | ||||
|         newnamecontrol = $('<input type="text" maxlength="100"/>'); | ||||
|         tr.append($('<td></td>').append(newnamecontrol)); | ||||
|         dialog = Common.createDialog(GetTextByKey("P_IPT_SAVEAS", 'Save As'), tb, function () { | ||||
|             _this.onSaveAs(); | ||||
|         }); | ||||
|         dialog.showDialog(); | ||||
|     }; | ||||
|  | ||||
|     q.prototype.onSaveAs = function () { | ||||
|         var _this = this; | ||||
|         var name = newnamecontrol.val(); | ||||
|         if (!name || name.length == 0) { | ||||
|             showAlert(GetTextByKey("P_IPT_TEMPLATENAMENOTBEEMPTY", 'Template name cannot be empty.'), GetTextByKey("P_IPT_SAVEAS", 'Save As')); | ||||
|             return; | ||||
|         } | ||||
|         name = htmlencode(name); | ||||
|         var p = JSON.stringify([teamintelligence, _this.template.Id, name]); | ||||
|  | ||||
|         inspectionrequest("TemplateSaveAs", htmlencode(p), function (data) { | ||||
|             if (data !== 'OK') | ||||
|                 showAlert(data, GetTextByKey("P_IPT_SAVEAS", 'Save As')); | ||||
|             else if (_this.templatemodule && typeof _this.templatemodule.refresh === "function") | ||||
|                 _this.templatemodule.refresh(); | ||||
|  | ||||
|             dialog.hideDialog(); | ||||
|         }, function (err) { | ||||
|             showAlert(GetTextByKey("P_IPT_FAILEDTOSAVEAS", 'Failed to save as.'), GetTextByKey("P_IPT_SAVEAS", 'Save As')); | ||||
|         }); | ||||
|     }; | ||||
|  | ||||
|     return q; | ||||
| }); | ||||
							
								
								
									
										128
									
								
								Site/Inspection/js/modules/templates/templatepicture.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										128
									
								
								Site/Inspection/js/modules/templates/templatepicture.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,128 @@ | ||||
| define(['common'], function (Common) { | ||||
|  | ||||
|     var dialogPicture = null; | ||||
|     var ls = function () { | ||||
|     }; | ||||
|  | ||||
|     ls.prototype.getDialogPicture = function () { | ||||
|         if (!dialogPicture) | ||||
|             dialogPicture = new $pictureselector(); | ||||
|         return dialogPicture; | ||||
|     } | ||||
|  | ||||
|     var $pictureselector = function () { | ||||
|         this.title = GetTextByKey("P_IPT_SELECTPICTURE", 'Select Picture'); | ||||
|         this.companyId = null; | ||||
|         this.exceptSource = null; | ||||
|         this.onOK = null; | ||||
|         this.onDialogClosed = null; | ||||
|     }; | ||||
|  | ||||
|     (function () { | ||||
|         var __proto = $pictureselector.prototype; | ||||
|  | ||||
|         function initGrid(parent) { | ||||
|             var grid = new GridView(parent); | ||||
|             var columns = []; | ||||
|             columns.push({ | ||||
|                 // checkbox | ||||
|                 name: 'check', | ||||
|                 key: 'Selected', | ||||
|                 width: 30, | ||||
|                 align: 'center', | ||||
|                 sortable: false, | ||||
|                 allcheck: true, | ||||
|                 type: 3 | ||||
|             }); | ||||
|             columns.push({ | ||||
|                 key: 'Name', | ||||
|                 caption: GetTextByKey("P_IPT_NAME", 'Name'), | ||||
|                 width: 200 | ||||
|             }); | ||||
|             //grid.canMultiSelect = true; | ||||
|             grid.columns = columns; | ||||
|             grid.init(); | ||||
|  | ||||
|             this.gridctrl = grid; | ||||
|         } | ||||
|  | ||||
|         function createDialog() { | ||||
|             var dialog = $('<div class="dialog" style="display: none; width: 602px; height: 380px;z-index:1;">'); | ||||
|  | ||||
|             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); | ||||
|  | ||||
|             this.listdiv = $('<div style="width: 580px; height: 290px;margin-bottom:5px;"></div>').appendTo(content); | ||||
|  | ||||
|             var dialogFunction = $('<div class="dialog-func"></div>').appendTo(dialog); | ||||
|             $('<input type="button" value="' + GetTextByKey("P_IPT_CANCEL", "Cancel") + '" class="dialog-close" />').appendTo(dialogFunction); | ||||
|             //$('<input type="button" value="' + GetTextByKey("P_IPT_COPY", "Copy") + '" />').click(onCopyClick.bind(this)).appendTo(dialogFunction); | ||||
|             $('<input type="button" value="' + GetTextByKey("P_IPT_ADDASLINK", "Add as Link") + '" />').click(onLinkClick.bind(this)).appendTo(dialogFunction); | ||||
|             $('<div class="clear"></div>').appendTo(dialogFunction); | ||||
|  | ||||
|             $('<div class="maskbg" style="display: none;z-index:1;"><div class="loading_icon icon c-spin"></div></div>').appendTo(dialog); | ||||
|  | ||||
|             // init | ||||
|             initGrid.call(this, this.listdiv); | ||||
|             $(document.body).append(dialog); | ||||
|             var mask = $('<div class="maskbg"></div>'); | ||||
|             dialog.data('mask', mask); | ||||
|             dialog.before(mask); | ||||
|  | ||||
|             var _this = this; | ||||
|             dialog.dialog(function () { | ||||
|                 if (_this.onDialogClosed) | ||||
|                     _this.onDialogClosed(); | ||||
|                 if (dialog.data('mask')) | ||||
|                     dialog.data('mask').hide(); | ||||
|             }); | ||||
|             return dialog; | ||||
|         } | ||||
|  | ||||
|         __proto.showSelector = function () { | ||||
|             if (!this.dialog) { | ||||
|                 this.dialog = createDialog.call(this); | ||||
|             } | ||||
|  | ||||
|             if (this.dialog.data('mask')) | ||||
|                 this.dialog.data('mask').show(); | ||||
|             this.dialog.showDialog(false); | ||||
|             this.gridctrl.setData([]); | ||||
|             showTemplatePictures.call(this); | ||||
|         }; | ||||
|  | ||||
|         function showTemplatePictures() { | ||||
|             //currenttemplate is defined in Inspection.aspx, it is a global variable | ||||
|             if (currenttemplate && currenttemplate.StaticPictures && currenttemplate.StaticPictures.length > 0) { | ||||
|                 var items = []; | ||||
|                 for (var i = 0; i < currenttemplate.StaticPictures.length; i++) { | ||||
|                     var it = currenttemplate.StaticPictures[i]; | ||||
|                     it.Selected = false; | ||||
|                     items.push({ Values: it }); | ||||
|                 } | ||||
|                 this.gridctrl.setData(items); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         function onCopyClick() { | ||||
|             //var index = this.gridctrl.selectedIndex; | ||||
|             this.onOK && this.onOK(this.gridctrl.source, true); | ||||
|             if (this.dialog.data('mask')) | ||||
|                 this.dialog.data('mask').hide(); | ||||
|             this.dialog.hideDialog(); | ||||
|         } | ||||
|  | ||||
|         function onLinkClick() { | ||||
|             //var index = this.gridctrl.selectedIndex; | ||||
|             this.onOK && this.onOK(this.gridctrl.source, false); | ||||
|             if (this.dialog.data('mask')) | ||||
|                 this.dialog.data('mask').hide(); | ||||
|             this.dialog.hideDialog(); | ||||
|         } | ||||
|     })(); | ||||
|  | ||||
|     return ls; | ||||
| }); | ||||
							
								
								
									
										528
									
								
								Site/Inspection/js/report.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										528
									
								
								Site/Inspection/js/report.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,528 @@ | ||||
|  | ||||
| var vm; | ||||
| var reportdata; | ||||
| $(function () { | ||||
|     $("#host_header").find(".button").remove(); | ||||
|     $("#spanUserName").remove(); | ||||
|  | ||||
|     checkBrowser(); | ||||
|  | ||||
|     if (teamintelligence) { | ||||
|         $('.assettr').remove(); | ||||
|         $(".assettrmobile").remove(); | ||||
|     } | ||||
|     vm = new Vue({ | ||||
|         el: '#divreport', | ||||
|         data: { | ||||
|             report: { | ||||
|                 Asset: {}, | ||||
|                 Template: {}, | ||||
|                 ReportLayout: {} | ||||
|             } | ||||
|         }, | ||||
|         methods: { | ||||
|             reload: function (data) { | ||||
|                 this.report = data; | ||||
|             } | ||||
|         } | ||||
|     }); | ||||
|     GetInspectionReport(); | ||||
| }); | ||||
|  | ||||
| function checkBrowser() { | ||||
|     if (isMobile()) { | ||||
|         $(".logo").remove(); | ||||
|         $(".logoright").remove(); | ||||
|         $(".headernote").remove(); | ||||
|         $("#host_header").css("text-align", "left").css("min-width", "unset"); | ||||
|  | ||||
|         $("#divreport").css("width", "unset"); | ||||
|         //$("#button-edit").remove(); | ||||
|         $("#button-print").remove(); | ||||
|         $("#button-dl").css("margin-right", 10); | ||||
|         $(".assettr").remove(); | ||||
|  | ||||
|         $("#tdiissues").attr("colspan", "2"); | ||||
|         $("#tdpages").attr("colspan", "2"); | ||||
|         //$(".assettrmobile").children().eq(0).css("width", 130); | ||||
|         //$(".assettrmobile").children().eq(1).css("width", "auto"); | ||||
|         $(".assettrmobile").show(); | ||||
|     } | ||||
|     else { | ||||
|         $(".assettrmobile").remove(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function GetInspectionReport() { | ||||
|     showmaskbg(true); | ||||
|     var p = JSON.stringify([teamintelligence, htmlencode(reportid)]); | ||||
|     inspectionrequest("GetInspectionReport", p, function (data) { | ||||
|         if (typeof (data) === "string") { | ||||
|             showAlert(data, GetTextByKey("P_IPT_ERROR", 'Error')); | ||||
|         } | ||||
|         else { | ||||
|             reportdata = data; | ||||
|             vm.reload(data); | ||||
|             showReportLayout(data.ReportLayout); | ||||
|             showIdentifiedQuestions(data.IdentifiedQuestions); | ||||
|             showPages(data); | ||||
|             showSignature(data); | ||||
|         } | ||||
|  | ||||
|         showmaskbg(false); | ||||
|     }, function (err) { | ||||
|         showmaskbg(false); | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function showReportLayout(layout) { | ||||
|     $('#reportlayoutlogo').hide(); | ||||
|     $('.td_pageheaderleft').html(''); | ||||
|     $('.td_pageheadercenter').html(''); | ||||
|     $('.td_pageheaderright').html(''); | ||||
|     $('.td_pagefooterleft').html(''); | ||||
|     $('.td_pagefootercenter').html(''); | ||||
|     $('.td_pagefooterright').html(''); | ||||
|     if (layout) { | ||||
|         $('.td_pageheaderleft').html(layout.PageHeaderLeft); | ||||
|         $('.td_pageheadercenter').html(layout.PageHeaderCenter); | ||||
|         $('.td_pageheaderright').html(layout.PageHeaderRight); | ||||
|         $('.td_pagefooterleft').html(layout.PageFooterLeft); | ||||
|         $('.td_pagefootercenter').html(layout.PageFooterCenter); | ||||
|         $('.td_pagefooterright').html(layout.PageFooterRight); | ||||
|  | ||||
|         $('#reportlayoutlogo').show(); | ||||
|         if (layout.IncludeLOGO && layout.LOGO && layout.LOGO.length > 0) { | ||||
|             var jpeg = layout.LOGO; | ||||
|             if (typeof (layout.LOGO) !== "string") { | ||||
|                 jpeg = arrayBufferToBase64(layout.LOGO); | ||||
|             } | ||||
|             $('#reportlayoutlogo').attr('src', 'data:image/png;base64,' + jpeg); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| function arrayBufferToBase64(buffer) { | ||||
|     var binary = ''; | ||||
|     var bytes = new Uint8Array(buffer); | ||||
|     var len = bytes.byteLength; | ||||
|     for (var i = 0; i < len; i++) { | ||||
|         binary += String.fromCharCode(bytes[i]); | ||||
|     } | ||||
|     return window.btoa(binary); | ||||
| } | ||||
|  | ||||
| function showIdentifiedQuestions(questions) { | ||||
|     if (!questions || questions.length == 0) | ||||
|         return; | ||||
|     var content = $('<div></div>'); | ||||
|     content.append($('<div class="catelog">IDENTIFIED ISSUES</div>')); | ||||
|     if (questions && questions.length > 0) { | ||||
|         for (var i = 0; i < questions.length; i++) { | ||||
|             var q = questions[i]; | ||||
|             var div_question = $('<div class="question"></div>'); | ||||
|             content.append(div_question); | ||||
|             div_question.append($('<div style="width:320px;flex-grow:1;"></div>').text(q.DisplayText)) | ||||
|             if (q.StaticPictures && q.StaticPictures.length > 0) { | ||||
|                 var div_pic = $('<div style=""></div>'); | ||||
|                 div_pic = createPictures(q.StaticPictures, div_pic); | ||||
|                 div_question.append(div_pic) | ||||
|             } | ||||
|  | ||||
|             createAnswerContent(content, q); | ||||
|         } | ||||
|     } | ||||
|     else | ||||
|         content.append($('<div class="question"></div>').text(GetTextByKey("P_IPT_NOQUESTIONS", 'No Questions'))); | ||||
|  | ||||
|     $('#divquestions').append(content); | ||||
| } | ||||
|  | ||||
| function showSeverityLevel(level) { | ||||
|     var levertext = GetTextByKey("P_IPT_SEVERITYLEVEL_COLON", "Severity Level: "); | ||||
|     if (level === 0) | ||||
|         levertext = ""; | ||||
|     if (level === 1) | ||||
|         levertext += GetTextByKey("P_IPT_SL_LOW", "Low"); | ||||
|     else if (level === 2) | ||||
|         levertext += GetTextByKey("P_IPT_SL_MEDIUM", "Medium"); | ||||
|     else if (level === 3) | ||||
|         levertext += GetTextByKey("P_IPT_SL_HIGH", "High"); | ||||
|     return levertext; | ||||
| } | ||||
|  | ||||
| function showPages(report) { | ||||
|     var pages = report.Template.Pages; | ||||
|     var pagescontent = $('<div></div>'); | ||||
|     pagescontent.append($('<div class="catelog" style="margin-top:20px;">' + GetTextByKey("P_IPT_INSPECTIONDETAIL", "INSPECTION DETAIL") + '</div>')); | ||||
|  | ||||
|     for (var i = 0; i < pages.length; i++) { | ||||
|         var p = pages[i]; | ||||
|         var pagecontent = createPage(p); | ||||
|         pagescontent.append(pagecontent); | ||||
|     } | ||||
|     $('#divpages').append(pagescontent); | ||||
| } | ||||
|  | ||||
| function showSignature(report) { | ||||
|     if (report && report.SignatureUrl && report.SignatureUrl != "") { | ||||
|         $('#divsign').append($('<div style="border-bottom:1px solid #dbdbdb;"></div>')); | ||||
|         $('#divsign').append($('<div class="catelog" style="margin-top:20px;">' + GetTextByKey("P_IPT_SIGNATURE", "Signature") + '</div>')); | ||||
|         var pic = $('<img style="height:320px; margin-left:70px;margin-right:10px;margin-bottom:10px;"></img>').attr('src', report.SignatureUrl); | ||||
|         $('#divsign').append(pic); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function createPage(page) { | ||||
|     var content = $('<div style="padding:0px;"></div>'); | ||||
|     var divpage = $('<div class="page"></div>'); | ||||
|     content.append(divpage); | ||||
|  | ||||
|     var btnpage = $('<em class="spanbtn iconangledown" style="font-size:22px;width:24px;"></em>'); | ||||
|     btnpage.click(function () { | ||||
|         var icon = $(this); | ||||
|         if (icon.hasClass('iconangleright')) { | ||||
|             icon.removeClass('iconangleright').addClass('iconangledown'); | ||||
|             icon.parent().next().show(); | ||||
|         } | ||||
|         else { | ||||
|             icon.removeClass('iconangledown').addClass('iconangleright'); | ||||
|             icon.parent().next().hide(); | ||||
|         } | ||||
|     }); | ||||
|     divpage.append(btnpage); | ||||
|     divpage.append($('<span></span>').text(page.DisplayText)); | ||||
|  | ||||
|     var sectioncontent = createSectionContent(page); | ||||
|     content.append(sectioncontent); | ||||
|  | ||||
|     return content; | ||||
| } | ||||
|  | ||||
| function createSectionContent(page) { | ||||
|     var content = $('<div style="margin-bottom:30px;"></div>'); | ||||
|     if (page.Sections && page.Sections.length > 0) { | ||||
|         for (var i = 0; i < page.Sections.length; i++) { | ||||
|             var s = page.Sections[i]; | ||||
|             var divsection = $('<div class="section"></div>'); | ||||
|             content.append(divsection); | ||||
|  | ||||
|             var btnsection = $('<em class="spanbtn iconangledown" style="font-size:18px;display:inline-block;"></em>'); | ||||
|             btnsection.click(function () { | ||||
|                 var icon = $(this); | ||||
|                 if (icon.hasClass('iconangleright')) { | ||||
|                     icon.removeClass('iconangleright').addClass('iconangledown'); | ||||
|                     icon.parent().next().show(); | ||||
|                 } | ||||
|                 else { | ||||
|                     icon.removeClass('iconangledown').addClass('iconangleright'); | ||||
|                     icon.parent().next().hide(); | ||||
|                 } | ||||
|             }); | ||||
|             divsection.append(btnsection); | ||||
|             var ispic = false; | ||||
|             if (s.StaticPictures && s.StaticPictures.length > 0) { | ||||
|                 ispic = true; | ||||
|                 var div_pic = $('<span></span>'); | ||||
|                 createPictures(s.StaticPictures, div_pic); | ||||
|                 divsection.append(div_pic); | ||||
|                 divsection.append('<br/>'); | ||||
|             } | ||||
|             var span_title = $('<span></span>').text(s.DisplayText); | ||||
|             if (ispic) | ||||
|                 span_title.css('margin-left', 24); | ||||
|             divsection.append(span_title); | ||||
|  | ||||
|             var qc = createQuestionContent(s, i); | ||||
|             content.append(qc); | ||||
|         } | ||||
|     } | ||||
|     else | ||||
|         content.append($('<div class="question"></div>').text('No Sections')); | ||||
|     return content; | ||||
| } | ||||
|  | ||||
| function createQuestionContent(section) { | ||||
|     var content = $('<div style="margin-bottom:30px;"></div>'); | ||||
|     if (section.Questions && section.Questions.length > 0) { | ||||
|         for (var i = 0; i < section.Questions.length; i++) { | ||||
|             var q = section.Questions[i]; | ||||
|             var div_question = $('<div class="question"></div>'); | ||||
|             content.append(div_question); | ||||
|  | ||||
|             var div_title = $('<div style="width:320px;flex-grow:1;"></div>').text(q.DisplayText); | ||||
|             div_question.append(div_title); | ||||
|             if (q.StaticPictures && q.StaticPictures.length > 0) { | ||||
|                 var div_pic = $('<div style=""></div>'); | ||||
|                 div_pic = createPictures(q.StaticPictures, div_pic); | ||||
|                 div_question.append(div_pic) | ||||
|             } | ||||
|  | ||||
|             createAnswerContent(content, q); | ||||
|  | ||||
|             if (i != section.Questions.length - 1) | ||||
|                 content.append($('<div style="border-bottom:1px solid #dbdbdb;"></div>')); | ||||
|         } | ||||
|     } | ||||
|     else | ||||
|         content.append($('<div class="question"></div>').text(GetTextByKey("P_IPT_NOQUESTIONS", 'No Questions'))); | ||||
|     return content; | ||||
| } | ||||
|  | ||||
| function createPictures(pictures, p) { | ||||
|     for (var i = 0; i < pictures.length; i++) { | ||||
|         var pic = pictures[i]; | ||||
|         var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', pic.Url).attr('title', pic.Name); | ||||
|         img.click(pic.Url, function (e) { | ||||
|             window.open(e.data, "_blank") | ||||
|         }); | ||||
|         $(p).append(img); | ||||
|     } | ||||
|     return p; | ||||
| } | ||||
|  | ||||
| function createAnswerContent(p, q) { | ||||
|     var leveltext = showSeverityLevel(q.SeverityLevel); | ||||
|     var label_level = $('<label class="label_level"></label>').text(leveltext); | ||||
|     if (reportdata && reportdata.Answers) { | ||||
|         for (var i = 0; i < reportdata.Answers.length; i++) { | ||||
|             var a = reportdata.Answers[i]; | ||||
|             if (a.QuestionId.toLowerCase() == q.Id.toLowerCase()) { | ||||
|                 if ([5, 8, 9, 10, 14, 15, 19].indexOf(q.QuestionType) < 0 | ||||
|                     || (q.QuestionType == 15 && q.SubType != 15)) {//except YesOrNo/DropDown/MultipleChoice/Picture/FuelRecords | ||||
|                     var result = a.Result; | ||||
|                     if (result == null) { | ||||
|                         result = ''; | ||||
|                     } | ||||
|                     if (q.QuestionType == 6 && result.indexOf(' ') >= 0)//Date do not show time | ||||
|                         result = result.split(' ')[0]; | ||||
|                     if (q.QuestionType == 11//Odometer | ||||
|                         || q.QuestionType == 18 //FuelUsed | ||||
|                         || (q.QuestionType == 15 && q.SubType == 8)//FuelRecords Odometer | ||||
|                         || (q.QuestionType == 15 && q.SubType == 10))//FuelRecords Quantity | ||||
|                         result += " " + convertUnits(a.Units); | ||||
|  | ||||
|                     var div_answer = $('<div class="answer"></div>'); | ||||
|                     if (q.QuestionType == 1 | ||||
|                         || (q.QuestionType == 15 && q.SubType == 14)) | ||||
|                         p.append(div_answer.html(replaceHtmlText(result))).append("<div style='clear:both;'></div>"); | ||||
|                     else if (q.QuestionType == 17 && q.TextToCompare != null && result.toLowerCase() != q.TextToCompare.toLowerCase())  // BarCodeValidate | ||||
|                         p.append(div_answer | ||||
|                             .append($('<span style="color:red"></span>').text(result)) | ||||
|                             .append($('<span style="margin-left:6px"></span>').text('(' + q.TextToCompare + ')')) | ||||
|                         ).append("<div style='clear:both;'></div>"); | ||||
|                     else | ||||
|                         p.append(div_answer.text(result)).append("<div style='clear:both;'></div>"); | ||||
|  | ||||
|                     div_answer.append(label_level); | ||||
|                 } | ||||
|                 else if (q.QuestionType == 5) {//YesOrNo | ||||
|                     if (a.SelectedItems && a.SelectedItems.length > 0) { | ||||
|                         var item = $('<div class="answer" ></div>'); | ||||
|                         var div_bg = $('<div class="circle"></div>'); | ||||
|                         var label = $('<label style="margin-left:5px;"></lable>').text(a.SelectedItems[0].Text); | ||||
|                         item.append(div_bg); | ||||
|                         item.append(label); | ||||
|                         leveltext = showSeverityLevel(a.SelectedItems[0].SeverityLevel); | ||||
|                         label_level = $('<label class="label_level"></label>').text(leveltext); | ||||
|                         item.append(label_level); | ||||
|                         if (a.SelectedItems[0].BackgroundColor && a.SelectedItems[0].BackgroundColor != "") { | ||||
|                             div_bg.css('background-color', a.SelectedItems[0].BackgroundColor); | ||||
|                         } | ||||
|                         p.append(item).append("<div style='clear:both;'></div>"); | ||||
|                     } | ||||
|                 } | ||||
|                 else if (q.QuestionType == 8 || q.QuestionType == 9//DropDown、List | ||||
|                     || (q.QuestionType == 15 && q.SubType == 6) | ||||
|                     || (q.QuestionType == 15 && q.SubType == 9)) { | ||||
|                     if (q.MultipleSelect) { | ||||
|                         if (a.SelectedItems && a.SelectedItems.length > 0) { | ||||
|                             for (var j = 0; j < a.SelectedItems.length; j++) { | ||||
|                                 var item = $('<div class="answer"></div>'); | ||||
|                                 var div_bg = $('<div class="circle"></div>'); | ||||
|                                 var label = $('<label style="margin-left:5px;"></lable>').text("" + (j + 1) + ". " + a.SelectedItems[j].Text); | ||||
|                                 item.append(div_bg); | ||||
|                                 item.append(label); | ||||
|                                 leveltext = showSeverityLevel(a.SelectedItems[j].SeverityLevel); | ||||
|                                 label_level = $('<label class="label_level"></label>').text(leveltext); | ||||
|                                 item.append(label_level); | ||||
|                                 if (a.SelectedItems[j].BackgroundColor && a.SelectedItems[j].BackgroundColor != "") { | ||||
|                                     div_bg.css('background-color', a.SelectedItems[j].BackgroundColor); | ||||
|                                 } | ||||
|                                 p.append(item).append("<div style='clear:both;'></div>"); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     else { | ||||
|                         if (a.SelectedItems && a.SelectedItems.length > 0) { | ||||
|                             var item = $('<div class="answer" ></div>'); | ||||
|                             var div_bg = $('<div class="circle"></div>'); | ||||
|                             var label = $('<label style="margin-left:5px;"></lable>').text(a.SelectedItems[0].Text); | ||||
|                             item.append(div_bg); | ||||
|                             item.append(label); | ||||
|                             leveltext = showSeverityLevel(a.SelectedItems[0].SeverityLevel); | ||||
|                             label_level = $('<label class="label_level"></label>').text(leveltext); | ||||
|                             item.append(label_level); | ||||
|                             if (a.SelectedItems[0].BackgroundColor && a.SelectedItems[0].BackgroundColor != "") { | ||||
|                                 div_bg.css('background-color', a.SelectedItems[0].BackgroundColor); | ||||
|                             } | ||||
|                             p.append(item).append("<div style='clear:both;'></div>"); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 else if (q.QuestionType == 14) {//Email (Drop Down) | ||||
|                     if (a.SelectedItems && a.SelectedItems.length > 0) { | ||||
|                         for (var j = 0; j < a.SelectedItems.length; j++) { | ||||
|                             var item = $('<div class="answer"></div>'); | ||||
|                             var label = $('<label style="margin-left:5px;"></lable>').text("" + (j + 1) + ". " + a.SelectedItems[j].Text + "<" + a.SelectedItems[j].Value + ">"); | ||||
|                             item.append(label); | ||||
|                             item.append(label_level); | ||||
|                             p.append(item).append("<div style='clear:both;'></div>"); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 else if (q.QuestionType == 10 | ||||
|                     || (q.QuestionType == 15 && q.SubType == 15)) {//Picture | ||||
|                     var pics = $('<div style="min-height:80px;overflow:auto;padding-left:90px;"></div>'); | ||||
|                     p.append(pics); | ||||
|                     //pics.append(label_level); | ||||
|                     if (reportdata.Medias && reportdata.Medias.length > 0) { | ||||
|                         for (var j = 0; j < reportdata.Medias.length; j++) { | ||||
|                             var m = reportdata.Medias[j]; | ||||
|                             if (m.AnswerId.toLowerCase() == a.Id.toLowerCase()) { | ||||
|                                 if (['.mp4', '.mov'].indexOf(m.FileType.toLowerCase()) >= 0) { | ||||
|                                     var v = $('<div class="media"><span class="video"></span></div>'); | ||||
|                                     v.click(m.Url, function (e) { | ||||
|                                         window.open(e.data, "_blank") | ||||
|                                     }); | ||||
|                                     pics.append(v); | ||||
|                                 } | ||||
|                                 else { | ||||
|                                     var pic = $('<img class="media"></img>').attr('src', m.ThumbnailUrl); | ||||
|                                     pic.click(m.Url, function (e) { | ||||
|                                         window.open(e.data, "_blank") | ||||
|                                     }); | ||||
|                                     pics.append(pic); | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 else if (q.QuestionType == 19) {//Asset Status | ||||
|                     var divanswer = $('<div class="answer" ></div>'); | ||||
|                     if (a.SelectedItems && a.SelectedItems.length > 0) { | ||||
|                         var div_bg = $('<div class="circle"></div>'); | ||||
|                         var label = $('<label style="margin-left:5px;"></lable>').text(a.SelectedItems[0].Text); | ||||
|                         divanswer.append(div_bg); | ||||
|                         divanswer.append(label); | ||||
|                         if (a.SelectedItems[0].BackgroundColor && a.SelectedItems[0].BackgroundColor != "") { | ||||
|                             div_bg.css('background-color', a.SelectedItems[0].BackgroundColor); | ||||
|                         } | ||||
|                         p.append(divanswer).append("<div style='clear:both;'></div>"); | ||||
|  | ||||
|                     } | ||||
|                     divanswer.append(label_level); | ||||
|  | ||||
|                     var pics = $('<div style="min-height:80px;overflow:auto;padding-left:90px;"></div>'); | ||||
|                     p.append(pics); | ||||
|                     if (reportdata.Medias && reportdata.Medias.length > 0) { | ||||
|                         for (var j = 0; j < reportdata.Medias.length; j++) { | ||||
|                             var m = reportdata.Medias[j]; | ||||
|                             if (m.AnswerId.toLowerCase() == a.Id.toLowerCase()) { | ||||
|                                 if (['.mp4', '.mov'].indexOf(m.FileType.toLowerCase()) >= 0) { | ||||
|                                     var v = $('<div class="media"><span class="video"></span></div>'); | ||||
|                                     v.click(m.Url, function (e) { | ||||
|                                         window.open(e.data, "_blank") | ||||
|                                     }); | ||||
|                                     pics.append(v); | ||||
|                                 } | ||||
|                                 else { | ||||
|                                     var pic = $('<img class="media"></img>').attr('src', m.ThumbnailUrl); | ||||
|                                     pic.click(m.Url, function (e) { | ||||
|                                         window.open(e.data, "_blank") | ||||
|                                     }); | ||||
|                                     pics.append(pic); | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     if (a.Result && a.Result != "") { | ||||
|                         p.append($('<div class="answer" style="color:#808080"></div>').html(replaceHtmlText(a.Result))); | ||||
|                     } | ||||
|                 } | ||||
|                 if (a.Comment && a.Comment != "") { | ||||
|                     p.append($('<div class="answer" style="color:#808080"></div>').html(replaceHtmlText(a.Comment))); | ||||
|                 } | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     p.append($('<div class="answer"></div>').text("")); | ||||
|  | ||||
|  | ||||
|     //public string Id { get; set; } | ||||
|     //public string QuestionId { get; set; } | ||||
|     //public string Result { get; set; } | ||||
|     //public string Comment { get; set; } | ||||
|     //public string Units { get; set; } | ||||
|     //public SeverityLeveles SeverityLevel { get; set; } | ||||
|     //public List<SelectItem> SelectedItems { get; } | ||||
|  | ||||
|     //SingleLineText = 0, | ||||
|     //MultipleLineText = 1, | ||||
|     //Email = 2, | ||||
|     //Number = 3, | ||||
|     //Integer = 4, | ||||
|     //YesOrNo = 5, | ||||
|     //Date = 6, | ||||
|     //DateAndTime = 7, | ||||
|     //DropDown = 8, | ||||
|     //MultipleChoice = 9, | ||||
|     //Picture = 10, | ||||
|     //Odometer = 11, | ||||
|     //EngingHours = 12 | ||||
|  | ||||
|     //如果是非select类型,则是界面上直接录的值 | ||||
|     //如果question type为odometer时,units表示所用的单位,其它类型忽略units | ||||
|     //如果question是select类型的(多选,单选,yes / no) ,则忽略result, 此时question的答案要从selecteditems当中去取 | ||||
|     //如果是picture类型,result存的是media的id, | ||||
|     //@Tsanie picture类型是这样的吧 | ||||
|     //picture类型的没在ReportInfo结构上存,是MediaInfo里的AnswerId为ReportInfo里的Id | ||||
|     //如果AssetStatus类型,result存的是notes | ||||
|  | ||||
|  | ||||
|     return result; | ||||
| } | ||||
|  | ||||
| function convertUnits(u) { | ||||
|     switch (u.toLowerCase()) { | ||||
|         case "mile": | ||||
|             return "Mile(s)"; | ||||
|         case "kilometre": | ||||
|         case "kilometer": | ||||
|             return "Kilometer"; | ||||
|         case "percent": | ||||
|             return "Percent"; | ||||
|         case "gallon": | ||||
|         case "gal": | ||||
|             return "Gallon"; | ||||
|         case "litre": | ||||
|             return "Litre"; | ||||
|         default: | ||||
|             break; | ||||
|     } | ||||
|     return u; | ||||
| } | ||||
|  | ||||
| function isLight(color) { | ||||
|     color = color.replace('#', ''); | ||||
|     var r, g, b; | ||||
|     if (color.length == 6) { | ||||
|         r = '0x' + color.substr(0, 2); | ||||
|         g = '0x' + color.substr(2, 2); | ||||
|         b = '0x' + color.substr(4, 2); | ||||
|  | ||||
|         return 0.213 * parseInt(r) + 0.715 * parseInt(g) + 0.072 * parseInt(b) > 255 / 2; | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
							
								
								
									
										23
									
								
								Site/Inspection/js/view-main.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Site/Inspection/js/view-main.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| require.config({ | ||||
|     baseUrl: 'js', | ||||
|     paths: { | ||||
|         //jquery: "../../js/jquery-3.6.0.min", | ||||
|         //spectrum: "../../js/spectrum" | ||||
|     }, | ||||
|     waitSeconds: 0, | ||||
|     urlArgs: "v=38" //+ Math.random() | ||||
| }) | ||||
|  | ||||
| requirejs(['modules/inspects/editinspection'], function (EditModule) { | ||||
|     //if (isAdmin) { | ||||
|         $(function () { | ||||
|             $('#button-edit').click(function () { | ||||
|                 var ei = new EditModule.EditInspection(function () { | ||||
|                     window.location = window.location.href; | ||||
|                 }, reportid); | ||||
|                 $('#right_popup').empty().append(ei.createContent()); | ||||
|                 showRightPopup(true); | ||||
|             }); | ||||
|         }); | ||||
|     //} | ||||
| }) | ||||
		Reference in New Issue
	
	Block a user