Преглед на файлове

\#50: Neue Labels können hinzugefügt werden

Moritz Schmidt преди 10 години
родител
ревизия
a1099d58f2
променени са 5 файла, в които са добавени 102 реда и са изтрити 16 реда
  1. 42 4
      ajax.php
  2. 0 1
      includes/database.inc.php
  3. 15 0
      includes/label.inc.php
  4. 40 8
      scripts/custom.js
  5. 5 3
      templates/manage-labels.php

+ 42 - 4
ajax.php

@@ -86,12 +86,15 @@ switch($_REQUEST['action']) {
     case 'manageMailboxFolder':
         header("Status: 200 OK");
 
+        $allMailBoxes = Mailbox::getAllMailboxes(false);
+
         $editBox = array(
             "options"   => array(
                 array(
-                    "type"  => "select",
-                    "name"  => "account",
-                    "value" => Mailbox::getMailboxNameFromMailaccountId($_GET['mbId'])
+                    "type"      => "select",
+                    "name"      => "account",
+                    "value"     => Mailbox::getMailboxNameFromMailaccountId($_GET['mbId']),
+                    "values"    => array()
                 ),
                 array(
                     "type"  => "text",
@@ -102,6 +105,10 @@ switch($_REQUEST['action']) {
             "title"     => "Mailkonto bearbeiten"
         );
 
+        foreach($allMailBoxes as $mailBox) {
+            $editBox['options'][0]['values'][] = $mailBox->getUsername();
+        }
+
         echo json_encode($editBox);
 
         break;
@@ -149,6 +156,7 @@ switch($_REQUEST['action']) {
         echo json_encode(array_values($templateVars));
         break;
     case 'getMailboxStatus':
+        header("Status: 200 OK");
         $mailbox = Mailbox::getMailboxById($_REQUEST['mailboxId'], true);
         $mailboxStatus = array(
             "connected" => $mailbox->getConnected()
@@ -168,8 +176,38 @@ switch($_REQUEST['action']) {
 
         echo json_encode($_REQUEST);
 
-        //pa($_REQUEST);
+        break;
+    case 'getNewLabelBox':
+        header("Status: 200 OK");
+        $editBox = array(
+            "options"   => array(
+                array(
+                    "type"  => "text",
+                    "name"  => "name",
+                    "value" => ""
+
+                ),
+                array(
+                    "type"  => "text",
+                    "name"  => "path",
+                    "value" => ""
+                )
+            ),
+            "title"     => "Neues Label"
+        );
+
+        echo json_encode($editBox);
+        break;
+    case 'saveNewLabel':
+        header("Status: 200 OK");
+        Label::addLabel($_REQUEST['name'], $_REQUEST['path']);
+
+        // TODO: get status by DB (See: #40, #43)
+        $return = array(
+            "status"   => "OK"
+        );
 
+        echo json_encode($return);
         break;
     case 'debugTest': // for testing single methods etc.
         pa(Document::getDefaultDraft());

+ 0 - 1
includes/database.inc.php

@@ -62,7 +62,6 @@ class Database {
 	}
 
 	public function insertQuery($query) {
-		echo $query;
 		$stmt = $this->handle->prepare($query);
 		$stmt->execute();
 		$stmt->close();

+ 15 - 0
includes/label.inc.php

@@ -96,6 +96,21 @@ class Label {
 
         return $return[0];
     }
+
+    /**
+     * Add new Label to DB
+     *
+     * @param type $name  description
+     *
+     * @return type  the integer of the set mode used. FALSE if foo
+     *
+     */
+
+     public static function addLabel($name, $path) {
+         global $db;
+
+         $db->insertQuery("INSERT INTO `labels`(`name`, `path`) VALUES ('" . $name . "', '" . $path . "')");
+     }
 }
 
 

+ 40 - 8
scripts/custom.js

@@ -40,13 +40,16 @@ $(document).ready(function() {
                                 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>"
-                                    }
-                                });
+                                if(typeof this['values'] !== "undefined" && this['values']) {
+                                    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;
@@ -116,6 +119,31 @@ $(document).ready(function() {
         });
     }
 
+    function newLabelListener() {
+        $(document).on("click", "#save-new-label", function(e) {
+
+            e.preventDefault();
+
+            data = {
+                name: $("#editbox-input-name").val(),
+                path: $("#editbox-input-path").val()
+            };
+
+            $.getJSON("ajax.php?action=saveNewLabel", data, function(r) {
+                if(r['status'] == "OK") {
+                    location.reload();
+                } else {
+                    var n = noty({
+                        layout  : 'topCenter',
+                        text    : 'Irgendwas ist schief gelaufen.<br>Bitte probieren Sie es später noch einmal.',
+                        type    : 'error',
+                        timeout : 5000
+                        });
+                }
+            });
+        });
+    }
+
     function newDocumentListener() {
         $(document).on("change", ".fancybox-inner select", function(e) {
             reloadDraftVars();
@@ -129,7 +157,7 @@ $(document).ready(function() {
                 filename: $("#editbox-input-filename").val(),
                 labelId: getUrlGetParameter("labelId"),
                 draftVars: {}
-            }
+            };
 
             $(".editbox-draft-vars").each(function(i) {
                 data['draftVars'][$(this).attr("id").replace("editbox-draft-vars-", "")] = $(this).val();
@@ -368,6 +396,10 @@ $(document).ready(function() {
         case 'manage-label':
             loadBox('.manage-mailboxfolder', function() {});
             break;
+        case 'manage-labels':
+            loadBox('#add-label', function() { $('.fancybox-inner').append("<a href=\"#\"type=\"button\" id=\"save-new-label\" class=\"btn btn-success\">Label speichern</a>"); });
+            newLabelListener();
+            break;
         case 'label':
             loadBox('#new-document', function() { reloadDraftVars(); });
             newDocumentListener();

+ 5 - 3
templates/manage-labels.php

@@ -2,9 +2,6 @@
     <h1 class="page-header">Label verwalten</h1>
 
     <div class="row">
-        <?php
-            //pa($this->_['labels']);
-        ?>
         <table class="table table-striped">
             <thead>
                 <tr>
@@ -22,6 +19,11 @@
                     echo '</tr>';
                 }
             ?>
+            <tr>
+                <td><a href="ajax.php?action=getNewLabelBox" id="add-label"><i class="fa fa-plus-circle"></i></a></td>
+                <td></td>
+                <td></td>
+            </tr>
         </table>
     </div>
 </div>