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;
25 // console.log("Check schema: "+check_schema);
26 // console.log("Check metadata: "+check_metadata);
31 $.each(doc, function(i,n){
32 if ( (i == '_id' && n != '')
33 || i == 'id' && n != '') {
34 self.ready_doc['_id'] = n;
35 } else if (i == '_rev' && n != '') {
36 self.ready_doc[i] = n;
37 } else if (i == 'key' && n != '') {
38 self.ready_doc[i] = n;
39 } else if (i == 'value' && n != '') {
40 self.ready_doc[i] = n;
44 if (typeof this.ready_doc['value'] == 'undefined') {
45 $.ajatus.debug("Error: Document didn't have value field defined!", "ajatus.document");
46 return this.ready_doc;
50 if (! this.ready_doc.value.metadata) {
53 this.check_metadata();
57 if (! $.ajatus.preferences.client.content_types[this.ready_doc.value._type]) {
58 this.ready_doc.value._type = 'note';
65 this.prepare_doc_title();
67 return this.ready_doc;
69 $.extend($.ajatus.document.prototype, {
70 check_schema: function() {
72 var type = $.ajatus.preferences.client.content_types[this.ready_doc.value._type];
74 var new_schema_parts = {};
76 $.each(type.original_schema, function(k,si){
77 // console.log("self.ready_doc.value.metadata["+k+"]:"+self.ready_doc.value.metadata[k])
78 if (typeof(self.ready_doc.value[k]) == 'undefined') {
80 if (typeof si['def_val'] != 'undefined') {
81 def_val = si['def_val'];
83 new_schema_parts[k] = {
89 def_val = self.ready_doc.value[k].val || '';
90 if (typeof si['def_val'] != 'undefined') {
91 def_val = si['def_val'];
93 self.ready_doc.value[k] = $.extend({
96 }, self.ready_doc.value[k]);
101 // console.log("Found schema parts that need to be updated:");
102 // console.log(new_schema_parts);
103 self._fix_doc_schema(new_schema_parts);
106 _fix_doc_schema: function(new_parts) {
107 // console.log("FIX SCHEMA:");
108 // console.log(new_parts);
111 doc = _self.ready_doc;//new $.ajatus.document.loader(_self.ready_doc._id, _self.ready_doc._rev, false, false);
112 doc.value = $.extend(doc.value, new_parts);
114 var db_path = $.ajatus.preferences.client.content_database;
116 $.jqCouch.connection('doc').save(db_path, doc);
117 _self.ready_doc = doc;//new $.ajatus.document(doc);
119 add_metadata: function() {
121 this.ready_doc.value.metadata = {};
122 $.each($.ajatus.document.metadata, function(k,m){
123 self.ready_doc.value.metadata[k] = {
129 check_metadata: function() {
130 // console.log("check metadata");
133 var new_md_parts = {};
134 $.each($.ajatus.document.metadata, function(k,m){
135 // console.log("self.ready_doc.value.metadata["+k+"]:"+self.ready_doc.value.metadata[k])
136 if (typeof(self.ready_doc.value.metadata[k]) == 'undefined') {
138 if (typeof m['def_val'] != 'undefined') {
139 def_val = m['def_val'];
147 def_val = self.ready_doc.value.metadata[k].val || '';
148 if (typeof m['def_val'] != 'undefined') {
149 def_val = m['def_val'];
151 self.ready_doc.value.metadata[k] = $.extend({
154 }, self.ready_doc.value.metadata[k]);
159 self._fix_metadata(new_md_parts);
162 _fix_metadata: function(new_metadata) {
165 // console.log("_fix_metadata for: "+_self.ready_doc._id);
166 // console.log(new_metadata);
168 doc = new $.ajatus.document.loader(_self.ready_doc._id, _self.ready_doc._rev, false);
170 // console.log("Before:");
171 // console.log(doc.value.metadata);
173 doc.value.metadata = $.extend({}, doc.value.metadata, new_metadata);
175 // console.log("After:");
176 // console.log(doc.value.metadata);
178 var db_path = $.ajatus.preferences.client.content_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 != '') )
190 $.ajatus.preferences.client.content_types[this.ready_doc.value._type].schema['title'] = {
200 $.each($.ajatus.preferences.client.content_types[this.ready_doc.value._type]['title_item'], function(i,part){
201 if (self.ready_doc.value[part]) {
202 var widget = new $.ajatus.widget(self.ready_doc.value[part].widget.name, self.ready_doc.value[part].widget.config);
203 var val = widget.value_on_view(self.ready_doc.value[part].val, 'plain');
204 if (typeof val != 'string') {
205 val = self.ready_doc.value[part].val;
209 title_val += $.ajatus.i10n.get(part);
213 this.ready_doc.value['title'] = {
215 widget: $.ajatus.preferences.client.content_types[this.ready_doc.value._type].schema['title'].widget
220 $.ajatus.document.loader = function(id, rev, check_metadata) {
221 if (typeof check_metadata == 'undefined') {
222 var check_metadata = true;
226 if ( typeof rev != 'undefined'
232 return new $.ajatus.document(
233 $.jqCouch.connection('doc').get($.ajatus.preferences.client.content_database + '/' + id, args),
238 $.ajatus.document.revisions = {
240 // console.log("get_revisions for "+doc._id);
241 if (typeof doc._revs_info == 'undefined') {
242 doc = $.jqCouch.connection('doc').get($.ajatus.preferences.client.content_database + '/' + doc._id, {
248 var available_revs = [];
249 var active_rev_status = false;
250 $.each(doc._revs_info, function(i,n){
251 if (n.rev == doc._rev) {
252 active_rev_status = n.status;
254 if (n.status == 'disk') {
255 available_revs.push(n);
261 revs_data['active'] = {
263 status: active_rev_status
265 revs_data['available'] = available_revs;
266 revs_data['all'] = doc._revs_info;
268 // console.log("Revs data:");
269 // console.log(revs_data);
273 navigate_to: function(pos, current, rev_data) {
274 // console.log("Navigate_to ("+pos+"), current rev: "+current);
278 var revisions = rev_data.all;
280 var put_behind = true;
282 $.each(revisions, function(i,n){
284 if (n.rev == current) {
295 var curr_key = rev_idxs[current];
297 // console.log("Behind:");
298 // console.log(behind);
299 // console.log("Ahead:");
300 // console.log(ahead);
302 var return_rev = null;
306 if (typeof ahead[(ahead.length-1)] != 'undefined') {
307 return_rev = ahead[(ahead.length-1)];
308 curr_key = rev_idxs[return_rev];
312 if (typeof behind[0] != 'undefined') {
313 return_rev = behind[0];
314 curr_key = rev_idxs[return_rev];
316 if (rev_data.active.rev == current) {
317 curr_key = rev_idxs[current];
322 if (typeof behind[(behind.length-1)] != 'undefined') {
323 return_rev = behind[(behind.length-1)];
324 curr_key = rev_idxs[return_rev];
325 } else if (typeof ahead[0] != 'undefined') {
326 return_rev = ahead[0];
327 curr_key = rev_idxs[return_rev];
330 if (rev_data.active.rev == current) {
331 curr_key = rev_idxs[current];
336 if (typeof ahead[0] != 'undefined') {
337 return_rev = ahead[0];
338 curr_key = rev_idxs[return_rev];
343 // console.log("Total revs: "+revisions.length);
344 // console.log("curr_key: "+curr_key);
345 // console.log("Current: "+(revisions.length - (curr_key)));
347 // console.log("Return rev: "+return_rev);
350 total: revisions.length,
351 current: (revisions.length - curr_key),
356 $.ajatus.document.metadata = {
406 $.ajatus.document.modify_metadata = function(doc, metadata) {
407 $.each(metadata, function(k,v){
408 if ($.ajatus.document.metadata[k])
410 var wdgt = new $.ajatus.widget($.ajatus.document.metadata[k].widget.name, $.ajatus.document.metadata[k].widget.config);
411 doc.value.metadata[k] = {
412 val: wdgt.value_on_save(wdgt.value_on_save(v)),
413 widget: $.ajatus.document.metadata[k].widget
420 $.ajatus.document.actions = {
421 execute: function(action, tmpdoc) {
422 if ( typeof tmpdoc._rev != 'undefined'
423 && tmpdoc._rev != null)
425 var doc = new $.ajatus.document.loader(tmpdoc._id, tmpdoc._rev);
427 var doc = new $.ajatus.document.loader(tmpdoc._id);
430 var act_info = $.ajatus.document.actions._get_action_info(action);
432 var msg = $.ajatus.elements.messages.create(
433 $.ajatus.i10n.get('Unknown document action'),
434 $.ajatus.i10n.get('Unknown action %s requested for object %s!', [action, doc.value.title.val])
439 if (act_info.pool_action)
441 var pa = act_info.pool_action;
442 var pai = $.ajatus.document.actions._get_action_info(fa);
448 var pool_id = $.ajatus.document.history.pool.add(pool_action);
452 if (act_info.undoable) {
453 $.ajatus.document.actions._execute_temp(act_info.action, doc);
455 $.ajatus.document.actions._execute_final(act_info.action, doc);
458 _execute_temp: function(action, doc) {
459 // console.log("_execute_temp: "+action);
462 var on_success = function(data) {
467 var msg = $.ajatus.elements.messages.create(
468 $.ajatus.i10n.get('Object deleted'),
469 $.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>'
471 msg.bind_in_content('click', 'a.undo', function(e){
472 $.ajatus.document.actions.execute("undelete", tmpdoc);
473 msg.fade('out', true);
479 doc = $.ajatus.document.modify_metadata(doc, {
481 revised: $.ajatus.formatter.date.js_to_iso8601(new Date()),
482 revisor: $.ajatus.preferences.local.user.email
485 $.jqCouch.connection('doc', on_success).save($.ajatus.preferences.client.content_database, doc);
487 $('#object_'+doc._id, $.ajatus.application_content_area).hide().addClass('deleted');
490 var on_success = function(data) {
495 var msg = $.ajatus.elements.messages.create(
496 $.ajatus.i10n.get('Object archived'),
497 $.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>'
499 msg.bind_in_content('click', 'a.undo', function(e){
500 $.ajatus.document.actions.execute("unarchive", tmpdoc);
501 msg.fade('out', true);
507 doc = $.ajatus.document.modify_metadata(doc, {
508 revised: $.ajatus.formatter.date.js_to_iso8601(new Date()),
509 revisor: $.ajatus.preferences.local.user.email,
513 $.jqCouch.connection('doc', on_success).save($.ajatus.preferences.client.content_database, doc);
515 $('#object_'+doc._id, $.ajatus.application_content_area).hide().addClass('archived');
519 _execute_final: function(action, doc) {
522 var on_success = function(data) {
523 var msg = $.ajatus.elements.messages.create(
524 $.ajatus.i10n.get('Object deleted'),
525 $.ajatus.i10n.get('Object %s removed from Ajatus.', [doc.value.title.val])
530 $.jqCouch.connection('doc', on_success).del($.ajatus.preferences.client.content_database, doc);
531 $('#object_'+doc._id, $.ajatus.application_content_area).remove();
534 var on_success = function(data) {
535 var msg = $.ajatus.elements.messages.create(
536 $.ajatus.i10n.get('Object restored'),
537 $.ajatus.i10n.get('Object %s restored succesfully.', [doc.value.title.val])
542 doc = $.ajatus.document.modify_metadata(doc, {
544 revised: $.ajatus.formatter.date.js_to_iso8601(new Date()),
545 revisor: $.ajatus.preferences.local.user.email
547 $.jqCouch.connection('doc', on_success).save($.ajatus.preferences.client.content_database, doc);
549 $('#object_'+doc._id, $.ajatus.application_content_area).not('.deleted').remove();
550 $('#object_'+doc._id, $.ajatus.application_content_area).filter('.deleted').show().removeClass('deleted');
553 var on_success = function(data) {
554 var msg = $.ajatus.elements.messages.create(
555 $.ajatus.i10n.get('Object restored'),
556 $.ajatus.i10n.get('Object %s restored succesfully.', [doc.value.title.val])
561 doc = $.ajatus.document.modify_metadata(doc, {
562 revised: $.ajatus.formatter.date.js_to_iso8601(new Date()),
563 revisor: $.ajatus.preferences.local.user.email,
566 $.jqCouch.connection('doc', on_success).save($.ajatus.preferences.client.content_database, doc);
568 $('#object_'+doc._id, $.ajatus.application_content_area).filter('.archived').show().removeClass('archived');
572 empty_pool: function () {
573 var items = $.ajatus.document.history.pool.get_all();
574 if (items.length > 0) {
575 var msg = $.ajatus.elements.messages.create(
576 $.ajatus.i10n.get('Emptying action pool'),
577 $.ajatus.i10n.get('Running %d pooled actions.', [items.length])
580 $.each(items, function(i,item){
581 $.ajatus.document.history.pool.remove(i);
582 $.ajatus.document.actions.execute(item.action, item.doc);
585 _get_action_info: function(action) {
590 label: $.ajatus.i10n.get('Delete'),
592 undo_label: $.ajatus.i10n.get('Undelete'),
599 label: $.ajatus.i10n.get('Delete'),
607 label: $.ajatus.i10n.get('Undelete'),
615 label: $.ajatus.i10n.get('Archive'),
617 undo_label: $.ajatus.i10n.get('Restore'),
624 label: $.ajatus.i10n.get('Restore'),
635 $.ajatus.document.history = {};
636 $.ajatus.document.history.pool = {
639 add: function(action) {
640 var new_length = $.ajatus.document.history.pool.items.push(action);
641 var pool_id = new_length-1;
644 remove: function(item_id) {
645 $.ajatus.document.history.pool.items = $.grep($.ajatus.document.history.pool.items, function(n,i){
649 get_item: function(item_id) {
650 if (items[item_id]) {
651 return items[item_id];
656 get_all: function() {
657 return $.ajatus.document.history.pool.items;
661 $.ajatus.document.additionals = {
670 $.extend($.ajatus.document.additionals, {
671 create: function(content_type, row_holder, opts) {
672 $.ajatus.document.additionals._reset();
674 var id = $.ajatus.document.additionals._generate_id();
676 var options = $.ajatus.document.additionals.defaults;
682 var af_win = $.ajatus.document.additionals._create_structure(id, options);
683 $('.title', af_win).html($.ajatus.i10n.get('Add field'));
685 var jqform = $('.form', af_win);
686 var contents = $('.contents', af_win);
688 var wdgts = $.ajatus.document.additionals._generate_widget_list();
690 $('<label for="widget"/>').html($.ajatus.i10n.get('Widget')).appendTo(contents);
691 var wdgt_sel_holder = $('<div id="widget_selection_holder"/>');
692 wdgt_sel_holder.html(wdgts).appendTo(contents);
694 var wdgt_details = $('<div id="widget_details_holder"/>');
695 wdgt_details.appendTo(contents);
697 var wdgts_on_change = function(e){
698 var sel_w = e.currentTarget.value;
700 wdgt_sel_holder.html($.ajatus.i10n.get(sel_w));
701 wdgt_sel_holder.addClass('selected');
702 wdgt_details.html($.ajatus.document.additionals._generate_widget_details(sel_w));
704 var field = $('<input type="hidden" />').attr({
708 field.appendTo(jqform);
712 wdgts.bind('change', wdgts_on_change);
714 wdgt_sel_holder.bind('dblclick', function(e){
715 wdgt_sel_holder.removeClass('selected');
716 wdgt_sel_holder.html(wdgts);
717 wdgts.bind('change', wdgts_on_change);
720 $('.actions #submit_save', af_win).bind('click', function(e){
721 var result = $.ajatus.document.additionals.save_widget(jqform.formToArray(false), jqform);
724 $.ajatus.document.additionals.close(id);
730 if (options.auto_show) {
731 $.ajatus.document.additionals.show(id);
734 edit: function(content_type, row_holder, data, opts) {
735 $.ajatus.document.additionals._reset();
737 var id = $.ajatus.document.additionals._generate_id();
738 console.log("Edit win id: "+id);
740 var options = $.ajatus.document.additionals.defaults;
746 var af_win = $.ajatus.document.additionals._create_structure(id, options);
747 $('.title', af_win).html($.ajatus.i10n.get('Edit field %s', [data.name]));
749 $('.actions #submit_save', af_win).bind('click', function(e){
750 console.log("save additional field (on edit)");
751 $.ajatus.document.additionals.close(id);
754 if (options.auto_show) {
755 $.ajatus.document.additionals.show(id);
758 config: function(widget, prev_vals, on_save) {
759 if (typeof prev_vals == 'undefined') {
762 if (typeof on_save == 'undefined') {
763 var on_save = '$.ajatus.document.additionals.save_widget_settings';
766 var id = $.ajatus.document.additionals._generate_id();
768 var af_win = $.ajatus.document.additionals._create_structure(id);
769 $('.title', af_win).html($.ajatus.i10n.get('Configure widget %s', [$.ajatus.i10n.get(widget.name)]));
771 var jqform = $('.form', af_win);
772 var contents = $('.contents', af_win);
774 var wdgt_settings = $('<div id="widget_settings_holder" />');
775 wdgt_settings.appendTo(contents);
776 wdgt_settings.html($.ajatus.document.additionals._generate_widget_settings(widget, prev_vals));
778 $('.actions #submit_save', af_win).bind('click', function(e){
779 var parent_win = $.ajatus.document.additionals._get_parent();
782 if (typeof on_save == 'string') {
785 var result = fn.apply(fn, [jqform.formToArray(false), parent_win, jqform]);
788 $.ajatus.document.additionals.close(id);
792 $.ajatus.document.additionals.show(id);
795 $.ajatus.document.additionals.active = id;
796 $.ajatus.document.additionals.open.push(id);
797 $.ajatus.document.additionals._position(id);
801 close: function(id) {
802 if (typeof id == 'undefined') {
803 var id = $.ajatus.document.additionals.active;
808 var active_idx = null;
809 var still_open = $.grep($.ajatus.document.additionals.open, function(n,i){
819 && $.ajatus.document.additionals.open.length-1 >= (active_idx-1))
821 $.ajatus.document.additionals.active = still_open[active_idx-1];
823 $.ajatus.document.additionals.active = null;
826 $.ajatus.document.additionals.open = still_open;
828 save_widget_settings: function(form_data, parent_win_id, form) {
829 var form_values = {};
831 $.each(form_data, function(i,row){
832 if (row.name.toString().match(/__(.*?)/)) {
835 if (row.name.substr(0,6) != "widget") {
838 var prev_val = false;
840 var name_parts_count = 0;
841 if (row.name.toString().match(/;/g)) {
842 name_parts = row.name.toString().split(";");
843 name_parts_count = name_parts.length;
846 $.each(form_data, function(x,r){
847 if (r.name == 'widget['+row.name+':name]') {
848 widget['name'] = r.value;
849 } else if (r.name == 'widget['+row.name+':config]') {
850 widget['config'] = $.ajatus.converter.parseJSON(r.value);
851 } else if (r.name == 'widget['+row.name+':prev_val]') {
852 prev_val = $.ajatus.converter.parseJSON(r.value);
856 var wdgt = new $.ajatus.widget(widget['name'], widget['config']);
858 item['val'] = wdgt.value_on_save(row.value, prev_val);
859 item['widget'] = widget;
861 if (name_parts_count > 0) {
863 for (var i=0; i < name_parts_count; i++) {
864 var key = "['"+name_parts[i]+"']";
866 if (prevs.length > 0) {
868 $.each(prevs, function(pi, pk){
869 key_prefix = "['" + pk + "']" + key_prefix;
871 key = key_prefix + key;
874 if (typeof eval("form_values"+key) == 'undefined') {
875 eval("form_values"+key+"={};");
878 prevs.push(name_parts[i]);
879 if (i == name_parts_count-1) {
880 if ($.browser.mozilla) {
881 if (typeof item == 'object') {
882 eval("form_values"+key+"="+item.toSource()+";");
884 eval("form_values"+key+"="+item+";");
887 eval("form_values"+key+"="+item+";");
892 form_values[row.name] = item;
897 var config_holder = $('#'+parent_win_id+' .saved_settings');
898 config_holder.html('');
900 $.each(form_values, function(k,item){
901 var field = $('<input type="hidden" />').attr({
903 value: $.ajatus.converter.toJSON(item.val)
905 field.appendTo(config_holder);
910 save_widget: function(form_data, form) {
911 var form_values = {};
912 var sel_widget = 'text';
914 // console.log(form_values);
916 $.each(form_data, function(i,row){
917 if (row.name.toString().match(/__(.*?)/)) {
920 if (row.name == '_widget') {
921 sel_widget = String(row.value);
923 else if (row.name.substr(0,6) != "widget") {
926 var prev_val = false;
928 var name_parts_count = 0;
930 if (row.name.toString().match(/;/g)) {
931 name_parts = row.name.toString().split(";");
932 name_parts_count = name_parts.length;
935 $.each(form_data, function(x,r){
936 if (r.name == 'widget['+row.name+':name]') {
937 widget['name'] = r.value;
938 } else if (r.name == 'widget['+row.name+':config]') {
939 widget['config'] = $.ajatus.converter.parseJSON(r.value);
940 } else if (r.name == 'widget['+row.name+':prev_val]') {
941 prev_val = $.ajatus.converter.parseJSON(r.value);
945 if (typeof widget['name'] == 'undefined') {
949 var wdgt = new $.ajatus.widget(widget['name'], widget['config']);
951 item['val'] = wdgt.value_on_save(row.value, prev_val);
952 item['widget'] = widget;
954 if (name_parts_count > 0) {
955 // console.log("name_parts_count > 0");
957 for (var i=0; i < name_parts_count; i++) {
958 var key = "['"+name_parts[i]+"']";
960 if (prevs.length > 0) {
962 $.each(prevs, function(pi, pk){
963 key_prefix = "['" + pk + "']" + key_prefix;
965 key = key_prefix + key;
968 if (typeof eval("form_values"+key) == 'undefined') {
969 eval("form_values"+key+"={};");
972 prevs.push(name_parts[i]);
973 if (i == name_parts_count-1) {
974 if ($.browser.mozilla) {
975 if (typeof item == 'object') {
976 eval("form_values"+key+"="+item.toSource()+";");
978 eval("form_values"+key+"="+item+";");
981 eval("form_values"+key+"="+item+";");
986 form_values[row.name] = item;
991 // var additional_items = {};
994 if (typeof form_values['config'] != 'undefined') {
995 $.each(form_values['config'], function(i,n){
996 if (typeof n == 'object') {
997 config[i] = $.ajatus.converter.parseJSON(n.val);
1004 var item_name = form_values.name.val.toString().toLowerCase();
1006 if (item_name == '') {
1010 var additional_item = {
1011 label: form_values.label.val,
1016 def_val: form_values.def_val.val,
1017 required: form_values.required.val
1019 // additional_items[item_name] = additional_item;
1020 // console.log(additional_items);
1021 // console.log(additional_item);
1023 var row_holder = $('.form_structure ul.row_holder:eq(0)', $.ajatus.forms.active);
1025 $.ajatus.renderer.form_helpers._add_additional_row('create', row_holder, item_name, additional_item);
1029 generate_item_actions_tpl: function(name, widget, doc) {
1031 'img', { className: 'additional_edit_btn', src: $.ajatus.preferences.client.theme_icons_url + 'edit.png', title: $.ajatus.i10n.get('Edit'), alt: $.ajatus.i10n.get('Edit') }, '',
1032 'img', { className: 'additional_delete_btn', src: $.ajatus.preferences.client.theme_icons_url + 'trash.png', title: $.ajatus.i10n.get('Delete'), alt: $.ajatus.i10n.get('Delete') }, '',
1035 _get_parent: function() {
1036 var prev_id = $.ajatus.document.additionals.open[$.ajatus.document.additionals.open.length-2];
1040 _position: function(id) {
1041 var win = $('#' + id);
1042 var top = $.ajatus.document.additionals.top_start;
1043 var left = $.ajatus.document.additionals.left_start;
1045 if ($.ajatus.document.additionals.open.length > 1) {
1046 var incr = $.ajatus.document.additionals.open.length * 2;
1056 _create_structure: function(id, options) {
1057 var af_win = $('<div class="additionals_window" />').attr({
1060 var title = $('<h2 class="title"/>');
1061 var form = $('<form id="additionals_window_form" class="form" />');
1062 var content_area = $('<div class="contents"/>');
1063 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') + '" />');
1065 af_win.appendTo($.ajatus.application_dynamic_elements);
1066 title.appendTo(af_win);
1067 form.appendTo(af_win);
1068 content_area.appendTo(form);
1069 actions.appendTo(af_win);
1071 $('#submit_cancel', actions).bind('click', function(e){
1072 $.ajatus.document.additionals.close(id);
1078 _generate_widget_list: function() {
1079 var select = $('<select id="widget" name="widget" />');
1081 $.each($.ajatus.widgets.loaded_widgets, function(i,w){
1082 var opt = $('<option />').attr({
1084 }).html($.ajatus.i10n.get(w));
1085 opt.appendTo(select);
1088 var opt = $('<option />').attr({
1090 selected: 'selected'
1091 }).html($.ajatus.i10n.get('Select one') + ' ');
1092 opt.prependTo(select);
1096 _generate_widget_details: function(widget_name, data) {
1097 var widget = $.ajatus.widget(widget_name);
1098 var details = $('<p>' + $.ajatus.i10n.get("Widget %s doesn't support dynamic creation.", [$.ajatus.i10n.get(widget_name)]) + '</p>');
1099 if (typeof(widget['create_widget_details']) == 'function') {
1100 details = widget.create_widget_details(data || {});
1105 _generate_widget_settings: function(widget_name, data) {
1106 var widget = $.ajatus.widget(widget_name);
1107 var details = $('<p>' + $.ajatus.i10n.get("Widget %s doesn't support dynamic settings.", [$.ajatus.i10n.get(widget_name)]) + '</p>');
1108 if (typeof(widget['create_widget_settings']) == 'function') {
1109 details = widget.create_widget_settings(data || {});
1114 _reset: function() {
1115 $.ajatus.document.additionals.open = [];
1116 $.ajatus.document.additionals.active = null;
1117 $.ajatus.application_dynamic_elements.html('');
1119 _generate_id: function()
1121 return "additionals_window_" + $.ajatus.utils.generate_id();