瀏覽代碼

Same, lot of stuff

Brendan Abolivier 9 年之前
父節點
當前提交
25034e3c8c
共有 4 個文件被更改,包括 67 次插入17 次删除
  1. 22
    0
      controllers/document.php
  2. 1
    0
      index.php
  3. 43
    16
      lib/platypuce.js
  4. 1
    1
      views/list.html.php

+ 22
- 0
controllers/document.php 查看文件

@@ -25,6 +25,28 @@ function add_document()
25 25
     ));
26 26
 }
27 27
 
28
+function alter_document($documentid)
29
+{
30
+    $doc = new Document($documentid);
31
+
32
+    // We'll need to parse the PUT body to get our arguments
33
+    $params = file_get_contents("php://input", "r");
34
+
35
+    $putParams = array();
36
+
37
+    while(preg_match("/&/", $params))
38
+    {
39
+        $param = strstr($params, "&", true);
40
+        $params = substr(strstr($params, "&"), 1);
41
+        $putParams[strstr($param, "=", true)] = substr(strstr($param, "="), 1);
42
+    }
43
+    // We need it one more time for the last argument
44
+    $param = $params;
45
+    $putParams[strstr($param, "=", true)] = substr(strstr($param, "="), 1);
46
+
47
+    var_dump($putParams);
48
+}
49
+
28 50
 function delete_document($fileid)
29 51
 {
30 52
     (new Document($fileid))->erase();

+ 1
- 0
index.php 查看文件

@@ -13,6 +13,7 @@ dispatch_post("/document",              "add_document");
13 13
 dispatch_post("/promo",                 "add_promo");
14 14
 
15 15
 dispatch_put("/data/:dataid",           "alter_data");
16
+dispatch_put("/document/:documentid",   "alter_document");
16 17
 dispatch_put("/promo/:promoid",         "alter_promo");
17 18
 
18 19
 dispatch_delete("/document/:fileid",    "delete_document");

+ 43
- 16
lib/platypuce.js 查看文件

@@ -1,33 +1,60 @@
1
-var dataSelect = "";
2
-
3 1
 function checkPromoId(promoid)
4 2
 {
5 3
     return promoid.match(/A[1-5]/) != null;
6 4
 }
7 5
 
8
-if($("title").text() === "Documents") {
9
-    dataSelect = $("option")[0].value;
10
-}
11
-
12
-$(document).on('change', 'select', function(e) {
13
-    if($("title").text() === "Documents") {
14
-        dataSelect = this.options[e.target.selectedIndex].value;
15
-    }
16
-});
17
-
18
-$('.fa-pencil').on("click", function() {
6
+function editRow() {
19 7
     var row = $(this).parent().parent();
20 8
     var rang = $(row.children()[0]);
9
+    var promo = $(row.children()[1]);
21 10
     var rangValeur = rang.html();
11
+    var promoValeur = $(promo[0]).attr("class");
12
+    var promos = $("#promo").children();
13
+    var str = '<select class="tempPromos">';
14
+    var selected = "";
15
+
22 16
     rang.html('<input type="number" value="'+rangValeur+'" size="2" style="width:35px" />');
17
+    $(promo[0]).removeClass(promoValeur);
18
+    for(var i = 0; i < promos.length; i++)
19
+    {
20
+        if (promos[i].value === promoValeur)
21
+        {
22
+            selected = "selected";
23
+        }
24
+        else
25
+        {
26
+            selected = "";
27
+        }
28
+        str += '<option value="'+promos[i].value+'" '+selected+'>'+promos[i].text+'</option>';
29
+    }
30
+    str += "</select>";
31
+    promo.html(str);
23 32
     $(this).addClass("fa-check");
24 33
     $(this).removeClass("fa-pencil");
25 34
     $(this).off("click");
26 35
     $(this).on("click", function () {
27
-        rangValeur = $(rang.children()[0]).value;
36
+        rangValeur = $(rang.children()[0]).val();
28 37
         rang.html(rangValeur);
38
+        promoValeur = promo.children().val();
39
+        promo.addClass(promoValeur);
40
+        var promoName = "";
41
+        for(var i = 0; i < promos.length; i++)
42
+        {
43
+            if (promos[i].value === promoValeur)
44
+            {
45
+                promoName = promos[i].text;
46
+            }
47
+        }
48
+        promo.html(promoName);
49
+        $(this).addClass("fa-pencil");
50
+        $(this).removeClass("fa-check");
51
+        // Insert AJAX request here
52
+        $(this).off("click");
53
+        $(this).on("click", editRow);
29 54
     });
30
-});
55
+}
56
+
57
+$('.fa-pencil').on("click", editRow);
31 58
 
32 59
 $('#addForm').submit(function(e) {
33 60
     e.preventDefault();
@@ -37,7 +64,7 @@ $('#addForm').submit(function(e) {
37 64
     {
38 65
         case "Documents":
39 66
             data.append("document", $("#file")[0].files[0]);
40
-            data.append("promo", dataSelect);
67
+            data.append("promo", $("#promo").val());
41 68
             data.append("rang", $("#rang").val());
42 69
             data.append("libelle", $("#libelle").val());
43 70
 

+ 1
- 1
views/list.html.php 查看文件

@@ -79,7 +79,7 @@
79 79
             foreach ($element as $field => $value) {
80 80
                 if (is_array($value)) {
81 81
                     ?>
82
-                    <td id="<?php echo $value["id"]; ?>"><?php echo $value["libelle"]; ?></td>
82
+                    <td class="<?php echo $value["id"]; ?>"><?php echo $value["libelle"]; ?></td>
83 83
                     <?php
84 84
                 } else {
85 85
                     ?>