partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

TimeDisplay.js (1651B)


      1 Ext.define('PartKeepr.TimeDisplay', {
      2     extend: 'Ext.Toolbar.TextItem',
      3 
      4     /**
      5      * Holds the time update task
      6      * @var object
      7      */
      8     updateTimeTask: null,
      9 
     10     /**
     11      * Holds the layout task
     12      * @var object
     13      */
     14     updateLayoutTask: null,
     15 
     16     /**
     17      * Stores the currently assigned date format
     18      * @var string
     19      */
     20     dateFormat: null,
     21 
     22     /**
     23      * Inits the component. Sets up two timers for updating the time and updating the widget's layout.
     24      *
     25      * @param none
     26      * @return nothing
     27      */
     28     initComponent: function ()
     29     {
     30         this.callParent();
     31 
     32         this.dateFormat = Ext.getDateFormat();
     33 
     34         this.updateTimeTask = {
     35             run: this.updateTime,
     36             interval: 280, // Update every 280ms. This is NOT 1 second due to overhead, causing skipping seconds
     37             scope: this
     38         };
     39     },
     40     /**
     41      * Start both updating tasks just before rendering starts.
     42      * @param none
     43      * @return nothing
     44      */
     45     beforeRender: function ()
     46     {
     47         this.callParent();
     48         Ext.TaskManager.start(this.updateTimeTask);
     49     },
     50     /**
     51      * Updates the time. Avoids setText because it's slow.
     52      *
     53      * @param none
     54      * @return nothing
     55      */
     56     updateTime: function ()
     57     {
     58         var dt = new Date();
     59 
     60         var format = Ext.getDateFormat();
     61         var string = Ext.Date.format(dt, format);
     62 
     63         this.el.update(string);
     64     },
     65     /**
     66      * When the widget is removed, destroy both tasks.
     67      *
     68      * @param none
     69      * @return nothing
     70      */
     71     onDestroy: function ()
     72     {
     73         Ext.TaskManager.stop(this.updateTimeTask);
     74     }
     75 });
     76