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

\#62: Löschen jetzt möglich

Moritz Schmidt преди 10 години
родител
ревизия
5a74b1511c
променени са 4 файла, в които са добавени 61 реда и са изтрити 6 реда
  1. 10 0
      ajax.php
  2. 18 2
      includes/label.inc.php
  3. 28 2
      scripts/custom.js
  4. 5 2
      templates/manage-labels.php

+ 10 - 0
ajax.php

@@ -207,6 +207,16 @@ switch($_REQUEST['action']) {
             "status"   => "OK"
         );
 
+        echo json_encode($return);
+        break;
+    case 'removeLabel':
+        header("Status: 200 OK");
+        Label::removeLabel($_REQUEST['labelId']);
+
+        $return = array(
+            "status"    => "OK"
+        );
+
         echo json_encode($return);
         break;
     case 'debugTest': // for testing single methods etc.

+ 18 - 2
includes/label.inc.php

@@ -100,9 +100,10 @@ class Label {
     /**
      * Add new Label to DB
      *
-     * @param type $name  description
+     * @param string $name  Name of Label
+     * @param string $path  FS-Path of Label
      *
-     * @return type  the integer of the set mode used. FALSE if foo
+     * @return void
      *
      */
 
@@ -111,6 +112,21 @@ class Label {
 
          $db->insertQuery("INSERT INTO `labels`(`name`, `path`) VALUES ('" . $name . "', '" . $path . "')");
      }
+
+     /**
+     * Remove a Label by Label-ID
+     *
+     * @param int $labelId  ID of Label
+     *
+     * @return void
+     *
+     */
+
+     public static function removeLabel($labelId) {
+         global $db;
+
+         $db->removeQuery("DELETE FROM `labels` WHERE `id` = " . $labelId . ";");
+     }
 }
 
 

+ 28 - 2
scripts/custom.js

@@ -119,7 +119,7 @@ $(document).ready(function() {
         });
     }
 
-    function newLabelListener() {
+    function manageLabelsListener() {
         $(document).on("click", "#save-new-label", function(e) {
 
             e.preventDefault();
@@ -142,6 +142,32 @@ $(document).ready(function() {
                 }
             });
         });
+
+        $(document).on("click", ".remove-label", function(e) {
+            e.preventDefault();
+
+            tRow = $(this).parent().parent();
+
+            data = {
+                labelId: $(this).attr("data-id")
+            };
+
+            $.getJSON("ajax.php?action=removeLabel", data, function(r) {
+                if(r['status'] == "OK") {
+                    tRow.fadeOut(400, function() {
+                        tRow.remove();
+                    });
+
+                } 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() {
@@ -398,7 +424,7 @@ $(document).ready(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();
+            manageLabelsListener();
             break;
         case 'label':
             loadBox('#new-document', function() { reloadDraftVars(); });

+ 5 - 2
templates/manage-labels.php

@@ -7,7 +7,8 @@
                 <tr>
                     <th>#</th>
                     <th>Name</th>
-                    <th>Manage</th>
+                    <th></th>
+                    <th></th>
                 </tr>
             </thead>
             <?php
@@ -15,7 +16,8 @@
                     echo '<tr>';
                     echo '<td>' . $label->getId() . '</td>';
                     echo '<td>' . $label->getName() . '</td>';
-                    echo '<td><a href="?action=manage-label&labelId=' . $label->getId() . '" role="button" class="btn btn-primary">Manage</a></td>';
+                    echo '<td><a href="?action=manage-label&labelId=' . $label->getId() . '"><i class="fa fa-wrench"></i></a></td>';
+                    echo '<td><a href="#" class="remove-label" data-id="' . $label->getId() . '"><i class="fa fa-minus-circle"></i></a></td>';
                     echo '</tr>';
                 }
             ?>
@@ -23,6 +25,7 @@
                 <td><a href="ajax.php?action=getNewLabelBox" id="add-label"><i class="fa fa-plus-circle"></i></a></td>
                 <td></td>
                 <td></td>
+                <td></td>
             </tr>
         </table>
     </div>