4 * Ajatus - Distributed CRM
5 * @requires jQuery v1.2.1
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
17 $.ajatus
.document = function(doc
, check_metadata
, check_schema
) {
18 if (typeof check_metadata
== 'undefined') {
19 var check_metadata
= true;
21 if (typeof check_schema
== 'undefined') {
22 var check_schema
= false;
28 $.each(doc
, function(i
,n
){
29 if ( (i
== '_id' && n
!= '')
30 || i
== 'id' && n
!= '') {
31 self
.ready_doc
['_id'] = n
;
32 } else if (i
== '_rev' && n
!= '') {
33 self
.ready_doc
[i
] = n
;
34 } else if (i
== 'key' && n
!= '') {
35 self
.ready_doc
[i
] = n
;
36 } else if (i
== 'value' && n
!= '') {
37 self
.ready_doc
[i
] = n
;
41 if (typeof this.ready_doc
['value'] == 'undefined') {
42 $.ajatus
.debug("Error: Document didn't have value field defined!", "ajatus.document");
43 return this.ready_doc
;
47 if (! this.ready_doc
.value
.metadata
) {
50 this.check_metadata();
54 if (! $.ajatus
.preferences
.client
.content_types
[this.ready_doc
.value
._type
]) {
55 this.ready_doc
.value
._type
= 'note';
62 this.prepare_doc_title();
64 return this.ready_doc
;
66 $.extend($.ajatus
.document
.prototype, {
67 check_schema: function() {
69 var type
= $.ajatus
.preferences
.client
.content_types
[this.ready_doc
.value
._type
];
71 var new_schema_parts
= {};
72 $.each(type
.original_schema
, function(k
,si
){
73 // console.log("self.ready_doc.value.metadata["+k+"]:"+self.ready_doc.value.metadata[k])
74 if (typeof(self
.ready_doc
.value
[k
]) == 'undefined') {
76 if (typeof si
['def_val'] != 'undefined') {
77 def_val
= si
['def_val'];
79 new_schema_parts
[k
] = {
85 def_val
= self
.ready_doc
.value
[k
].val
|| '';
86 if (typeof si
['def_val'] != 'undefined') {
87 def_val
= si
['def_val'];
89 self
.ready_doc
.value
[k
] = $.extend({
92 }, self
.ready_doc
.value
[k
]);
97 // console.log("Found schema parts that need to be updated:");
98 // console.log(new_schema_parts);
99 self
._fix_doc_schema(new_schema_parts
);
102 _fix_doc_schema: function(new_parts
) {
105 doc
= new $.ajatus
.document
.loader(_self
.ready_doc
._id
, _self
.ready_doc
._rev
, false, false);
106 doc
.value
= $.extend(doc
.value
, new_parts
);
108 var db_path
= $.ajatus
.preferences
.client
.content_database
;
109 if (doc
.value
._type
== 'tag') {
110 db_path
= $.ajatus
.preferences
.client
.tags_database
;
113 $.jqCouch
.connection('doc').save(db_path
, doc
);
114 _self
.ready_doc
= new $.ajatus
.document(doc
);
116 add_metadata: function() {
118 this.ready_doc
.value
.metadata
= {};
119 $.each($.ajatus
.document
.metadata
, function(k
,m
){
120 self
.ready_doc
.value
.metadata
[k
] = {
126 check_metadata: function() {
127 // console.log("check metadata");
130 var new_md_parts
= {};
131 $.each($.ajatus
.document
.metadata
, function(k
,m
){
132 // console.log("self.ready_doc.value.metadata["+k+"]:"+self.ready_doc.value.metadata[k])
133 if (typeof(self
.ready_doc
.value
.metadata
[k
]) == 'undefined') {
135 if (typeof m
['def_val'] != 'undefined') {
136 def_val
= m
['def_val'];
144 def_val
= self
.ready_doc
.value
.metadata
[k
].val
|| '';
145 if (typeof m
['def_val'] != 'undefined') {
146 def_val
= m
['def_val'];
148 self
.ready_doc
.value
.metadata
[k
] = $.extend({
151 }, self
.ready_doc
.value
.metadata
[k
]);
156 self
._fix_metadata(new_md_parts
);
159 _fix_metadata: function(new_metadata
) {
162 // console.log("_fix_metadata for: "+_self.ready_doc._id);
163 // console.log(new_metadata);
165 doc
= new $.ajatus
.document
.loader(_self
.ready_doc
._id
, _self
.ready_doc
._rev
, false);
167 // console.log("Before:");
168 // console.log(doc.value.metadata);
170 doc
.value
.metadata
= $.extend({}, doc
.value
.metadata
, new_metadata
);
172 // console.log("After:");
173 // console.log(doc.value.metadata);
175 var db_path
= $.ajatus
.preferences
.client
.content_database
;
176 if (doc
.value
._type
== 'tag') {
177 db_path
= $.ajatus
.preferences
.client
.tags_database
;
180 $.jqCouch
.connection('doc').save(db_path
, doc
);
181 _self
.ready_doc
= new $.ajatus
.document(doc
);
183 prepare_doc_title: function() {
186 if ( $.ajatus
.preferences
.client
.content_types
[this.ready_doc
.value
._type
]['title_item']
187 && ( typeof(this.ready_doc
.value
['title']) == 'undefined'
188 || this.ready_doc
.value
['title'].val
!= '') ) {
189 $.ajatus
.preferences
.client
.content_types
[this.ready_doc
.value
._type
].schema
['title'] = {
199 $.each($.ajatus
.preferences
.client
.content_types
[this.ready_doc
.value
._type
]['title_item'], function(i
,part
){
200 if (self
.ready_doc
.value
[part
]) {
201 var widget
= new $.ajatus
.widget(self
.ready_doc
.value
[part
].widget
.name
, self
.ready_doc
.value
[part
].widget
.config
);
202 var val
= widget
.value_on_view(self
.ready_doc
.value
[part
].val
, 'plain');
203 if (typeof val
!= 'string') {
204 val
= self
.ready_doc
.value
[part
].val
;
208 title_val
+= $.ajatus
.i10n
.get(part
);
212 this.ready_doc
.value
['title'] = {
214 widget
: $.ajatus
.preferences
.client
.content_types
[this.ready_doc
.value
._type
].schema
['title'].widget
219 $.ajatus
.document
.loader = function(id
, rev
, check_metadata
) {
220 if (typeof check_metadata
== 'undefined') {
221 var check_metadata
= true;
226 if (typeof rev
!= 'undefined') {
230 original
= new $.ajatus
.document(
231 $.jqCouch
.connection('doc').get($.ajatus
.preferences
.client
.content_database
+ '/' + id
, args
),
238 $.ajatus
.document
.metadata
= {
290 $.ajatus
.document
.modify_metadata = function(doc
, metadata
) {
291 $.each(metadata
, function(k
,v
){
292 if ($.ajatus
.document
.metadata
[k
])
294 var wdgt
= new $.ajatus
.widget($.ajatus
.document
.metadata
[k
].widget
.name
, $.ajatus
.document
.metadata
[k
].widget
.config
);
295 doc
.value
.metadata
[k
] = {
296 val
: wdgt
.value_on_save(wdgt
.value_on_save(v
)),
297 widget
: $.ajatus
.document
.metadata
[k
].widget
304 $.ajatus
.document
.actions
= {
305 execute: function(action
, tmpdoc
) {
306 var doc
= new $.ajatus
.document
.loader(tmpdoc
._id
, tmpdoc
._rev
);
308 var act_info
= $.ajatus
.document
.actions
._get_action_info(action
);
310 var msg
= $.ajatus
.elements
.messages
.create(
311 $.ajatus
.i10n
.get('Unknown document action'),
312 $.ajatus
.i10n
.get('Unknown action %s requested for object %s!', [action
, doc
.value
.title
.val
])
317 if (act_info
.pool_action
)
319 var pa
= act_info
.pool_action
;
320 var pai
= $.ajatus
.document
.actions
._get_action_info(fa
);
326 var pool_id
= $.ajatus
.document
.history
.pool
.add(pool_action
);
330 if (act_info
.undoable
) {
331 $.ajatus
.document
.actions
._execute_temp(act_info
.action
, doc
);
333 $.ajatus
.document
.actions
._execute_final(act_info
.action
, doc
);
336 _execute_temp: function(action
, doc
) {
337 // console.log("_execute_temp: "+action);
340 var on_success = function(data
) {
345 var msg
= $.ajatus
.elements
.messages
.create(
346 $.ajatus
.i10n
.get('Object deleted'),
347 $.ajatus
.i10n
.get('Object %s moved to trash.', [doc
.value
.title
.val
]) + ' <a href="#undelete.'+doc
.value
._type
+'.'+doc
._id
+'" class="undo">' + $.ajatus
.i10n
.get('Undo') + '</a>'
349 msg
.bind_in_content('click', 'a.undo', function(e
){
350 $.ajatus
.document
.actions
.execute("undelete", tmpdoc
);
351 msg
.fade('out', true);
357 doc
= $.ajatus
.document
.modify_metadata(doc
, {
359 revised
: $.ajatus
.formatter
.date
.js_to_iso8601(new Date()),
360 revisor
: $.ajatus
.preferences
.local
.user
.email
363 $.jqCouch
.connection('doc', on_success
).save($.ajatus
.preferences
.client
.content_database
, doc
);
365 $('#object_'+doc
._id
, $.ajatus
.application_content_area
).hide().addClass('deleted');
368 var on_success = function(data
) {
373 var msg
= $.ajatus
.elements
.messages
.create(
374 $.ajatus
.i10n
.get('Object archived'),
375 $.ajatus
.i10n
.get('Object %s moved to archive.', [doc
.value
.title
.val
]) + ' <a href="#unarchive.'+doc
.value
._type
+'.'+doc
._id
+'" class="undo">' + $.ajatus
.i10n
.get('Undo') + '</a>'
377 msg
.bind_in_content('click', 'a.undo', function(e
){
378 $.ajatus
.document
.actions
.execute("unarchive", tmpdoc
);
379 msg
.fade('out', true);
385 doc
= $.ajatus
.document
.modify_metadata(doc
, {
386 revised
: $.ajatus
.formatter
.date
.js_to_iso8601(new Date()),
387 revisor
: $.ajatus
.preferences
.local
.user
.email
,
388 archived
: $.ajatus
.formatter
.date
.js_to_iso8601(new Date()),
389 archiver
: $.ajatus
.preferences
.local
.user
.email
392 $.jqCouch
.connection('doc', on_success
).save($.ajatus
.preferences
.client
.content_database
, doc
);
394 $('#object_'+doc
._id
, $.ajatus
.application_content_area
).hide().addClass('archived');
398 _execute_final: function(action
, doc
) {
401 var on_success = function(data
) {
402 var msg
= $.ajatus
.elements
.messages
.create(
403 $.ajatus
.i10n
.get('Object deleted'),
404 $.ajatus
.i10n
.get('Object %s removed from Ajatus.', [doc
.value
.title
.val
])
409 $.jqCouch
.connection('doc', on_success
).del($.ajatus
.preferences
.client
.content_database
, doc
);
410 $('#object_'+doc
._id
, $.ajatus
.application_content_area
).remove();
413 var on_success = function(data
) {
414 var msg
= $.ajatus
.elements
.messages
.create(
415 $.ajatus
.i10n
.get('Object restored'),
416 $.ajatus
.i10n
.get('Object %s restored succesfully.', [doc
.value
.title
.val
])
421 doc
= $.ajatus
.document
.modify_metadata(doc
, {
423 revised
: $.ajatus
.formatter
.date
.js_to_iso8601(new Date()),
424 revisor
: $.ajatus
.preferences
.local
.user
.email
426 $.jqCouch
.connection('doc', on_success
).save($.ajatus
.preferences
.client
.content_database
, doc
);
428 $('#object_'+doc
._id
, $.ajatus
.application_content_area
).not('.deleted').remove();
429 $('#object_'+doc
._id
, $.ajatus
.application_content_area
).filter('.deleted').show().removeClass('deleted');
432 var on_success = function(data
) {
433 var msg
= $.ajatus
.elements
.messages
.create(
434 $.ajatus
.i10n
.get('Object restored'),
435 $.ajatus
.i10n
.get('Object %s restored succesfully.', [doc
.value
.title
.val
])
440 doc
= $.ajatus
.document
.modify_metadata(doc
, {
441 revised
: $.ajatus
.formatter
.date
.js_to_iso8601(new Date()),
442 revisor
: $.ajatus
.preferences
.local
.user
.email
,
446 $.jqCouch
.connection('doc', on_success
).save($.ajatus
.preferences
.client
.content_database
, doc
);
448 $('#object_'+doc
._id
, $.ajatus
.application_content_area
).filter('.archived').show().removeClass('archived');
452 empty_pool: function () {
453 var items
= $.ajatus
.document
.history
.pool
.get_all();
454 if (items
.length
> 0) {
455 var msg
= $.ajatus
.elements
.messages
.create(
456 $.ajatus
.i10n
.get('Emptying action pool'),
457 $.ajatus
.i10n
.get('Running %d pooled actions.', [items
.length
])
460 $.each(items
, function(i
,item
){
461 $.ajatus
.document
.history
.pool
.remove(i
);
462 $.ajatus
.document
.actions
.execute(item
.action
, item
.doc
);
465 _get_action_info: function(action
) {
470 label
: $.ajatus
.i10n
.get('Delete'),
472 undo_label
: $.ajatus
.i10n
.get('Undelete'),
479 label
: $.ajatus
.i10n
.get('Delete'),
487 label
: $.ajatus
.i10n
.get('Undelete'),
495 label
: $.ajatus
.i10n
.get('Archive'),
497 undo_label
: $.ajatus
.i10n
.get('Restore'),
504 label
: $.ajatus
.i10n
.get('Restore'),
515 $.ajatus
.document
.history
= {};
516 $.ajatus
.document
.history
.pool
= {
519 add: function(action
) {
520 var new_length
= $.ajatus
.document
.history
.pool
.items
.push(action
);
521 var pool_id
= new_length
-1;
524 remove: function(item_id
) {
525 $.ajatus
.document
.history
.pool
.items
= $.grep($.ajatus
.document
.history
.pool
.items
, function(n
,i
){
529 get_item: function(item_id
) {
530 if (items
[item_id
]) {
531 return items
[item_id
];
536 get_all: function() {
537 return $.ajatus
.document
.history
.pool
.items
;
541 $.ajatus
.document
.additionals
= {
550 $.extend($.ajatus
.document
.additionals
, {
551 create: function(content_type
, row_holder
, opts
) {
552 $.ajatus
.document
.additionals
._reset();
554 var id
= $.ajatus
.document
.additionals
._generate_id();
556 var options
= $.ajatus
.document
.additionals
.defaults
;
562 var af_win
= $.ajatus
.document
.additionals
._create_structure(id
, options
);
563 $('.title', af_win
).html($.ajatus
.i10n
.get('Add field'));
565 var jqform
= $('.form', af_win
);
566 var contents
= $('.contents', af_win
);
568 var wdgts
= $.ajatus
.document
.additionals
._generate_widget_list();
570 $('<label for="widget"/>').html($.ajatus
.i10n
.get('Widget')).appendTo(contents
);
571 var wdgt_sel_holder
= $('<div id="widget_selection_holder"/>');
572 wdgt_sel_holder
.html(wdgts
).appendTo(contents
);
574 var wdgt_details
= $('<div id="widget_details_holder"/>');
575 wdgt_details
.appendTo(contents
);
577 var wdgts_on_change = function(e
){
578 var sel_w
= e
.currentTarget
.value
;
580 wdgt_sel_holder
.html($.ajatus
.i10n
.get(sel_w
));
581 wdgt_sel_holder
.addClass('selected');
582 wdgt_details
.html($.ajatus
.document
.additionals
._generate_widget_details(sel_w
));
584 var field
= $('<input type="hidden" />').attr({
588 field
.appendTo(jqform
);
592 wdgts
.bind('change', wdgts_on_change
);
594 wdgt_sel_holder
.bind('dblclick', function(e
){
595 wdgt_sel_holder
.removeClass('selected');
596 wdgt_sel_holder
.html(wdgts
);
597 wdgts
.bind('change', wdgts_on_change
);
600 $('.actions #submit_save', af_win
).bind('click', function(e
){
601 var result
= $.ajatus
.document
.additionals
.save_widget(jqform
.formToArray(false), jqform
);
604 $.ajatus
.document
.additionals
.close(id
);
610 if (options
.auto_show
) {
611 $.ajatus
.document
.additionals
.show(id
);
614 edit: function(content_type
, row_holder
, data
, opts
) {
615 $.ajatus
.document
.additionals
._reset();
617 var id
= $.ajatus
.document
.additionals
._generate_id();
618 console
.log("Edit win id: "+id
);
620 var options
= $.ajatus
.document
.additionals
.defaults
;
626 var af_win
= $.ajatus
.document
.additionals
._create_structure(id
, options
);
627 $('.title', af_win
).html($.ajatus
.i10n
.get('Edit field %s', [data
.name
]));
629 $('.actions #submit_save', af_win
).bind('click', function(e
){
630 console
.log("save additional field (on edit)");
631 $.ajatus
.document
.additionals
.close(id
);
634 if (options
.auto_show
) {
635 $.ajatus
.document
.additionals
.show(id
);
638 config: function(widget
, prev_vals
, on_save
) {
639 if (typeof prev_vals
== 'undefined') {
642 if (typeof on_save
== 'undefined') {
643 var on_save
= '$.ajatus.document.additionals.save_widget_settings';
646 var id
= $.ajatus
.document
.additionals
._generate_id();
648 var af_win
= $.ajatus
.document
.additionals
._create_structure(id
);
649 $('.title', af_win
).html($.ajatus
.i10n
.get('Configure widget %s', [$.ajatus
.i10n
.get(widget
.name
)]));
651 var jqform
= $('.form', af_win
);
652 var contents
= $('.contents', af_win
);
654 var wdgt_settings
= $('<div id="widget_settings_holder" />');
655 wdgt_settings
.appendTo(contents
);
656 wdgt_settings
.html($.ajatus
.document
.additionals
._generate_widget_settings(widget
, prev_vals
));
658 $('.actions #submit_save', af_win
).bind('click', function(e
){
659 var parent_win
= $.ajatus
.document
.additionals
._get_parent();
662 if (typeof on_save
== 'string') {
665 var result
= fn
.apply(fn
, [jqform
.formToArray(false), parent_win
, jqform
]);
668 $.ajatus
.document
.additionals
.close(id
);
672 $.ajatus
.document
.additionals
.show(id
);
675 $.ajatus
.document
.additionals
.active
= id
;
676 $.ajatus
.document
.additionals
.open
.push(id
);
677 $.ajatus
.document
.additionals
._position(id
);
681 close: function(id
) {
682 if (typeof id
== 'undefined') {
683 var id
= $.ajatus
.document
.additionals
.active
;
688 var active_idx
= null;
689 var still_open
= $.grep($.ajatus
.document
.additionals
.open
, function(n
,i
){
699 && $.ajatus
.document
.additionals
.open
.length
-1 >= (active_idx
-1))
701 $.ajatus
.document
.additionals
.active
= still_open
[active_idx
-1];
703 $.ajatus
.document
.additionals
.active
= null;
706 $.ajatus
.document
.additionals
.open
= still_open
;
708 save_widget_settings: function(form_data
, parent_win_id
, form
) {
709 var form_values
= {};
711 $.each(form_data
, function(i
,row
){
712 if (row
.name
.toString().match(/__(.*?)/)) {
715 if (row
.name
.substr(0,6) != "widget") {
718 var prev_val
= false;
720 var name_parts_count
= 0;
721 if (row
.name
.toString().match(/;/g
)) {
722 name_parts
= row
.name
.toString().split(";");
723 name_parts_count
= name_parts
.length
;
726 $.each(form_data
, function(x
,r
){
727 if (r
.name
== 'widget['+row
.name
+':name]') {
728 widget
['name'] = r
.value
;
729 } else if (r
.name
== 'widget['+row
.name
+':config]') {
730 widget
['config'] = $.ajatus
.converter
.parseJSON(r
.value
);
731 } else if (r
.name
== 'widget['+row
.name
+':prev_val]') {
732 prev_val
= $.ajatus
.converter
.parseJSON(r
.value
);
736 var wdgt
= new $.ajatus
.widget(widget
['name'], widget
['config']);
738 item
['val'] = wdgt
.value_on_save(row
.value
, prev_val
);
739 item
['widget'] = widget
;
741 if (name_parts_count
> 0) {
743 for (var i
=0; i
< name_parts_count
; i
++) {
744 var key
= "['"+name_parts
[i
]+"']";
746 if (prevs
.length
> 0) {
748 $.each(prevs
, function(pi
, pk
){
749 key_prefix
= "['" + pk
+ "']" + key_prefix
;
751 key
= key_prefix
+ key
;
754 if (typeof eval("form_values"+key
) == 'undefined') {
755 eval("form_values"+key
+"={};");
758 prevs
.push(name_parts
[i
]);
759 if (i
== name_parts_count
-1) {
760 if ($.browser
.mozilla
) {
761 if (typeof item
== 'object') {
762 eval("form_values"+key
+"="+item
.toSource()+";");
764 eval("form_values"+key
+"="+item
+";");
767 eval("form_values"+key
+"="+item
+";");
772 form_values
[row
.name
] = item
;
777 var config_holder
= $('#'+parent_win_id
+' .saved_settings');
778 config_holder
.html('');
780 $.each(form_values
, function(k
,item
){
781 var field
= $('<input type="hidden" />').attr({
783 value
: $.ajatus
.converter
.toJSON(item
.val
)
785 field
.appendTo(config_holder
);
790 save_widget: function(form_data
, form
) {
791 var form_values
= {};
792 var sel_widget
= 'text';
794 // console.log(form_values);
796 $.each(form_data
, function(i
,row
){
797 if (row
.name
.toString().match(/__(.*?)/)) {
800 if (row
.name
== '_widget') {
801 sel_widget
= String(row
.value
);
803 else if (row
.name
.substr(0,6) != "widget") {
806 var prev_val
= false;
808 var name_parts_count
= 0;
810 if (row
.name
.toString().match(/;/g
)) {
811 name_parts
= row
.name
.toString().split(";");
812 name_parts_count
= name_parts
.length
;
815 $.each(form_data
, function(x
,r
){
816 if (r
.name
== 'widget['+row
.name
+':name]') {
817 widget
['name'] = r
.value
;
818 } else if (r
.name
== 'widget['+row
.name
+':config]') {
819 widget
['config'] = $.ajatus
.converter
.parseJSON(r
.value
);
820 } else if (r
.name
== 'widget['+row
.name
+':prev_val]') {
821 prev_val
= $.ajatus
.converter
.parseJSON(r
.value
);
825 if (typeof widget
['name'] == 'undefined') {
829 var wdgt
= new $.ajatus
.widget(widget
['name'], widget
['config']);
831 item
['val'] = wdgt
.value_on_save(row
.value
, prev_val
);
832 item
['widget'] = widget
;
834 if (name_parts_count
> 0) {
835 console
.log("name_parts_count > 0");
837 for (var i
=0; i
< name_parts_count
; i
++) {
838 var key
= "['"+name_parts
[i
]+"']";
840 if (prevs
.length
> 0) {
842 $.each(prevs
, function(pi
, pk
){
843 key_prefix
= "['" + pk
+ "']" + key_prefix
;
845 key
= key_prefix
+ key
;
848 if (typeof eval("form_values"+key
) == 'undefined') {
849 eval("form_values"+key
+"={};");
852 prevs
.push(name_parts
[i
]);
853 if (i
== name_parts_count
-1) {
854 if ($.browser
.mozilla
) {
855 if (typeof item
== 'object') {
856 eval("form_values"+key
+"="+item
.toSource()+";");
858 eval("form_values"+key
+"="+item
+";");
861 eval("form_values"+key
+"="+item
+";");
866 form_values
[row
.name
] = item
;
871 // var additional_items = {};
874 if (typeof form_values
['config'] != 'undefined') {
875 $.each(form_values
['config'], function(i
,n
){
876 if (typeof n
== 'object') {
877 config
[i
] = $.ajatus
.converter
.parseJSON(n
.val
);
884 var item_name
= form_values
.name
.val
.toString().toLowerCase();
886 if (item_name
== '') {
890 var additional_item
= {
891 label
: form_values
.label
.val
,
896 def_val
: form_values
.def_val
.val
,
897 required
: form_values
.required
.val
899 // additional_items[item_name] = additional_item;
900 // console.log(additional_items);
901 console
.log(additional_item
);
903 var row_holder
= $('.form_structure ul:eq(0)', $.ajatus
.forms
.active
);
905 $.ajatus
.renderer
.form_helpers
._add_additional_row('create', row_holder
, item_name
, additional_item
);
909 generate_item_actions_tpl: function(name
, widget
, doc
) {
911 'img', { className
: 'additional_edit_btn', src
: 'images/icons/edit.png', title
: $.ajatus
.i10n
.get('Edit'), alt
: $.ajatus
.i10n
.get('Edit') }, '',
912 'img', { className
: 'additional_delete_btn', src
: 'images/icons/trash.png', title
: $.ajatus
.i10n
.get('Delete'), alt
: $.ajatus
.i10n
.get('Delete') }, '',
915 _get_parent: function() {
916 var prev_id
= $.ajatus
.document
.additionals
.open
[$.ajatus
.document
.additionals
.open
.length
-2];
920 _position: function(id
) {
921 var win
= $('#' + id
);
922 var top
= $.ajatus
.document
.additionals
.top_start
;
923 var left
= $.ajatus
.document
.additionals
.left_start
;
925 if ($.ajatus
.document
.additionals
.open
.length
> 1) {
926 var incr
= $.ajatus
.document
.additionals
.open
.length
* 2;
936 _create_structure: function(id
, options
) {
937 var af_win
= $('<div class="additionals_window" />').attr({
940 var title
= $('<h2 class="title"/>');
941 var form
= $('<form id="additionals_window_form" class="form" />');
942 var content_area
= $('<div class="contents"/>');
943 var actions
= $('<div class="actions" />').html('<input type="submit" id="submit_save" name="save" value="' + $.ajatus
.i10n
.get('Save') + '" /><input type="submit" id="submit_cancel" name="cancel" value="' + $.ajatus
.i10n
.get('Cancel') + '" />');
945 af_win
.appendTo($.ajatus
.application_dynamic_elements
);
946 title
.appendTo(af_win
);
947 form
.appendTo(af_win
);
948 content_area
.appendTo(form
);
949 actions
.appendTo(af_win
);
951 $('#submit_cancel', actions
).bind('click', function(e
){
952 $.ajatus
.document
.additionals
.close(id
);
958 _generate_widget_list: function() {
959 var select
= $('<select id="widget" name="widget" />');
961 $.each($.ajatus
.widgets
.loaded_widgets
, function(i
,w
){
962 var opt
= $('<option />').attr({
964 }).html($.ajatus
.i10n
.get(w
));
965 opt
.appendTo(select
);
968 var opt
= $('<option />').attr({
971 }).html($.ajatus
.i10n
.get('Select one') + ' ');
972 opt
.prependTo(select
);
976 _generate_widget_details: function(widget_name
, data
) {
977 var widget
= $.ajatus
.widget(widget_name
);
978 var details
= $('<p>' + $.ajatus
.i10n
.get("Widget %s doesn't support dynamic creation.", [$.ajatus
.i10n
.get(widget_name
)]) + '</p>');
979 if (typeof(widget
['create_widget_details']) == 'function') {
980 details
= widget
.create_widget_details(data
|| {});
985 _generate_widget_settings: function(widget_name
, data
) {
986 var widget
= $.ajatus
.widget(widget_name
);
987 var details
= $('<p>' + $.ajatus
.i10n
.get("Widget %s doesn't support dynamic settings.", [$.ajatus
.i10n
.get(widget_name
)]) + '</p>');
988 if (typeof(widget
['create_widget_settings']) == 'function') {
989 details
= widget
.create_widget_settings(data
|| {});
995 $.ajatus
.document
.additionals
.open
= [];
996 $.ajatus
.document
.additionals
.active
= null;
997 $.ajatus
.application_dynamic_elements
.html('');
999 _generate_id: function()
1001 return "additionals_window_" + $.ajatus
.utils
.generate_id();