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