Bläddra i källkod

\#39: Alle (Meiste ?) Fancyboxen umgestellt

Moritz Schmidt 10 år sedan
förälder
incheckning
2ced901473
3 ändrade filer med 75 tillägg och 80 borttagningar
  1. 22 17
      ajax.php
  2. 52 62
      scripts/custom.js
  3. 1 1
      templates/documentlist.php

+ 22 - 17
ajax.php

@@ -115,23 +115,28 @@ switch($_REQUEST['action']) {
         echo json_encode($mbArray);
         break;
     case 'getNewDocumentBox':
-        $boxHtml = 'Vorlage: ';
-        $boxHtml .= getEditableLink('document-draft', 'select', 0, 'Click to change', 'Rechnung.odt');
-        $boxHtml .= '<br>Dateiname: ';
-        $boxHtml .= getEditableLink('document-filename', 'text', 0, 'Click to change', 'Neue-Rechnung-09.04.2015.odt');
-        $documentHandler = new DocumentHandler('NeueRechnung.docx', 'Rechnung.docx');
-        $valueKeys = $documentHandler->getVariables();
-        foreach($valueKeys as $key=>$value) {
-            $boxHtml .= '<br>' . getEditableLink('template-value-' . $key, 'text', 0, 'Click to change', $value) . $value;
-        }
-        $documentHandler->setVal('ADRESSE', 'Moritz Schmidt' . PHP_EOL . 'Fr.-Weinbrenner-Str. 13' . PHP_EOL . '69126 Heidelberg');
-        $documentHandler->setVal('RECHNUNGSNUMMER', '2015.1');
-        $documentHandler->setVal('BESCHREIBUNG', 'eine kleine rechnung lol');
-        $documentHandler->setVal('RECHNUNGTABELLE', 'tabelle idk ollo todo implement!');
-        $documentHandler->setVal('GESAMTBETRAG', '7€');
-        $documentHandler->setVal('JAHR', '2015');
-        //$documentHandler->saveFile();
-        echo $boxHtml;
+        header("Status: 200 OK");
+
+        // TODO: add reload on draft change
+        // TODO: add draft-fields as options, depends on ^
+
+        $editBox = array(
+            "options"   => array(
+                array(
+                    "type"  => "select",
+                    "name"  => "vorlage",
+                    "value" => "Rechnung.odt" // TODO: get default value
+                ),
+                array(
+                    "type"  => "text",
+                    "name"  => "filename",
+                    "value" => "Neue-Rechnung-DATUM.odt" // TODO: get value based on draft
+                )
+            ),
+            "title" => "Neues Dokument"
+        );
+
+        echo json_encode($editBox);
         break;
     case 'getMailboxStatus':
         $mailbox = Mailbox::getMailboxById($_REQUEST['mailboxId'], true);

+ 52 - 62
scripts/custom.js

@@ -21,6 +21,52 @@ $(document).ready(function() {
         element.children(".spinner").remove();
     }
 
+    function loadBox(element) {
+
+        $(document).on("click", element, function(e) {
+
+            e.preventDefault();
+
+            $.get($(this).attr('href'), function(r) {
+
+                try {
+                    editBox = $.parseJSON(r);
+                    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>")
+                    });
+
+                    $.fancybox({
+                        maxWidth	: 800,
+                        maxHeight	: 600,
+                        fitToView	: true,
+                        width		: '70%',
+                        height		: '70%',
+                        autoSize	: false,
+                        title   : "<h3>" + editBox['title'] + "</h3><hr>",
+                        content : optionsContainer.innerHTML,
+                        helpers : {
+                            title: {
+                                type    : 'inside',
+                                position: 'top'
+                            }
+                        }
+                    });
+                } catch(e) {
+                    console.log(e); // DBG
+                    var n = noty({
+                        layout  : 'topCenter',
+                        text    : 'Irgendwas ist schief gelaufen.<br>Bitte probieren Sie es später noch einmal.',
+                        type    : 'error',
+                        timeout : 5000
+                        });
+                }
+            });
+
+        });
+    }
+
     function getMailboxStatus() {
         $("#settings-mailboxes tr").each(function(item) {
             var thisTr = this;
@@ -218,54 +264,6 @@ $(document).ready(function() {
             });
     });
 
-    $('.manage-mailboxfolder').on('click', function(e) {
-        e.preventDefault();
-
-        $.get($(this).attr('href'), function(r) {
-
-            try {
-                editBox = $.parseJSON(r);
-                console.log(editBox['options']); // DBG
-
-                var optionsContainer = document.createElement('div');
-
-                console.log(optionsContainer);
-
-                $.each(editBox['options'], function(i) {
-                    console.log("jo");
-                    $(optionsContainer).append(this.name + "<input type=\"" + this.type + "\" value=\"" + this.value + "\" style=\"float: right;\"/><br><br>")
-                });
-
-                console.log(optionsContainer);
-
-                $.fancybox({
-                    maxWidth	: 800,
-                    maxHeight	: 600,
-                    fitToView	: true,
-                    width		: '70%',
-                    height		: '70%',
-                    autoSize	: false,
-                    title   : "<h3>" + editBox['title'] + "</h3><hr>",
-                    content : optionsContainer.innerHTML,
-                    helpers : {
-                        title: {
-                            type    : 'inside',
-                            position: 'top'
-                        }
-                    }
-                });
-            } catch(e) {
-                console.log(e); // DBG
-                var n = noty({
-                    layout  : 'topCenter',
-                    text    : 'Irgendwas ist schief gelaufen.<br>Bitte probieren Sie es später noch einmal.',
-                    type    : 'error',
-                    timeout : 5000
-                    });
-            }
-        });
-    });
-
     $('#add-mailboxfolder').on('click', function(e) {
         e.preventDefault();
         var uId = $(this).attr('data-uid');
@@ -284,25 +282,17 @@ $(document).ready(function() {
             });
     });
 
-    $('#new-document').fancybox({
-        beforeShow  : fancyBoxLoader,
-        maxWidth	: 800,
-        maxHeight	: 600,
-        fitToView	: false,
-        width		: '50%',
-        height		: '70%',
-        autoSize	: false,
-        closeClick	: false,
-        openEffect	: 'none',
-        closeEffect	: 'none'
-    });
-
     switch(getUrlGetParameter("action")) {
         case 'settings':
             getMailboxStatus();
             break;
+        case 'manage-label':
+            loadBox('.manage-mailboxfolder');
+            break;
+        case 'label':
+            loadBox('#new-document');
+            break;
         default:
-
             break;
     }
 

+ 1 - 1
templates/documentlist.php

@@ -25,4 +25,4 @@ foreach($documents as $document) {
 }
 ?>
 </table>
-<a id="new-document" href="ajax.php?action=getNewDocumentBox" type="button" class="btn btn-success fancybox.ajax">New Document</a>
+<a id="new-document" href="ajax.php?action=getNewDocumentBox" type="button" class="btn btn-success fancybox.ajax">Neues Dokument</a>