447 lines
16 KiB
JavaScript
447 lines
16 KiB
JavaScript
define(function () {
|
|
//define([], function () {//使用外部的$,才有Dialog,后期修改
|
|
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) {
|
|
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 () {
|
|
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;
|
|
}); |