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
16 $.ajatus
= $.ajatus
|| {};
17 $.ajatus
.preferences
= {};
19 $.ajatus
.preferences
.local
= {};
20 $.ajatus
.preferences
.local_defaults
= {
30 content_height
: '460px'
44 $.ajatus
.preferences
.client
= {};
45 $.ajatus
.preferences
.client_defaults
= {
50 application_url
: '/_utils/ajatus/',
51 application_database_identifier
: 'stable',
60 $.ajatus
.preferences
.loader = function() {
61 this.jqcouch
= $.jqcouch
.doc
;
64 this.jqcouch
.on_error = function(request
, caller
)
67 $.ajatus
.events
.lock_pool
.decrease();
68 $.ajatus
.ajax_error(request
, caller
);
70 this.jqcouch
.on_success = function(data
, caller
)
72 $.ajatus
.events
.lock_pool
.decrease();
73 $.ajatus
.preferences
.local
= $.extend({}, $.ajatus
.preferences
.local_defaults
, data
.value
);
76 $.extend($.ajatus
.preferences
.loader
.prototype, {
78 $.ajatus
.events
.lock_pool
.increase();
79 this.jqcouch
.get($.ajatus
.preferences
.client
.application_database
+ '/preferences');
83 $.ajatus
.preferences
.view
= {
87 'user', 'localization', 'replication', 'layout', 'backups', 'expansions'
93 $.ajatus
.tabs
.on_click(e
);
94 $.ajatus
.preferences
.view
.render();
99 $.ajatus
.application_content_area
.html('');
100 $.ajatus
.layout
.body
.set_class('preferences');
101 $.ajatus
.views
.on_change("#view.preferences");
103 var form
= $('<form name="preferences"/>');
104 form
.appendTo($.ajatus
.application_content_area
);
106 var sections_holder
= $('<div id="preference_sections" />');
107 sections_holder
.appendTo(form
);
109 $.each($.ajatus
.preferences
.view
.sections
, function(i
,s
){
110 var section_holder
= $('<div class="section" id="section_' + s
+ '" />');
111 section_holder
.appendTo(sections_holder
);
113 var title
= $('<h3 />').html($.ajatus
.i10n
.get(s
));
114 title
.appendTo(section_holder
);
116 var form_items
= $.ajatus
.preferences
.view
.generate_section_form(s
);
118 form_items
.appendTo(section_holder
);
123 generate_section_form: function(section
) {
124 if (typeof $.ajatus
.preferences
.local
[section
] == 'undefined') {
129 var section_data
= $.ajatus
.preferences
.local
[section
];
131 function auto_gen(data
) {
132 var rows
= $('<ul/>');
134 $.each(data
, function(i
,s
){
135 // console.log("i: "+i+" s: ");
137 var s_type
= typeof(s
);
138 // console.log('type: '+s_type);
140 var normalized_name
= i
.toString().replace('_', ' ');
144 wdgt
= $.ajatus
.widget('boolean');
147 wdgt
= $.ajatus
.widget('integer');
151 wdgt
= $.ajatus
.widget('text');
155 'li', { id
: '_setting_'+i
, className
: 'row' }, [
156 'label', { id
: '_setting_'+i
+'_label' }, $.ajatus
.i10n
.get(normalized_name
),
157 'div', { id
: '_setting_'+i
+'_widget', className
: wdgt
.name
}, wdgt
.get_create_tpl(i
, s
),
158 'br', { className
: 'clear_fix' }, ''
161 wdgt
.init($('#_setting_'+i
+'_widget',rows
), true);
164 $('li:first', rows
).addClass('first');
165 $('li:last', rows
).addClass('last');
170 function gen_localization(data
) {
171 var rows
= $('<ul/>');
172 var langs
= $.ajatus
.i10n
.get_available_langs();
174 var select
= $('<select name="localization[language]" />');
175 $.each(langs
, function(i
){
176 var opt
= $('<option>'+$.ajatus
.i10n
.get(this)+'</option>').attr({
179 opt
.appendTo(select
);
182 $('option', select
).each(function(i
,o
){
183 if (o
.value
== data
.language
) {
184 o
.selected
= 'selected';
188 select
.appendTo(rows
);
195 items
= gen_localization(section_data
);
198 items
= auto_gen(section_data
);