]> _ Git - cubist_cms-back.git/commitdiff
wip #2834 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 14 Jun 2019 10:10:59 +0000 (12:10 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 14 Jun 2019 10:10:59 +0000 (12:10 +0200)
src/app/Magic/Models/CubistMagicAbstractModel.php
src/resources/lang/fr/fields.php [new file with mode: 0644]
src/resources/lang/fr/templates.php [new file with mode: 0644]
src/resources/views/when.blade.php

index b0cd1ab714cdd0b5b4eff2ea5e00b1ccdac97653..21714b03f35b18680eaaf513eb72a5f6885738a4 100644 (file)
@@ -89,6 +89,8 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $res;
     }
 
+
+
     public function onRetreived(){
 
     }
diff --git a/src/resources/lang/fr/fields.php b/src/resources/lang/fr/fields.php
new file mode 100644 (file)
index 0000000..d563f3b
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+return [
+    /*
+    |--------------------------------------------------------------------------
+    | Templates Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are used for Cubist backpack
+    |
+    */
+    'first_value' => 'Valeur minimale',
+    'second_value' => 'Valeur maximale'
+];
diff --git a/src/resources/lang/fr/templates.php b/src/resources/lang/fr/templates.php
new file mode 100644 (file)
index 0000000..6ad6f5d
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+return [
+    /*
+    |--------------------------------------------------------------------------
+    | Templates Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are used for Cubist backpack
+    |
+    */
+    'name' => 'Name',
+    'value' => 'Value',
+    'description' => 'Description',
+    'template_singular' => 'template',
+    'template_plural' => 'templates',
+    'parent' => 'Parent',
+    'field_singular' => 'Field',
+    'field_plural' => 'Fields',
+    'first_value' => 'First value',
+    'second_value' => 'Second value'
+
+];
index ed224a2d166457c5513073e72ca50be4af9c2502..dcc34fa56a1baf732ee39253c0589b3914d70915 100644 (file)
                 }
 
                 $(form).find('[data-when]').removeClass('when-visible').each(function () {
-                    var conditions = $(this).data('when');
+                    if ($(this).data('when-normalized') === undefined) {
+                        $(this).data('when-normalized', normalizeWhen($(this).data('when')));
+                    }
+                    var when = $(this).data('when-normalized');
                     var match = true;
-                    $.each(conditions, function (k, v) {
-                        if (!Array.isArray(v)) {
-                            v = [v];
-                        }
-                        var val = $(form).find('[name="' + k + '"]').val();
-                        var valnum = parseFloat(val);
-                        if (!isNumber(valnum)) {
-                            valnum = val;
-                        }
-                        if (v.indexOf(val) === -1 && v.indexOf(valnum) === -1) {
-                            console.log('no match', v, val, valnum);
-                            match = false;
+                    var order = 1000;
+                    $.each(when, function (property, conditions) {
+                        var val = $(form).find('[name="' + property + '"]').val().toString();
+                        $.each(conditions, function (k, condition) {
+                            if (condition.id !== val) {
+                                match = false;
+                                return false;
+                            }
+                            order = Math.min(order, condition.order);
+                        });
+                        if (match === false) {
                             return false;
                         }
                     });
 
                     if (match) {
                         $(this).addClass('when-visible');
+                        $(this).attr('data-when-order', order);
                     }
                 });
+
+                orderWhen();
             };
 
             function isNumber(n) {
                 triggersWhenChange($(this));
             });
             triggersWhenChange();
+
+            function orderWhen() {
+                $("[data-when]").parent().each(function () {
+                    // Inspired from https://stackoverflow.com/a/14160529/1082031
+                    $(this).find('[data-when-order]').sort(function (a, b) {
+                        return $(a).data('when-order') - $(b).data('when-order');
+                    }).appendTo(this);
+                });
+            }
+
+            function normalizeWhen(w) {
+                var res = {};
+                $.each(w, function (property, conditions) {
+                    if (!Array.isArray(conditions)) {
+                        conditions = [conditions];
+                    }
+                    var normalizedConditions = [];
+                    $.each(conditions, function (k, condition) {
+                        if (!isObject(condition)) {
+                            condition = {id: condition};
+                        }
+                        if (!condition.hasOwnProperty('order')) {
+                            condition.order = k;
+                        }
+                        condition.id = condition.id.toString();
+                        normalizedConditions[k] = condition;
+                    });
+                    res[property] = normalizedConditions;
+                });
+                return res;
+            }
+
+            function isObject(value) {
+                return value && typeof value === 'object' && value.constructor === Object;
+            }
+
         });
 
     </script>