Dutch from Niels Breet and Polish from Piotr Pokora
[ajatus.git] / js / ajatus.preferences.js
blobde3fe53aa5f48f399766b0aaa79b0121c5ba3f80
1 /*
2 * This file is part of
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
15 (function($){
16 $.ajatus = $.ajatus || {};
17 $.ajatus.preferences = {};
19 $.ajatus.preferences.local = {};
20 $.ajatus.preferences.local_defaults = {
21 user: {
22 name: 'Root Ajatus'
24 replication: {
25 enabled: false,
26 public_key: '',
27 allowed_keys: ''
29 layout: {
30 content_height: '460px'
32 localization: {
33 language: 'en_GB'
35 backups: {
36 enabled: false,
37 auto: false
39 expansions: {
40 active: []
44 $.ajatus.preferences.client = {};
45 $.ajatus.preferences.client_defaults = {
46 debug: false,
47 history: true,
48 language: null,
49 server_url: '/',
50 application_url: '/_utils/ajatus/',
51 application_database_identifier: 'stable',
52 content_types: {},
53 custom_views: [],
54 custom_widgets: [],
55 extensions: [
56 'history'
60 $.ajatus.preferences.loader = function() {
61 this.jqcouch = $.jqcouch.doc;
62 this.loaded = false;
64 this.jqcouch.on_error = function(request, caller)
66 this.loaded = false;
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, {
77 load: function() {
78 $.ajatus.events.lock_pool.increase();
79 this.jqcouch.get($.ajatus.preferences.client.application_database + '/preferences');
81 });
83 $.ajatus.preferences.view = {
84 title: 'Preferences',
85 options: {},
86 sections: [
87 'user', 'localization', 'replication', 'layout', 'backups', 'expansions'
90 tab: {
91 on_click: function(e)
93 $.ajatus.tabs.on_click(e);
94 $.ajatus.preferences.view.render();
98 render: function() {
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);
117 if (form_items) {
118 form_items.appendTo(section_holder);
123 generate_section_form: function(section) {
124 if (typeof $.ajatus.preferences.local[section] == 'undefined') {
125 return false;
128 var items = false;
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: ");
136 // console.log(s);
137 var s_type = typeof(s);
138 // console.log('type: '+s_type);
139 var wdgt = null;
140 var normalized_name = i.toString().replace('_', ' ');
142 switch (s_type) {
143 case 'boolean':
144 wdgt = $.ajatus.widget('boolean');
145 break;
146 case 'number':
147 wdgt = $.ajatus.widget('integer');
148 break;
149 case 'string':
150 default:
151 wdgt = $.ajatus.widget('text');
154 rows.createAppend(
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');
167 return rows;
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({
177 value: this
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);
190 return rows;
193 switch (section) {
194 case 'localization':
195 items = gen_localization(section_data);
196 break;
197 default:
198 items = auto_gen(section_data);
201 return items;
205 })(jQuery);