|
|
@@ -21,7 +21,7 @@ $(document).ready(function() {
|
|
|
element.children(".spinner").remove();
|
|
|
}
|
|
|
|
|
|
- function loadBox(element) {
|
|
|
+ function loadBox(element, callback) {
|
|
|
|
|
|
$(document).on("click", element, function(e) {
|
|
|
|
|
|
@@ -34,7 +34,25 @@ $(document).ready(function() {
|
|
|
var optionsContainer = document.createElement('div');
|
|
|
|
|
|
$.each(editBox['options'], function(i) {
|
|
|
- $(optionsContainer).append(this.name + "<input type=\"" + this.type + "\" value=\"" + this.value + "\" style=\"float: right;\"/><br><br>")
|
|
|
+ switch(this.type) {
|
|
|
+ case 'text':
|
|
|
+ $(optionsContainer).append(this.name + "<input id=\"editbox-input-" + this.name + "\" type=\"text\" value=\"" + this.value + "\" class=\"editbox-input\" /><br><br>");
|
|
|
+ break;
|
|
|
+ case 'select':
|
|
|
+ selectHtml = "<select id=\"editbox-input-" + this.name + "\" class=\"editbox-input\">";
|
|
|
+ this['values'].forEach(function(item) { // TODO: jQuery-each?
|
|
|
+ if(editBox['options'][0]['value'] == item) {
|
|
|
+ selectHtml += "<option selected value=\"" + item + "\">" + item + "</option>"
|
|
|
+ } else {
|
|
|
+ selectHtml += "<option value=\"" + item + "\">" + item + "</option>"
|
|
|
+ }
|
|
|
+ });
|
|
|
+ selectHtml += "</select>";
|
|
|
+ $(optionsContainer).append(this.name + selectHtml + "<br><br>");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
$.fancybox({
|
|
|
@@ -44,14 +62,15 @@ $(document).ready(function() {
|
|
|
width : '70%',
|
|
|
height : '70%',
|
|
|
autoSize : false,
|
|
|
- title : "<h3>" + editBox['title'] + "</h3><hr>",
|
|
|
- content : optionsContainer.innerHTML,
|
|
|
- helpers : {
|
|
|
+ title : "<h3>" + editBox['title'] + "</h3><hr>",
|
|
|
+ content : optionsContainer.innerHTML,
|
|
|
+ helpers : {
|
|
|
title: {
|
|
|
type : 'inside',
|
|
|
position: 'top'
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ afterShow : callback
|
|
|
});
|
|
|
} catch(e) {
|
|
|
console.log(e); // DBG
|
|
|
@@ -86,6 +105,50 @@ $(document).ready(function() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ function newDocumentListener() {
|
|
|
+ $(document).on("change", ".fancybox-inner select", function(e) {
|
|
|
+ reloadDraftVars();
|
|
|
+ });
|
|
|
+
|
|
|
+ $(document).on("click", "#save-new-document", function(e) {
|
|
|
+ e.preventDefault();
|
|
|
+
|
|
|
+ data = {
|
|
|
+ draft: $("#editbox-input-vorlage").val(),
|
|
|
+ filename: $("#editbox-input-filename").val(),
|
|
|
+ draftVars: {}
|
|
|
+ }
|
|
|
+
|
|
|
+ $(".editbox-draft-vars").each(function(i) {
|
|
|
+ data['draftVars'][$(this).attr("id").replace("editbox-draft-vars-", "")] = $(this).val();
|
|
|
+ });
|
|
|
+
|
|
|
+ $.getJSON("ajax.php?action=saveNewDocument", data, function(r) {
|
|
|
+ console.log(r);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function reloadDraftVars() {
|
|
|
+ $.getJSON("ajax.php?action=getDraftVars&draft=" + $(".fancybox-inner select").val(), function(r) {
|
|
|
+ draftVarsContainer = $("#draft-vars");
|
|
|
+
|
|
|
+ if(draftVarsContainer.length > 0) {
|
|
|
+ console.log(draftVarsContainer);
|
|
|
+ draftVarsContainer.remove();
|
|
|
+ }
|
|
|
+
|
|
|
+ $(".fancybox-inner").append("<div id=\"draft-vars\"></div>")
|
|
|
+
|
|
|
+ r.forEach(function(item) {
|
|
|
+ $(".fancybox-inner #draft-vars").append(item + "<input id=\"editbox-draft-vars-" + item + "\" class=\"editbox-draft-vars\" type=\"text\" /><br><br>");
|
|
|
+ })
|
|
|
+
|
|
|
+ $(".fancybox-inner #draft-vars").append("<a href=\"#\"type=\"button\" id=\"save-new-document\" class=\"btn btn-success\">Dokument speichern</a>");
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
$.fn.editable.defaults.mode = 'inline';
|
|
|
$.fn.editableform.buttons =
|
|
|
'<button type="submit" class="btn btn-primary btn-sm editable-submit">'+
|
|
|
@@ -287,10 +350,11 @@ $(document).ready(function() {
|
|
|
getMailboxStatus();
|
|
|
break;
|
|
|
case 'manage-label':
|
|
|
- loadBox('.manage-mailboxfolder');
|
|
|
+ loadBox('.manage-mailboxfolder', function() {});
|
|
|
break;
|
|
|
case 'label':
|
|
|
- loadBox('#new-document');
|
|
|
+ loadBox('#new-document', function() { reloadDraftVars(); });
|
|
|
+ newDocumentListener();
|
|
|
break;
|
|
|
default:
|
|
|
break;
|