Fixes #4189: theme box fails when entering second theme.
[redakcja.git] / src / redakcja / static / js / wiki / view_properties.js
index 571dac0..e6ad1ca 100644 (file)
                     "name": "alt",
                     "type": "text",
                 },
+                {
+                    "name": "szer",
+                    "type": "percent",
+                },
+                {
+                    "name": "wyrownanie",
+                    "type": "select",
+                    "options": ["lewo", "srodek", "prawo"],
+                },
+                {
+                    "name": "oblew",
+                    "type": "bool",
+                },
             ],
         },
         "ref": {
             self.$pane = $("#side-properties");
             
             $(document).on('click', '[x-node]', function(e) {
-                e.stopPropagation();
-                self.edit(this);
+                if (!e.redakcja_edited) {
+                    e.redakcja_edited = true;
+                    self.edit(this);
+                }
             });
 
             self.$pane.on('click', '#parents li', function(e) {
             self.$pane.on('change', '.form-control', function() {
                 let $input = $(this);
 
+                let inputval;
+                if ($input.attr('type') == 'checkbox') {
+                    inputval = $input.is(':checked');
+                } else {
+                    inputval = $input.val();
+                }
+                
                 if ($input.data("edited")) {
-                    $input.data("edited").text($input.val());
+                    $input.data("edited").text(inputval);
                     return;
                 }
                 
@@ -56,7 +78,8 @@
                         w(222)
                         let $xmlelem = $($.parseXML(xml));
                         w(333, $xmlelem)
-                        $xmlelem.contents().attr($input.data('property'), $input.val());
+                        w($input.data('property'), $input.val());
+                        $xmlelem.contents().attr($input.data('property'), inputval);
                         w(444, $xmlelem)
                         let newxml = (new XMLSerializer()).serializeToString($xmlelem[0]);
                         w(555, newxml)
         let nodeDef = elementDefs[node];
         if (nodeDef && nodeDef.attributes) {
             $.each(nodeDef.attributes, function(i, a) {
-                self.addEditField(a.name, a.type, $(element).attr('data-wlf-' + a.name)); // ...
+                self.addEditField(a, $(element).attr('data-wlf-' + a.name)); // ...
             })
         }
 
             $("> .RDF > .Description > [x-node]", $node).each(function() {
                 $meta = $(this);
                 self.addEditField(
-                    $meta.attr('x-node'),
-                    null,
+                    {"name": $meta.attr('x-node'),},
                     $meta.text(),
                     $meta,
                 );
         }
     };
         
-    PropertiesPerspective.prototype.addEditField = function(name, type, value, elem) {
+    PropertiesPerspective.prototype.addEditField = function(defn, value, elem) {
         let self = this;
         let $form = $("#properties-form", self.$pane);
 
         let $fg = $("<div class='form-group'>");
-        $("<label/>").attr("for", "property-" + name).text(name).appendTo($fg);
+        $("<label/>").attr("for", "property-" + defn.name).text(defn.name).appendTo($fg);
         let $input;
-        if (type == 'text') {
+        switch (defn.type) {
+        case 'text':
             $input = $("<textarea>");
+            break;
+        case 'select':
+            $input = $("<select>");
+            $.each(defn.options, function(i, e) {
+                $("<option>").text(e).appendTo($input);
+            });
+            break;
+        case 'bool':
+            $input = $("<input type='checkbox'>");
+            break;
+        default:
+            $input = $("<input>");
+        }
+
+        $input.addClass("form-control").attr("id", "property-" + defn.name).data("property", defn.name);
+        if ($input.attr('type') == 'checkbox') {
+            $input.prop('checked', value == 'true');
         } else {
-            $input = $("<input>")
+            $input.val(value);
         }
-        // val?
-        $input.addClass("form-control").attr("id", "property-" + name).data("property", name).val(value);
+        
         if (elem) {
             $input.data("edited", elem);
         }