189cd4e2f58a9cc812f0c30a3a544f7d584f92d9
[ccsdk/features.git] /
1 /**
2  * Copyright 2010-2013 Ben Birch
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this software except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 (function( $, app, i18n ) {
17
18         var ui = app.ns("ui");
19
20         ui.RefreshButton = ui.SplitButton.extend({
21                 defaults: {
22                         timer: -1
23                 },
24                 init: function( parent ) {
25                         this.config.label = i18n.text("General.RefreshResults");
26                         this._super( parent );
27                         this.set( this.config.timer );
28                 },
29                 set: function( value ) {
30                         this.value = value;
31                         window.clearInterval( this._timer );
32                         if( this.value > 0 ) {
33                                 this._timer = window.setInterval( this._refresh_handler, this.value );
34                         }
35                 },
36                 _click_handler: function() {
37                         this._refresh_handler();
38                 },
39                 _select_handler: function( el, event ) {
40                         this.set( event.value );
41                         this.fire("change", this );
42                 },
43                 _refresh_handler: function() {
44                         this.fire("refresh", this );
45                 },
46                 _getItems: function() {
47                         return [
48                                 { text: i18n.text("General.ManualRefresh"), value: -1 },
49                                 { text: i18n.text("General.RefreshQuickly"), value: 100 },
50                                 { text: i18n.text("General.Refresh5seconds"), value: 5000 },
51                                 { text: i18n.text("General.Refresh1minute"), value: 60000 }
52                         ];
53                 }
54         });
55
56 })( this.jQuery, this.app, this.i18n );