Merge branch 'master' of git+ssh://w_i@repo.or.cz/srv/git/ajatus
[ajatus.git] / js / views / system.js
blob526c4c7397937ee6ac1aa387bd1a08a0c07ef99a
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     $.ajatus.views = $.ajatus.views || {};
18     
19     $.ajatus.views.system = {
20         available: [
21             'frontpage', 'edit', 'create', 'item', 'tags', 'trash'
22         ]
23     };
24     $.ajatus.views.system.frontpage = {
25         title: 'Frontpage',
26         options: {
27             group_item_count: 3,
28             max_items_before_pool: 3
29         },
30         in_tabs: true,
31         history_support: true,
32         
33         pool_settings: {
34             enabled: false,
35             settings: {
36                 tick_limit: 4
37             }
38         },
39                 
40         tab: {
41             on_click: function(e)
42             {
43                 $.ajatus.tabs.on_click(e);
44                 $.ajatus.views.system.frontpage.render();
45             }
46         },
47     
48         render: function()
49         {
50             $.ajatus.application_content_area.html('');
51             $.ajatus.layout.body.set_class('frontpage');
52             $.ajatus.views.on_change("#view.frontpage");
53             
54             $.each($.ajatus.preferences.client.content_types, function(key,type){
55                 if (   !type.views['list']
56                     || type.on_frontpage == false) {
57                     return false;
58                 }
59             
60                 var on_success = function(data) {
61                     if (data.total_rows == 0) {
62                         return;
63                     }
64                     
65                     var pool_settings = $.ajatus.views.system.frontpage.pool_settings;
66                     if (data.total_rows >= $.ajatus.views.system.frontpage.options.max_items_before_pool) {
67                         pool_settings.enabled = true;
68                     }                    
69                     
70                     var renderer = new $.ajatus.renderer.list(
71                         $.ajatus.application_content_area,
72                         type,
73                         {
74                             id: type.name + '_list_holder',
75                             append: true,
76                             pool: pool_settings
77                         }
78                     );
80                     $.each(data.rows, function(i,doc){
81                         var doc = new $.ajatus.document(doc);
82                         renderer.render_item(doc, i);
83                     });
84                     
85                     return data;
86                 };
88                 if (   $.ajatus.tags.active != ''
89                     && typeof type.views['list_at'] != 'undefined')
90                 {
91                     $.jqCouch.connection('view', on_success).temp($.ajatus.preferences.client.content_database, type.views['list_at'], {
92                         count: $.ajatus.views.system.frontpage.options.group_item_count,
93                         descending: true
94                     });
95                 } else {
96                     $.jqCouch.connection('view', on_success).get($.ajatus.preferences.client.content_database, type.name+'/list', {
97                         count: $.ajatus.views.system.frontpage.options.group_item_count,
98                         descending: true
99                     });                        
100                 }
101             });
102         }
103     };
104     $.ajatus.views.system.tags = {
105         title: 'Tags',
106         options: {            
107         },
108         in_tabs: true,
109         application_tab: true,
110         history_support: true,
111         icon: 'tag.png',
112                 
113         tab: {
114             on_click: function(e) {
115                 $.ajatus.tabs.on_click(e);
116                 $.ajatus.views.system.tags.render();
117             }
118         },
119         
120         render: function() {
121             $.ajatus.application_content_area.html('');
122             $.ajatus.layout.body.set_class('tags');
123             $.ajatus.views.on_change("#view.tags");
125             $.ajatus.toolbar.init();
126             $.ajatus.toolbar.show();
127             
128             $.ajatus.views.system.tags.get_items();
129         },
131         render_results: function(tags, items) {
132             var type = $.ajatus.preferences.client.content_types['tag'];
133             
134             var renderer = new $.ajatus.renderer.list(
135                 $.ajatus.application_content_area,
136                 type,
137                 {
138                     id: 'tags_list_holder',
139                     headers: [
140                         'title', 'context', 'value', 'created', 'creator', 'used'
141                     ],
142                     pool: {
143                         type: 'scroll'
144                     }
145                 }
146             );
147             
148             var x = 0;
149             $.each(tags, function(i,doc){
150                 var doc = new $.ajatus.document(doc);
151                 doc.value['used'] = {
152                     val: (typeof items[doc._id] != 'undefined' ? items[doc._id].length : 0)
153                 };
154                 renderer.render_item(doc, x);
155                 x+=1;
156             });
157             
158             renderer.enable_sorting();
159             
160             $.ajatus.views.system.tags.get_duplicates(items);
161         },
162         
163         render_duplicates: function(rows, items) {
164             var type = $.ajatus.preferences.client.content_types['tag'];
165             
166             var renderer = new $.ajatus.renderer.list(
167                 $.ajatus.application_content_area,
168                 type,
169                 {
170                     id: 'tag_dups_list_holder',
171                     title: $.ajatus.i10n.get("Duplicate"),
172                     headers: [
173                         'title', 'context', 'value', 'created', 'creator', 'used'
174                     ],
175                     pool: {
176                         type: 'scroll'
177                     },
178                     append: true,
179                     item_id_suffix: '_duplicate',
180                     show_actions: false,
181                     className: 'list_holder duplicates_list'
182                 }
183             );
184             
185             var duplicates = [];
186             var duplicate_ids = [];
187             
188             var tags = {};
189             
190             var hashes = [];
191             var ids = [];
192             
193             $.each (rows, function(i,doc){
194                 var doc = new $.ajatus.document(doc);
195                 // console.log(doc._id);
196                 // console.log(doc.key);
197                 // console.log(doc.value.context.val);
198                 // console.log(doc.value.value.val);
199                 
200                 // if (typeof tags[doc.key] == 'undefined') {
201                 //     tags[doc.key] = {
202                 //         contexts: [doc.value.context.val],
203                 //         values: [doc.value.value.val],
204                 //         docs: [doc],
205                 //     };
206                 // } else {
207                 //     tags[doc.key].contexts.push(doc.value.context.val);
208                 //     tags[doc.key].values.push(doc.value.value.val);
209                 //     tags[doc.key].docs.push(doc);
210                 // }
211                 
212                  var tag_hash = $.ajatus.utils.md5.encode(doc.value.context.val + ':' + doc.key + '=' + doc.value.value.val);
213                  hashes.push(tag_hash);
214                  ids.push(doc._id);
216                  tags[doc._id] = doc;
217             });
218             
219             var match_count = 0;
220             var chashes = hashes;
221             var duplicates_with = {};
222             
223             for (var i=0; i<hashes.length;i++) {
224                 var key = hashes[i];
225                 chashes[i] = '';
226                 var matched = $.inArray(key, chashes);
227                 if (matched != -1) {
228                     if (typeof duplicates_with[ids[i]] == 'undefined') {
229                         duplicates_with[ids[i]] = [ids[matched]];
230                     } else {
231                         duplicates_with[ids[i]].push(ids[matched]);
232                     }
233                     duplicates_with[ids[i]]
234                     duplicate_ids.push(ids[i]);
235                     match_count += 1;
236                 }
237             }
238             
239             // console.log("match_count: "+match_count);
240             // console.log("duplicate_ids: ");
241             // console.log(duplicate_ids);
242             // console.log("duplicates_with: ");
243             // console.log(duplicates_with);
245             var x = 0;
246             $.each(tags, function(i,d){
247                 if ($.inArray(i, duplicate_ids) != -1) {                    
248                     d.value['used'] = {
249                         val: (typeof items[d._id] != 'undefined' ? items[d._id].length : 0)
250                     };
251                     renderer.render_item(d, x);
252                     x+=1;
253                 }
254             });
255             var merger = new $.ajatus.tags.merger();
256             
257             $.each(duplicate_ids, function(i,dub){
258                 var row = $('#object_'+dub+'_duplicate');
259                 row.bind('click', function(){
260                     merger.toggle_selection($(this), dub, duplicates_with[dub]);
261                 });
262             });
263             
264             renderer.enable_sorting();
265         },
266         
267         get_items: function(on_success) {
268             var conn_on_success = function(data) {                
269                 if (data.total_rows == 0) {
270                     var key = $.ajatus.i10n.plural($.ajatus.i10n.get('tag'));
271                     var msg = $.ajatus.elements.messages.static($.ajatus.i10n.get('Empty results'), $.ajatus.i10n.get('No %s found', [key]));
272                     return;
273                 }
274                 
275                 var tags = {};
276                 var items = {};
277                 
278                 $.each(data.rows, function(i,n){
279                     if (n.key[1] == 0) {
280                         tags[n.key[0]] = n;
281                     } else {
282                         if (typeof items[n.key[0]] == 'undefined') {
283                             items[n.key[0]] = [];
284                         }
285                         items[n.key[0]].push(n);
286                     }
287                 });
289                 if (typeof on_success == 'undefined') {
290                     on_success = $.ajatus.views.system.tags.render_results;
291                 }
292                 
293                 on_success(tags, items);
294                 
295                 return data;
296             };
298             $.jqCouch.connection('view', conn_on_success).get($.ajatus.preferences.client.content_database, 'tag/list_with_docs', {
299                 // startkey: ["ED862081B2FBF46FB0CDBBE848ED6856", 0],
300                 // endkey: ["ED862081B2FBF46FB0CDBBE848ED6856", 1]
301             });
302         },
303         
304         get_duplicates: function(items) {
305             var conn_on_success = function(data) {                
306                 if (data.total_rows == 0) {
307                     var key = $.ajatus.i10n.plural($.ajatus.i10n.get('dublicate'));
308                     var msg = $.ajatus.elements.messages.static($.ajatus.i10n.get('Empty results'), $.ajatus.i10n.get('No %s found', [key]));
309                     return;
310                 }
312                 if (typeof on_success == 'undefined') {
313                     on_success = $.ajatus.views.system.tags.render_duplicates;
314                 }
315                 
316                 on_success(data.rows, items);
317                 
318                 return data;
319             };
321             $.jqCouch.connection('view', conn_on_success).get($.ajatus.preferences.client.content_database, 'tag/list_by_title', {
322             });
323         }
325     };
326     $.ajatus.views.system.trash = {
327         title: 'Trash',
328         options: {
329             group_item_count: 10
330         },
331         in_tabs: true,
332         application_tab: true,
333         history_support: true,
334         icon: 'trash.png',
335         
336         tab: {
337             on_click: function(e)
338             {
339                 $.ajatus.tabs.on_click(e);
340                 $.ajatus.views.system.trash.render();
341             }
342         },
343         
344         get_items: function(on_success) {            
345             var trash_view = 'if (doc.value.metadata.deleted.val == true) {';
346             trash_view += 'map( doc.value.metadata.revised, {"_type": doc.value._type,';
347             trash_view += '"title": doc.value.title,';
348             
349             $.each($.ajatus.preferences.client.content_types, function(key,type){
350                 if (type['title_item']) {
351                     $.each(type['title_item'], function(i,part){
352                         if (type.schema[part]) {
353                             trash_view += '"'+part+'": doc.value.'+part+',';
354                         }
355                     });
356                 }
357             });
359             trash_view += '"revised": doc.value.metadata.revised,"by": doc.value.metadata.revisor,"tags": doc.value.tags})}';
360             
361             var conn_on_success = function(data) {
362                 if (data.total_rows == 0) {
363                     var key = $.ajatus.i10n.plural($.ajatus.i10n.get('deleted item'));
364                     var msg = $.ajatus.elements.messages.static($.ajatus.i10n.get('Empty results'), $.ajatus.i10n.get('No %s found', [key]));
365                     return;
366                 }
367                 
368                 if (typeof on_success == 'undefined') {
369                     on_success = $.ajatus.views.system.trash.render_results;
370                 }
371                 
372                 on_success(data.rows);
373                 return data;
374             };
375             
376             $.jqCouch.connection('view', conn_on_success).temp($.ajatus.preferences.client.content_database, "$.ajatus.views.generate('"+trash_view+"')", {
377                 count: $.ajatus.views.system.trash.options.group_item_count,
378                 descending: true
379             });
380         },
381         
382         render: function()
383         {
384             $.ajatus.application_content_area.html('');
385             $.ajatus.layout.body.set_class('trash');
386             $.ajatus.views.on_change("#view.trash");
388             $.ajatus.toolbar.init();
389             $.ajatus.toolbar.show();
390             
391             $.ajatus.views.system.trash.get_items();
392         },
393         
394         render_results: function(rows)
395         {
396             var result_count = {};
397             var show_empty_trash = false;
398             
399             $.each($.ajatus.preferences.client.content_types, function(key,type){
400                 if (!type.views['list']) {
401                     return false;
402                 }
403                 
404                 result_count[type.name] = 0;
405                 
406                 $.each(rows, function(i,doc){
407                     if (doc.value._type == type.name) {
408                         result_count[type.name] += 1;
409                     }
410                 });
411                 
412                 if (result_count[type.name] == 0) {
413                     return;
414                 }
415                 
416                 show_empty_trash = true;
417                 
418                 var renderer = new $.ajatus.renderer.list(
419                     $.ajatus.application_content_area,
420                     false,
421                     {
422                         id: type.name + '_list_holder',
423                         append: true,
424                         title: type.title,
425                         headers: [
426                             'title', 'revised', 'by'
427                         ],
428                         schema: $.extend({
429                             by: {
430                                 label: 'By'
431                             }
432                         }, type.schema)
433                     }
434                 );
436                 $.each(rows, function(i,doc){
437                     if (doc.value._type == type.name) {
438                         var doc = new $.ajatus.document(doc);
439                         
440                         renderer.set_actions(
441                             [
442                                 {
443                                     name: 'view',
444                                     title: $.ajatus.i10n.get('View'),
445                                     icon: 'view.png',
446                                     click_action: '$.ajatus.views.system.item.render(doc);'
447                                 },
448                                 {
449                                     name: 'undelete',
450                                     title: $.ajatus.i10n.get('Undelete'),
451                                     icon: 'undo.png',
452                                     click_action: '$.ajatus.document.actions.execute("undelete", doc);'
453                                 },
454                                 {
455                                     name: 'delete_final',
456                                     title: $.ajatus.i10n.get('Delete'),
457                                     icon: 'trash.png',
458                                     click_action: '$.ajatus.document.actions.execute("delete_final", doc);'
459                                 }
460                             ]
461                         );
462                         renderer.render_item(doc, i);
463                     }
464                 });
465             
466                 renderer.enable_sorting();
467             });
468             
469             if (show_empty_trash) {
470                 $.ajatus.toolbar.add_item($.ajatus.i10n.get('Empty trash'), 'trash.png', function(){
471                     $.ajatus.views.system.trash.empty();
472                 });
473             }
474         },
475         empty: function() {
476             var answer = confirm($.ajatus.i10n.get("Deleting all items in trash. Are you sure?"));
477             if (answer) {
478                 $.ajatus.views.system.trash.get_items($.ajatus.views.system.trash.execute_empty);                
479             }
480         },
481         execute_empty: function(rows) {            
482             $.each(rows, function(i,doc){
483                 doc = new $.ajatus.document(doc);
484                 $.ajatus.document.actions.execute("delete_final", doc);
485             });
486         }
487     };
488     $.ajatus.views.system.edit = {
489         title: 'Edit',
490         options: {
491         },
492         in_tabs: false,
493         dynamic_history: true
494     };
495     $.extend($.ajatus.views.system.edit, {
496         render: function(type, doc, use_given_doc)
497         {
498             if (typeof use_given_doc == 'undefined') {
499                 use_given_doc = false;
500             }
501             
502             var content_type = type; 
503             
504             if (! use_given_doc) {
505                 var doc = new $.ajatus.document.loader(doc._id, doc._rev);                
506             }
507             
508             if (! type) {
509                 content_type = $.ajatus.preferences.client.content_types[doc.value._type];
510             }
511                         
512             if (typeof(type) == 'string') {
513                 content_type = $.ajatus.preferences.client.content_types[type];
514             }
515             
516             $.ajatus.layout.body.set_class('edit '+content_type.name);
517             
518             var view_hash = '#edit.'+doc.value._type+'.'+doc._id+'.'+doc._rev;
519             $.ajatus.history.update(view_hash);
520             $.ajatus.views.on_change(view_hash);
521             
522             var latest_rev = $.ajatus.document.revisions.get(doc).active.rev;
523             
524             if (   content_type.custom_renderer
525                 && typeof(content_type.custom_renderer['edit']) == 'function')
526             {
527                 var renderer = content_type.custom_renderer.edit(doc, latest_rev);
528             } else {            
529                 var renderer = new $.ajatus.renderer.form(content_type, doc, false, latest_rev);
530                 $.ajatus.application_content_area.html(renderer.form);
531                 $.ajatus.forms.register.normal(renderer.form);
532             }
533         },
534         history_register: function() {
535             $.ajatus.history.add_dynamic_map(['edit'], 3, '$.ajatus.views.system.edit.history_render');
536         },
537         history_render: function() {
538             var type = arguments[0];
539             var id = arguments[1];
540             var rev = false;
542             if (   typeof arguments[2] != 'undefined'
543                 && arguments[2] != '')
544             {
545                 rev = arguments[2];
546             }
547             
548             var doc = new $.ajatus.document.loader(id, rev);
549             $.ajatus.views.system.edit.render(type, doc);
550         }
551     });
552     
553     $.ajatus.views.system.create = {
554         title: 'Create',
555         options: {
556         },
557         in_tabs: false,
558         dynamic_history: true
559     };
560     $.extend($.ajatus.views.system.create, {
561         render: function(type, doc)
562         {
563             var content_type = type; 
564             
565             if (typeof(type) == 'string') {
566                 content_type = $.ajatus.preferences.client.content_types[type];
567             }
568             
569             $.ajatus.layout.body.set_class('create '+content_type.name);
570             
571             var view_hash = '#create.'+content_type.name;
572             
573             $.ajatus.history.update(view_hash);
574             
575             $.ajatus.views.on_change(view_hash);
576             
577             if (   content_type.custom_renderer
578                 && typeof(content_type.custom_renderer['create']) == 'function')
579             {
580                 var renderer = content_type.custom_renderer.create();
581             } else {
582                 var renderer = new $.ajatus.renderer.form(content_type, doc, true);
583                 $.ajatus.application_content_area.html(renderer.form);
584                 $.ajatus.forms.register.normal(renderer.form);
585             }
586         },
587         history_register: function() {
588             $.ajatus.history.add_dynamic_map(['create'], 2, '$.ajatus.views.system.create.history_render');
589         },
590         history_render: function() {            
591             var type = arguments[0];
592                         
593             $.ajatus.views.system.create.render(type);
594         }
595     });
597     $.ajatus.views.system.item = {
598         title: 'View item',
599         options: {
600         },
601         in_tabs: false,
602         dynamic_history: true
603     };
604     $.extend($.ajatus.views.system.item, {
605         render: function(doc)
606         {            
607             if (typeof doc._rev != 'undefined') {
608                 var doc = new $.ajatus.document.loader(doc._id, doc._rev);
609             } else {
610                 var doc = new $.ajatus.document.loader(doc._id);
611             }
612             
613             var content_type = $.ajatus.preferences.client.content_types[doc.value._type];
614             
615             $.ajatus.layout.body.set_class('view '+doc.value._type);
616             
617             var view_hash = '#view.'+doc.value._type+'.'+doc._id+'.'+doc._rev;
618             $.ajatus.history.update(view_hash);
619             $.ajatus.views.on_change(view_hash);
620             
621             $.ajatus.toolbar.add_item($.ajatus.i10n.get('Edit'), {
622                 icon: 'edit.png',
623                 action: function(){
624                     $.ajatus.views.system.edit.render(content_type, doc);
625                 },
626                 access_key: 'Ctrl+e'
627             });
629             if (doc.value.metadata.archived.val) {
630                 var unarch_id = $.ajatus.toolbar.add_item($.ajatus.i10n.get('Restore'), 'undo.png', function(item, doc){
631                     doc._rev = null;
632                     $.ajatus.document.actions.execute("unarchive", doc);
633                     
634                     $.ajatus.toolbar.hide_item(item.id);
635                     $.ajatus.toolbar.add_item($.ajatus.i10n.get('Archive'), 'archive.png', function(item, doc, unarch_item_id){
636                         doc._rev = null;
637                         $.ajatus.document.actions.execute("archive", doc);
638                         
639                         $.ajatus.toolbar.hide_item(item.id);
640                         $.ajatus.toolbar.show_item(unarch_item_id);
641                     }, [doc, unarch_id], unarch_id);
642                 }, [doc]);
643             } else {
644                 var arch_id = $.ajatus.toolbar.add_item($.ajatus.i10n.get('Archive'), 'archive.png', function(item, doc){
645                     doc._rev = null;
646                     $.ajatus.document.actions.execute("archive", doc);
647                     
648                     $.ajatus.toolbar.hide_item(item.id);
649                     $.ajatus.toolbar.add_item($.ajatus.i10n.get('Restore'), 'undo.png', function(item, doc, arch_item_id){
650                         doc._rev = null;
651                         $.ajatus.document.actions.execute("unarchive", doc);
652                         
653                         $.ajatus.toolbar.hide_item(item.id);
654                         $.ajatus.toolbar.show_item(arch_item_id);
655                     }, [doc, arch_id], arch_id);
656                 }, [doc]);
657             }
658             
659             if (doc.value.metadata.deleted.val) {
660                 var undel_id = $.ajatus.toolbar.add_item($.ajatus.i10n.get('Undelete'), 'undo.png', function(item, doc){
661                     doc._rev = null;
662                     $.ajatus.document.actions.execute("undelete", doc);
663                     
664                     var d = doc;
665                     $.ajatus.toolbar.hide_item(item.id);
666                     $.ajatus.toolbar.add_item($.ajatus.i10n.get('Delete'), 'trash.png', function(item, doc, undel_item_id){
667                         doc._rev = null;
668                         $.ajatus.document.actions.execute("delete", doc);
669                         
670                         $.ajatus.toolbar.hide_item(item.id);
671                         $.ajatus.toolbar.show_item(undel_item_id);
672                     }, [d, undel_id], undel_id);
673                 }, [doc]);                
674             } else {                
675                 var del_id = $.ajatus.toolbar.add_item($.ajatus.i10n.get('Delete'), 'trash.png', function(item, doc){
676                     doc._rev = null;
677                     $.ajatus.document.actions.execute("delete", doc);
679                     var d = doc;                    
680                     $.ajatus.toolbar.hide_item(item.id);
681                     $.ajatus.toolbar.add_item($.ajatus.i10n.get('Undelete'), 'undo.png', function(item, doc, del_item_id){
682                         doc._rev = null;
683                         $.ajatus.document.actions.execute("undelete", doc);
684                         
685                         $.ajatus.toolbar.hide_item(item.id);
686                         $.ajatus.toolbar.show_item(del_item_id);
687                     }, [d, del_id], del_id);
688                 }, [doc]);
689             }
691             $.ajatus.toolbar.show();
692             
693             var metadata_sb = new $.ajatus.renderer.blocks.sub('metadata_for_'+doc._id);
694             metadata_sb.set_title($.ajatus.i10n.get('Metadata'));
695             $.ajatus.views.on_change_actions.add('$.ajatus.renderer.blocks.clear_sub("'+metadata_sb.id+'");');
696             
697             var md_renderer = new $.ajatus.renderer.metadata(doc, metadata_sb.element);            
699             if (typeof doc.value.tags != 'undefined') {
700                 var rel_docs = $.ajatus.tags.related(doc.value.tags.val, [doc._id]);
702                 var related_sb = new $.ajatus.renderer.blocks.sub('related_objects');
703                 related_sb.set_title($.ajatus.i10n.get('Related Objects'));
704                 $.ajatus.views.on_change_actions.add('$.ajatus.renderer.blocks.clear_sub("'+related_sb.id+'");');
706                 var tinylist = new $.ajatus.renderer.tinylist(related_sb.element);
707                 tinylist.render_items(rel_docs);
708             }
709             
710             if (   content_type.custom_renderer
711                 && typeof(content_type.custom_renderer['item']) == 'function')
712             {
713                 var renderer = content_type.custom_renderer.item();
714             } else {
715                 var renderer = new $.ajatus.renderer.item(doc);
716             }
717         },
718         history_register: function() {
719             $.ajatus.history.add_dynamic_map(['view'], 3, '$.ajatus.views.system.item.history_render');
720         },
721         history_render: function() {
722             var type = arguments[0];
723             var id = arguments[1];
724             var rev = false;
726             if (   typeof arguments[2] != 'undefined'
727                 && arguments[2] != '')
728             {
729                 rev = arguments[2];
730             }
732             if (rev) {
733                 var data = {
734                     _id: id,
735                     _rev: rev,
736                     value: {
737                         _type: type
738                     }
739                 };                
740             } else {
741                 var data = {
742                     _id: id,
743                     value: {
744                         _type: type
745                     }
746                 };
747             }
749             if (typeof data['toSource'] != 'undefined') {
750                 data = data.toSource();
751             }
753             setTimeout("$.ajatus.views.system.item.render("+data+");", 200);
754         }
755     });
757 })(jQuery);