Added license header
[ajatus.git] / js / ajatus.development.js
blob86ee56d534b2fbe07ac507df5c7a2a0b9dbc5c34
1 /*
2  * This file is part of
3  *
4  * Ajatus - Distributed CRM
5  * @requires jQuery v1.2.1
6  * 
7  * Copyright (c) 2007 Jerry Jalava <jerry.jalava@gmail.com>
8  * Copyright (c) 2007 Nemein Oy <http://nemein.com>
9  * Website: http://ajatus.info
10  * Licensed under the GPL license
11  * http://www.gnu.org/licenses/gpl.html
12  * 
13  */
15 (function($){
16     $.ajatus = $.ajatus || {};
17     
18     $.ajatus.development = {
19     };
20     // $.extend($.ajatus.development, {
21     // });
22     
23     $.ajatus.development.view = {
24         title: 'Development',
25         icon: 'development.png',
26         options: {},
27         application_view: true,
28         history_support: true,
29         has_additional_views: true,
30         icongrid: null,
31         
32         generate_additional_views: function(add, icongrid) {
33             var views = {};
34             
35             if (typeof add == 'undefined') {
36                 var add = false;
37             }
38             if (typeof icongrid == 'undefined') {
39                 var icongrid = true;
40             }
41             
42             $.each($.ajatus.development.subview.available, function(i, name){
43                 var view = $.ajatus.development.subview[name];
44                 
45                 var vhash = '#view.development.'+name;
46                 if (typeof view.view_hash != 'undefined') {
47                     vhash = view.view_hash;
48                 }
49                 
50                 var view_data = {
51                     title: view.title,
52                     view_hash: vhash
53                 };
54                 
55                 if (typeof view.icon != 'undefined') {
56                     view_data.icon = view.icon;
57                 }
58                 
59                 views[name] = view_data;
60             });
61             
62             if (add) {
63                 var app_tab_holder = $('#tabs-application ul');
64                 if (icongrid) {
65                     $.ajatus.development.view.icongrid = new $.ajatus.renderer.icongrid({
66                         title: 'Development tools',
67                         width: 50,
68                         attach: false
69                     });
70                 }
71                 
72                 app_tab_holder.html('');
73                 $.each(views, function(name, data){                        
74                     var tab = $('<li><a href="'+data.view_hash+'"><span>'+$.ajatus.i10n.get(data.title)+'</span></a></li>');
75                     if (typeof data.icon != 'undefined') {
76                         tab = $('<li class="iconified"><a href="'+data.view_hash+'" title="'+$.ajatus.i10n.get(data.title)+'"><img src="'+ $.ajatus.preferences.client.theme_icons_url + data.icon + '" /></a></li>');
77                         
78                         if (icongrid) {
79                             $.ajatus.development.view.icongrid.add_item({
80                                 title: $.ajatus.i10n.get(data.title),
81                                 icon: data.icon,
82                                 hash: data.view_hash
83                             });
84                         }
85                     }
86                     tab.appendTo(app_tab_holder);
87                 });
88             }
89             
90             return views;
91         },
92         
93         render: function(view) {            
94             if (   typeof view == 'undefined'
95                 || view == 'frontpage')
96             {
97                 view = 'frontpage';
98                 $.ajatus.development.view.generate_additional_views(true);
99             } else {
100                 $.ajatus.development.view.generate_additional_views(false);
101             }
102             
103             if (   view != 'frontpage'
104                 && typeof $.ajatus.development.subview[view] != 'undefined')
105             {
106                 return $.ajatus.development.subview[view].render();
107             }
108             
109             $.ajatus.application_content_area.html('');
110             
111             var body_class = 'development';
112             var view_hash = '#view.development';
113             var view_title = $.ajatus.i10n.get('Development');
114             
115             $.ajatus.layout.title.update({
116                 view: view_title
117             });            
118             $.ajatus.layout.body.set_class(body_class);     
119             $.ajatus.views.on_change(view_hash, true);
121             $.ajatus.toolbar.init();
122             
123             if ($.ajatus.development.view.icongrid != null) {
124                 $.ajatus.development.view.icongrid.render();
125             }
126             
127             // if (view == 'frontpage') {
128             //     $.ajatus.views.system.archive.get_items();
129             // } else {
130             //     $.ajatus.views.system.archive.get_view_items(view);
131             // }
132         }
133     };
134     
135     $.ajatus.development.subview = {
136         base_class: 'development',
137         available: [
138             'generator', 'templating'
139         ]
140     };
142     $.ajatus.development.subview.generator = {
143         title: 'Object generator',
144         view_hash: '#view.development.generator',
145         icon: 'generator.png',
146         
147         render: function() {
148             $.ajatus.application_content_area.html('');
150             var body_class = $.ajatus.development.subview.base_class + ' generator';
151             var view_title = $.ajatus.i10n.get('Development') + ' - ' + $.ajatus.i10n.get($.ajatus.development.subview.generator.title);
152             
153             $.ajatus.layout.title.update({
154                 view: view_title
155             });            
156             $.ajatus.layout.body.set_class(body_class);
157             $.ajatus.views.on_change($.ajatus.development.subview.generator.view_hash, true);
159             $.ajatus.toolbar.init();
160             
161             
162         }
163     };
164     
165     $.ajatus.development.subview.templating = {
166         title: 'Templating',
167         view_hash: '#view.development.templating',
168         //icon: 'templating.png',
169         
170         render: function() {
171             $.ajatus.application_content_area.html('');
173             var body_class = $.ajatus.development.subview.base_class + ' templating';
174             var view_title = $.ajatus.i10n.get('Development') + ' - ' + $.ajatus.i10n.get($.ajatus.development.subview.templating.title);
175             
176             $.ajatus.layout.title.update({
177                 view: view_title
178             });            
179             $.ajatus.layout.body.set_class(body_class);
180             $.ajatus.views.on_change($.ajatus.development.subview.templating.view_hash, true);
182             $.ajatus.toolbar.init();
184             var type = $.ajatus.preferences.client.content_types['note'];
185             
186             var renderer = new $.ajatus.renderer.list_tpl(
187                 $.ajatus.application_content_area,
188                 type,
189                 {
190                     id: type.name + '_list_holder',
191                     pool: {
192                         enabled: true,
193                         settings: {
194                             type: 'scroll',
195                             use_db: true,
196                             db: {
197                                 'static': type.name+'/list'
198                             }
199                         }
200                     }
201                 }
202             );
203             
204             var doc_count = $.jqCouch.connection('view').get($.ajatus.preferences.client.content_database, type.name+'/list', {
205                 count: 0
206             }).total_rows;
207             
208             var on_success = function(data) {
209                 $.each(data.rows, function(i,doc){
210                     var doc = new $.ajatus.document(doc);
211                     renderer.add_item(doc);
212                 });
213                 
214                 renderer.add_total_count(doc_count);
215                 
216                 return data;
217             };
218             
219             $.jqCouch.connection('view', on_success).get($.ajatus.preferences.client.content_database, type.name+'/list', {
220                 count: 40,
221                 descending: true
222             });
223             
224             renderer.render();
225         }
226     };
227     
228 })(jQuery);