Add data-provider
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / resources / elasticsearch / plugins / head / src / app / ui / sidebarSection / sidebarSection.js
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.SidebarSection = ui.AbstractWidget.extend({
21                 defaults: {
22                         title: "",
23                         help: null,
24                         body: null,
25                         open: false
26                 },
27                 init: function() {
28                         this._super();
29                         this.el = $.joey( this._main_template() );
30                         this.body = this.el.children(".uiSidebarSection-body");
31                         this.config.open && ( this.el.addClass("shown") && this.body.css("display", "block") );
32                 },
33                 _showSection_handler: function( ev ) {
34                         var shown = $( ev.target ).closest(".uiSidebarSection")
35                                 .toggleClass("shown")
36                                         .children(".uiSidebarSection-body").slideToggle(200, function() { this.fire("animComplete", this); }.bind(this))
37                                 .end()
38                                 .hasClass("shown");
39                         this.fire(shown ? "show" : "hide", this);
40                 },
41                 _showHelp_handler: function( ev ) {
42                         new ui.HelpPanel({ref: this.config.help});
43                         ev.stopPropagation();
44                 },
45                 _main_template: function() { return (
46                         { tag: "DIV", cls: "uiSidebarSection", children: [
47                                 (this.config.title && { tag: "DIV", cls: "uiSidebarSection-head", onclick: this._showSection_handler, children: [
48                                         this.config.title,
49                                         ( this.config.help && { tag: "SPAN", cls: "uiSidebarSection-help pull-right", onclick: this._showHelp_handler, text: i18n.text("General.HelpGlyph") } )
50                                 ] }),
51                                 { tag: "DIV", cls: "uiSidebarSection-body", children: [ this.config.body ] }
52                         ] }
53                 ); }
54         });
55
56 })( this.jQuery, this.app, this.i18n );