Files
Facilitor/APPL/PDA/mobile.js
Jos Groot Lipman cad678a9e5 FCLT#61196 Interface toggle beter ondersteunen
svn path=/Website/trunk/; revision=47696
2020-08-10 12:53:00 +00:00

285 lines
9.5 KiB
JavaScript

/*
$Revision$
$Id$
File: mobile.js
Description: clientside functions for pda
*/
window.fcltmobile = 1;
if (window.localStorage.getItem("interface") == "touch") {
toTouch();
}
// Fix voor CVE-2015-9251 in jQuery 2.2.4 (FCLT#54923)
// Prevent auto-execution of scripts when no explicit dataType was provided (See gh-2432)
jQuery.ajaxPrefilter(function(s) {
if (s.crossDomain) {
s.contents.script = false;
}
});
$(document).bind("mobileinit", function() {
// Enhancement to use history.replaceState in supported browsers,
// to convert the hash-based Ajax URL into the full document path.
// Note that we recommend disabling this feature if Ajax is disabled
// or if extensive use of external links are used.
$.mobile.pushStateEnabled = false;
// $.mobile.ajaxEnabled = false;
if (window.FcltMgr);
});
$(document).bind("pageinit", function() {
$("i.dateklikker,i.timeklikker").each(function() {
$(this).appendTo($(this).prev());
});
});
$(function() {
$("a.previewext").on("click", function(event) {
event.preventDefault();
var target = $(this),
href = target.attr("href"),
short = target.attr("id"),
closebtn = '<a href="#" data-rel="back" class="ui-btn ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a>',
header = '<div data-role="header"><h2>' + target.html() + '</h2></div>',
img = '<img src="' + href + '" alt="' + target.html() + '" class="photo">',
popup = '<div data-role="popup" id="popup-' + short + '" data-short="' + short + '" data-theme="none" data-overlay-theme="a" data-corners="false" data-tolerance="15"></div>';
// Create the popup.
$(header)
.appendTo($(popup)
.appendTo($.mobile.activePage)
.popup())
.toolbar()
.before(closebtn)
.after(img);
// Wait with opening the popup until the popup image has been loaded in the DOM.
// This ensures the popup gets the correct size and position
$(".photo", "#popup-" + short).load(function() {
// Open the popup
$("#popup-" + short).popup("open");
// Clear the fallback
clearTimeout(fallback);
});
// Fallback in case the browser doesn't fire a load event
var fallback = setTimeout(function() {
$("#popup-" + short).popup("open");
}, 2000);
});
// Set a max-height to make large images shrink to fit the screen.
$(document).on("popupbeforeposition", ".ui-popup", function() {
var image = $(this).children("img"),
height = image.height(),
width = image.width();
// Set height and width attribute of the image
$(this).attr({
"height": height,
"width": width
});
// 68px: 2 * 15px for top/bottom tolerance, 38px for the header.
var maxHeight = $(window).height() - 68 + "px";
$("img.photo", this).css("max-height", maxHeight);
});
// Remove the popup after it has been closed to manage DOM size
$(document).on("popupafterclose", ".ui-popup", function() {
$(this).remove();
});
});
function McltCallbackAndThen(afterAction) {
return function(json, textStatus) {
if (json.message) alert(json.message); // Normaal door FcltMgr.closeDetail
if (json.warning) alert(json.warning);
json.message = null;
json.warning = null;
if (json.success) {
if (afterAction) afterAction(json);
}
}
};
function McltCallbackAndThenAlways(afterAction) {
return function(json, textStatus) {
if (json.message) alert(json.message);
if (json.warning) alert(json.warning);
json.message = null;
json.warning = null;
if (afterAction) afterAction(json);
}
};
function jqToast(msg) {
$("<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h3>" + msg + "</h3></div>")
.css({
display: "block",
opacity: 0.90,
position: "absolute",
padding: "7px",
"text-align": "center",
width: "270px",
left: (($(window).width() - 284) / 2) + "px",
top: ($(window).scrollTop() + $(window).height() / 2) + "px"
})
.appendTo($.mobile.pageContainer).delay(2500)
.fadeOut(400, function() {
$(this).remove();
});
}
var McltCallbackSaved = McltCallbackAndThen(function(json) {
if (json.success)
jqToast(L("lcl_mobile_data_saved"));
});
var McltCallbackRefresh = McltCallbackAndThen(function(json) {
window.location.href = window.location.href;
});
var McltCallbackClose = McltCallbackAndThen(function(json) {
window.history.back(1);
});
var McltCallbackHome = McltCallbackAndThen(function(json) {
// window.history.back(1); doet geen refresh als je bijvoorbeeld net een reservering hebt verwijderd
window.location.href = rooturl + "/appl/pda/facilitor.asp";
});
var mobile = {
button: {
click: function(evt, btn) {
FcltMgr.stopPropagation(evt);
if (btn.getAttribute("singlepress") && $(btn).hasClass("btn_disabled")) { // FcltMgr.alert("Heb geduld");
return;
}
if (btn.getAttribute("singlepress")) {
mobile.button.disable(btn);
}
var elem = btn.getAttribute("mobClick");
// window.fcltevent = evt;
var result = eval(elem);
// Dit lijkt erg onzinning (we zitten binnen mobile) maar soms als
// een scherm/dialoog net gesloten is door de action van de button
// blijkt de code toch nog hier te komen terwijl mobile weg is
if (typeof mobile == "undefined")
return;
if (result === false) {
mobile.button.enable(btn);
}
},
disable: function(btn) {
if (!btn || btn.tagName != 'A')
return; // not a mobile button
$(btn).toggleClass("btn_disabled", true)
.removeClass("btn_enabled");
},
enable: function(btn) {
if (!btn || btn.tagName != 'A')
return; // not a mobile button
$(btn).toggleClass("btn_enabled", true)
.removeClass("btn_disabled");
}
}
}
function onBijlagenMobile(formurl, // protected
saveUrl, // protected
multi,
objButton) {
// Vorige eventueel opruimen
$("#bijlagepopup").trigger("destroy").remove(); // eventuele vorige opruimen
var html = '<iframe class="mfcltmodal"' +
' frameborder="0"' +
' id="fcltmodal" name="fcltmodal" scrolling="no" style="padding: 0px;"' +
' src="' + rooturl + '/appl/shared/empty.html">' +
'</iframe>';
html = '<div id="bijlagepopup" data-role="popup" class="ui-content" data-theme="c">' +
'<a href="#" data-rel="back" data-role="button" data-theme="c" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>' +
html +
'</div>';
var $html = $(html);
$("body").append($html);
$html.trigger("create");
$("#bijlagepopup").on("popupafterclose",
function(event, ui) {
if (window.return_data) // gezet door BijlagenForm.asp
{
// Overkill alert(window.return_data.fileName + " is toegevoegd");
if (window.return_data.fileName) {
if ($(objButton).is("[src]")) {
afterUploadForm(window.return_data.fileName);
} else {
$(objButton).val(window.return_data.fileName)
.show()
.attr("onclick", "")
.attr("readonly", "1")
.parent().next().hide(); // de 'Add' knop
}
}
}
// Als we dit weglaten krijgen we obscure clientside jQuery errors ('Array not defined etc')
$("iframe.mfcltmodal").attr("src", "../shared/empty.html");
});
// $("#bijlagepopup").show();
$("#bijlagepopup").popup({ history: false }).popup("open");
$html.find("iframe").attr("src", formurl);
}
// make filename safe for show
function safeFilename(s) {
return s.replace(/[\x00-\x1F|\/|\\|\*|\%\<\>\"\:\;\?\|\+]+/g, "_");
}
// remove element of deleted file
function removeElement(element) {
return function(json) {
element.remove();
if (json.toaster) {
jqToast(json.toaster);
}
}
};
// delete flex-attachment
function DeleteFile(fname, safeDeleteurl, element) {
FcltMgr.confirm(L("lcl_delete") + " " + safeFilename(fname) + "?", function() {
var data = {};
protectRequest.dataToken(data);
$.post("../shared/" + safeDeleteurl,
data,
McltCallbackAndThen(removeElement(element))
);
});
}
function disable(btn) {
$(btn).attr("onclick", "return false;")
.toggleClass("btn-disabled", true)
.removeClass("btn-enabled");
}
function toTouch() {
window.localStorage.setItem("interface", "touch");
parent.location.href = "../../default.asp?interface=touch";
}