creating a list
[fnpeditor.git] / fnpjs / layout.js
1 define(['libs/jquery-1.9.1.min', 'libs/underscore-min'], function($ ,_) {
2     'use strict';
3       
4     var Layout = function(template) {
5         var layout = this;
6         this.dom = $(_.template(template)());
7         this.views = {};
8         
9         this.dom.onShow = function() {
10             _.values(layout.views).forEach(function(view) {
11                 if(view.onShow)
12                     view.onShow();
13             });
14         };
15         this.dom.onHide = function() {
16             _.values(layout.views).forEach(function(view) {
17                 if(view.onHide)
18                     view.onHide();
19             });
20         };
21         
22     };
23     
24     Layout.prototype.setView = function(place, view) {
25         this.dom.find('[fnpjs-place=' + place + ']').append(view);
26         this.views[place] = view;
27         if(this.dom.is(':visible') && view.onShow) {
28             view.onShow();
29         }
30     };
31     
32     Layout.prototype.getAsView = function() {
33         return this.dom;
34     };
35     
36     return {Layout: Layout};
37 });