d254bbd2fdb2982832fba96c16e27e31e936d323
[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         var services = app.ns("services");
20
21         ui.ClusterConnect = ui.AbstractWidget.extend({
22                 defaults: {
23                         cluster: null
24                 },
25                 init: function() {
26                         this._super();
27                         this.prefs = services.Preferences.instance();
28                         this.cluster = this.config.cluster;
29                         this.el = $.joey(this._main_template());
30                         this.cluster.get( "", this._node_handler );
31                 },
32                 
33                 _node_handler: function(data) {
34                         if(data) {
35                                 this.prefs.set("app-base_uri", this.cluster.base_uri);
36                         }
37                 },
38                 
39                 _reconnect_handler: function() {
40                         var base_uri = this.el.find(".uiClusterConnect-uri").val();
41                         $("body").empty().append(new app.App("body", { id: "es", base_uri: base_uri }));
42                 },
43                 
44                 _main_template: function() {
45                         return { tag: "SPAN", cls: "uiClusterConnect", children: [
46                                 { tag: "INPUT", type: "text", cls: "uiClusterConnect-uri", onkeyup: function( ev ) {
47                                         if(ev.which === 13) {
48                                                 ev.preventDefault();
49                                                 this._reconnect_handler();
50                                         }
51                                 }.bind(this), id: this.id("baseUri"), value: this.cluster.base_uri },
52                                 { tag: "BUTTON", type: "button", text: i18n.text("Header.Connect"), onclick: this._reconnect_handler }
53                         ]};
54                 }
55         });
56
57 })( this.jQuery, this.app, this.i18n );
58