Add period to event finder option state
authorMichael Spahn <m.spahn@metaways.de>
Mon, 26 Jun 2017 11:32:31 +0000 (13:32 +0200)
committerCornelius Weiss <c.weiss@metaways.de>
Mon, 26 Jun 2017 13:21:39 +0000 (15:21 +0200)
Change-Id: If9a46ea742ec888a934682faf32f7d9d8757f76b
Reviewed-on: http://gerrit.tine20.com/customers/4949
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Cornelius Weiss <c.weiss@metaways.de>
Tested-by: Cornelius Weiss <c.weiss@metaways.de>
tine20/Calendar/js/EventFinderOptionsDialog.js
tine20/Tinebase/css/Tinebase.css
tine20/Tinebase/js/RangeSliderComponent.js
tine20/Tinebase/js/common.js

index c39f54e..f9af0fa 100644 (file)
@@ -118,35 +118,75 @@ Tine.Calendar.EventFinderOptionsDialog = Ext.extend(Ext.Panel, {
         this.window.close();
     },
 
+    /**
+     * Get a time period of a given slider range
+     *
+     *    0:0:0 - 23:59:59
+     *
+     * @param range
+     * @return {{from: *, until: *}}
+     */
+    getPeriodFromSliderRange: function (range) {
+        var hoursStart = Tine.Tinebase.common.trunc(range[0]);
+        var minStart = Tine.Tinebase.common.trunc(Math.round((range[0] % 1) * 100) * 0.60);
+
+        var hoursEnd = Tine.Tinebase.common.trunc(range[1]);
+        var minEnd = Tine.Tinebase.common.trunc((range[1] % 1) * 100 * 0.60);
+
+        var startDate = new Date();
+        startDate.setHours(hoursStart);
+        startDate.setMinutes(minStart);
+        startDate.setSeconds(0);
+
+        var endDate = new Date();
+        endDate.setHours(hoursEnd);
+        endDate.setMinutes(minEnd);
+        endDate.setSeconds((hoursEnd === 23 && minEnd === 59) ? 59 : 0);
+
+        var pattern = 'H:i:s';
+
+        return {
+            from: startDate.format(pattern),
+            until: endDate.format(pattern)
+        };
+    },
+
     onSaveAndClose: function () {
         var data = [{
             id: 'monday',
             active: this.mondayCheckbox.getValue(),
-            config: this.mondaySlider.getRange()
+            config: this.mondaySlider.getRange(),
+            period: this.getPeriodFromSliderRange(this.mondaySlider.getRange())
         }, {
             id: 'tuesday',
             active: this.tuesdayCheckbox.getValue(),
-            config: this.tuesdaySlider.getRange()
+            config: this.tuesdaySlider.getRange(),
+            period: this.getPeriodFromSliderRange(this.tuesdaySlider.getRange())
         }, {
             id: 'wednesday',
             active: this.wednesdayCheckbox.getValue(),
-            config: this.wednesdaySlider.getRange()
+            config: this.wednesdaySlider.getRange(),
+            period: this.getPeriodFromSliderRange(this.wednesdaySlider.getRange())
         }, {
             id: 'thursday',
             active: this.thursdayCheckbox.getValue(),
-            config: this.thursdaySlider.getRange()
+            config: this.thursdaySlider.getRange(),
+            period: this.getPeriodFromSliderRange(this.thursdaySlider.getRange())
         }, {
             id: 'friday',
             active: this.fridayCheckbox.getValue(),
-            config: this.fridaySlider.getRange()
+            config: this.fridaySlider.getRange(),
+            period: this.getPeriodFromSliderRange(this.fridaySlider.getRange())
         }, {
             id: 'saturday',
             active: this.saturdayCheckbox.getValue(),
-            config: this.saturdaySlider.getRange()
+            config: this.saturdaySlider.getRange(),
+            period: this.getPeriodFromSliderRange(this.saturdaySlider.getRange())
         }, {
             id: 'sunday',
             active: this.sundayCheckbox.getValue(),
-            config: this.sundaySlider.getRange()
+            config: this.sundaySlider.getRange(),
+            period: this.getPeriodFromSliderRange(this.sundaySlider.getRange())
         }];
 
         Ext.state.Manager.set(this.stateId, data);
@@ -213,8 +253,8 @@ Tine.Calendar.EventFinderOptionsDialog = Ext.extend(Ext.Panel, {
      */
     getFormItems: function () {
         var wkdayItems = [];
-        for (var i=0,d; i<7; i++) {
-            d = (i+Ext.DatePicker.prototype.startDay)%7
+        for (var i = 0, d; i < 7; i++) {
+            d = (i + Ext.DatePicker.prototype.startDay) % 7;
             wkdayItems.push(this.getCheckboxSliderRowFor(this.wkdays[d]));
         }
 
@@ -230,7 +270,7 @@ Tine.Calendar.EventFinderOptionsDialog = Ext.extend(Ext.Panel, {
             items: wkdayItems
         }];
 
-        var items = {
+        return {
             xtype: 'tabpanel',
             border: false,
             plain: true,
@@ -241,7 +281,6 @@ Tine.Calendar.EventFinderOptionsDialog = Ext.extend(Ext.Panel, {
                 ptype: 'ux.tabpanelkeyplugin'
             }],
             activeTab: 0,
-            border: false,
             items: [{
                 title: this.title,
                 autoScroll: true,
@@ -256,8 +295,6 @@ Tine.Calendar.EventFinderOptionsDialog = Ext.extend(Ext.Panel, {
                 }]
             }]
         };
-
-        return items;
     }
 });
 
index 3ccf50c..4ecc985 100644 (file)
@@ -1116,4 +1116,9 @@ textarea.x-form-field.tinebase-editmultipledialog-noneedit {
 .rangeslider-component .rangeslider-component-slider {
     background-color: #b7f8bd;
     overflow: hidden;
+}
+
+.x-item-disabled.rangeslider-component .rangeslider-component-slider,
+.x-item-disabled.rangeslider-component .rangeslider-component-slider-label {
+    visibility: hidden !important;
 }
\ No newline at end of file
index 38d185f..842668f 100644 (file)
@@ -103,11 +103,11 @@ Tine.Tinebase.RangeSliderComponent = Ext.extend(Ext.BoxComponent, {
             this.sliderLabel.show();
         }
 
-        var hoursStart = this.trunc(this.currentStart);
-        var minStart = this.trunc(Math.round((this.currentStart % 1) * 100) * 0.60);
+        var hoursStart = Tine.Tinebase.common.trunc(this.currentStart);
+        var minStart = Tine.Tinebase.common.trunc(Math.round((this.currentStart % 1) * 100) * 0.60);
 
-        var hoursEnd = this.trunc(this.currentEnd);
-        var minEnd = this.trunc((this.currentEnd % 1) * 100 * 0.60);
+        var hoursEnd = Tine.Tinebase.common.trunc(this.currentEnd);
+        var minEnd = Tine.Tinebase.common.trunc((this.currentEnd % 1) * 100 * 0.60);
 
         var startDate = new Date();
         startDate.setHours(hoursStart);
@@ -124,21 +124,6 @@ Tine.Tinebase.RangeSliderComponent = Ext.extend(Ext.BoxComponent, {
 
     /**
      * @private
-     * @param x
-     * @return {*}
-     */
-    trunc: function (x) {
-        if (isNaN(x)) {
-            return NaN;
-        }
-        if (x > 0) {
-            return Math.floor(x);
-        }
-        return Math.ceil(x);
-    },
-
-    /**
-     * @private
      */
     getCropFactor: function () {
         return this.sliderWrap.getWidth(true) / this.maxRange;
index fc974ae..ba048c6 100644 (file)
@@ -815,6 +815,24 @@ Tine.Tinebase.common = {
                 }
             }
         }, this);
+    },
+
+    /**
+     * Math.trunc polyfill
+     *
+     * https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
+     *
+     * @param x
+     * @return {*}
+     */
+    trunc: function (x) {
+        if (isNaN(x)) {
+            return NaN;
+        }
+        if (x > 0) {
+            return Math.floor(x);
+        }
+        return Math.ceil(x);
     }
 };