');
if (!templatereadonly && !IsReferenced(p.Id) && editable) {
var del = $('').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 = $('
');
var drag = $('
');
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 = $('
');
if (pic.ReferenceId) {
var link = $('
');
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 = $('');
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;
});