]> _ Git - cubist_cms-back.git/commitdiff
#2783
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 7 Jun 2019 14:36:54 +0000 (16:36 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 7 Jun 2019 14:36:54 +0000 (16:36 +0200)
src/CubistBackpackServiceProvider.php
src/app/Magic/Fields/Integer.php [new file with mode: 0644]
src/app/Magic/Fields/Number.php
src/app/Magic/Fields/Range.php
src/resources/lang/en/fields.php [new file with mode: 0644]
src/resources/views/fields/rangeofvalues.blade.php

index b3b1a43c63fdc5ec790597b027158e854525db84..173d52069d5769f490a3be6e8f2f5dddaee8500e 100644 (file)
@@ -25,7 +25,7 @@ class CubistBackpackServiceProvider extends ServiceProvider
      */
     public function boot()
     {
-        $this->loadTranslationsFrom(__DIR__ . '/resources/lang', self::NAMESPACE);
+        $this->loadTranslationsFrom(realpath(__DIR__ . '/resources/lang'), self::NAMESPACE);
         foreach (glob(__DIR__ . '/routes/cubist/backpack/*.php') as $filename) {
             $this->loadRoutesFrom($filename);
         }
diff --git a/src/app/Magic/Fields/Integer.php b/src/app/Magic/Fields/Integer.php
new file mode 100644 (file)
index 0000000..c2a4a7e
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Fields;
+
+
+class Integer extends Number
+{
+    protected $_step = 1;
+}
index 542bad548ad8e0a68f372c5a87dfc40c821bb6d4..aa3135e42c8b18f9e0ad32e23abc3dddfa7249df 100644 (file)
@@ -9,4 +9,23 @@ class Number extends Field
     protected $_adminType = 'number';
     protected $_databaseType = 'float';
     protected $_columnType = 'number';
+    protected $_step = 'any';
+    protected $_min = null;
+    protected $_max = null;
+
+    public function getDefaultAttributes()
+    {
+        $res = parent::getDefaultAttributes();
+        $attrs = ['min', 'max', 'step'];
+        $defaults = [];
+        foreach ($attrs as $attr) {
+            if (null === $this->{'_' . $attr}) {
+                continue;
+            }
+            $defaults[$attr] = $this->{'_' . $attr};
+        }
+
+        $res['attributes'] = array_merge($defaults, $res['attributes']);
+        return $res;
+    }
 }
index b537d7f1c0f95094f54bd93760fb61f7ed0f11dc..f876143be6b2465abfd59e04187a9ef967a3727f 100644 (file)
@@ -6,8 +6,16 @@ namespace Cubist\Backpack\app\Magic\Fields;
 
 use Cubist\Backpack\CubistBackpackServiceProvider;
 
-class Range extends Field
+class Range extends Number
 {
     protected $_adminType = 'rangeofvalues';
     protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+
+    public function getDefaultAttributes()
+    {
+        $res = parent::getDefaultAttributes();
+        $res['first_label'] = trans('cubist_back::first_value');
+        $res['second_label'] = trans('cubist_back::second_value');
+        return $res;
+    }
 }
diff --git a/src/resources/lang/en/fields.php b/src/resources/lang/en/fields.php
new file mode 100644 (file)
index 0000000..28f15f2
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+return [
+    /*
+    |--------------------------------------------------------------------------
+    | Templates Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are used for Cubist backpack
+    |
+    */
+    'first_value' => 'First value',
+    'second_value' => 'Second value'
+];
index 8157434873a65d1fb40677f51a247ef0fe30e9ed..860bfd7a6fb5b12ded08502780a505b7e7bb02b6 100644 (file)
@@ -1,15 +1,21 @@
-<!-- field_type_name -->
+<!-- range of values -->
 <div @include('crud::inc.field_wrapper_attributes') >
     <label>{!! $field['label'] !!}</label>
-    <div @include('crud::inc.field_attributes')>
-        <input
-            type="text"
-            name="{{ $field['name'] }}[min]"
-        >
-        <input
-            type="text"
-            name="{{ $field['name'] }}[max]"
-        >
+    <div class="rangeofvalues__wrapper">
+        <div class="rangeofvalues__field">
+            <label>{!! $field['first_label'] !!}</label>
+            <input @include('crud::inc.field_attributes')
+                   type="text"
+                   name="{{ $field['name'] }}[min]"
+            >
+        </div>
+        <div class="rangeofvalues__field">
+            <label>{!! $field['second_label'] !!}</label>
+            <input @include('crud::inc.field_attributes')
+                   type="text"
+                   name="{{ $field['name'] }}[max]"
+            >
+        </div>
     </div>
 
     {{-- HINT --}}
     {{-- push things in the after_styles section --}}
 
     @push('crud_fields_styles')
-        <!-- no styles -->
+        <style type="text/css">
+            .rangeofvalues__wrapper {
+                width: 100%;
+                white-space: nowrap;
+            }
+
+            .rangeofvalues__field {
+                width: 50%;
+                display: inline-block;
+                padding: 0 15px;
+                box-sizing: border-box;
+            }
+
+            .rangeofvalues__field label{
+                font-weight: 400;
+            }
+
+            .rangeofvalues__field:first-child {
+                padding-left: 0;
+            }
+
+            .rangeofvalues__field:last-child {
+                padding-right: 0;
+            }
+        </style>
     @endpush
 
     {{-- FIELD EXTRA JS --}}