2 $.ajatus = $.ajatus || {};
7 $.extend($.ajatus.forms, {
9 normal: function(form) {
10 $.ajatus.events.named_lock_pool.increase('unsaved');
12 jqform = jQuery(form);
13 jqform.bind('submit',function(e){
17 $('input[@type=submit]', jqform).bind('click', function(){
18 //$.ajatus.process_form(jqform.formToArray(false));
19 $.ajatus.forms.process.normal(jqform.formToArray(false));
22 ajax: function(form) {
23 $.ajatus.events.named_lock_pool.increase('unsaved');
25 jqform = jQuery(form);
26 jqform.bind('submit',function(e){
30 $('input[@type=submit]', jqform).bind('click', function(){
31 $.ajatus.forms.process.ajax(jqform.formToArray(false));
37 common: function(form_data) {
45 var doc_type = 'note';
47 $.each(form_data, function(i,row){
48 //console.log('i: '+i+' row.name: '+row.name+' row.value: '+row.value);
50 if ( row.name == '_id'
51 && ( row.value != undefined
54 doc['_id'] = String(row.value);
57 else if( row.name == '_rev'
58 && ( row.value != undefined
61 doc['_rev'] = Number(row.value);
63 if (row.name != 'submit') {
64 if (row.name == '_type') {
66 form_values[row.name] = row.value;
68 else if ( row.name.substr(0,6) != "widget"
69 && row.name.substr(0,8) != "metadata")
74 $.each(form_data, function(x,r){
75 if (r.name == 'widget['+row.name+':name]') {
76 widget['name'] = r.value;
77 } else if (r.name == 'widget['+row.name+':config]') {
78 widget['config'] = $.ajatus.converter.parseJSON(r.value);
79 } else if (r.name == 'widget['+row.name+':prev_val]') {
80 prev_val = $.ajatus.converter.parseJSON(r.value);
84 var wdgt = new $.ajatus.widget(widget['name'], widget['config']);
85 item['val'] = wdgt.value_on_save(row.value, prev_val);
86 item['widget'] = widget;
87 form_values[row.name] = item;
89 else if (row.name.substr(0,8) == "metadata")
91 if (!form_values['metadata'])
93 form_values['metadata'] = {};
96 var re = /\bmetadata\[([a-z]+)\b/;
97 var results = re.exec(row.name);
100 form_values['metadata'][key] = {
107 doc['value'] = form_values;
109 doc = new $.ajatus.document(doc);
111 var now = $.ajatus.formatter.date.js_to_iso8601(new Date());
115 revisor: $.ajatus.preferences.local.user
117 if ( doc._id == undefined
120 new_metadata['created'] = now;
121 new_metadata['creator'] = $.ajatus.preferences.local.user;
124 $.ajatus.forms.process.doc = $.ajatus.document.modify_metadata(doc, new_metadata);
126 return $.ajatus.forms.process.doc;
128 normal: function(form_data) {
129 var doc = $.ajatus.forms.process.common(form_data);
131 var jqcouch = $.jqcouch.doc;
132 var db_path = $.ajatus.preferences.client.application_database + '/content';
133 jqcouch.on_success = function(data, caller) {
135 doc['_id'] = data._id;
136 doc['_rev'] = data._rev;
137 doc = new $.ajatus.document(doc);
138 $.ajatus.views.system.item.render(doc);
139 $.ajatus.events.named_lock_pool.decrease('unsaved');
142 jqcouch.save(db_path, $.ajatus.forms.process.doc);
145 ajax: function(form_data) {
146 var doc = $.ajatus.forms.process.common(form_data);
148 $.ajatus.events.named_lock_pool.decrease('unsaved');