63d097723a214aaba8eee9e415a7afb64f48304b
[ccsdk/features.git] /
1 (function( $, app, i18n ) {
2
3         var ui = app.ns("ui");
4         var services = app.ns("services");
5
6         ui.ClusterConnect = ui.AbstractWidget.extend({
7                 defaults: {
8                         cluster: null
9                 },
10                 init: function() {
11                         this._super();
12                         this.prefs = services.Preferences.instance();
13                         this.cluster = this.config.cluster;
14                         this.el = $.joey(this._main_template());
15                         this.cluster.get( "", this._node_handler );
16                 },
17                 
18                 _node_handler: function(data) {
19                         if(data) {
20                                 this.prefs.set("app-base_uri", this.cluster.base_uri);
21                         }
22                 },
23                 
24                 _reconnect_handler: function() {
25                         var base_uri = this.el.find(".uiClusterConnect-uri").val();
26                         $("body").empty().append(new app.App("body", { id: "es", base_uri: base_uri }));
27                 },
28                 
29                 _main_template: function() {
30                         return { tag: "SPAN", cls: "uiClusterConnect", children: [
31                                 { tag: "INPUT", type: "text", cls: "uiClusterConnect-uri", onkeyup: function( ev ) {
32                                         if(ev.which === 13) {
33                                                 ev.preventDefault();
34                                                 this._reconnect_handler();
35                                         }
36                                 }.bind(this), id: this.id("baseUri"), value: this.cluster.base_uri },
37                                 { tag: "BUTTON", type: "button", text: i18n.text("Header.Connect"), onclick: this._reconnect_handler }
38                         ]};
39                 }
40         });
41
42 })( this.jQuery, this.app, this.i18n );
43