add AJATUS_ROOT to include path since autoloading is not used everywhere, some places...
[ajatus.git] / js / ajatus.installer.js
bloba70016816426430997e91c70687d612cfb152cd5
1 /*
2  * This file is part of
3  *
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
12  * 
13  */
15 (function($){
16     $.ajatus = $.ajatus || {};
17     
18     $.ajatus.installer = {
19         installed: false,
20         installed_version: null,
21         
22         is_installed: function()
23         {
24             if ($.jqCouch.connection('db').exists($.ajatus.preferences.client.application_database)) {
25                 $.ajatus.installer.installed = true;
27                 var version = $.jqCouch.connection('doc').get($.ajatus.preferences.client.application_database + '/version');
28                 $.ajatus.installer.installed_version = version.value;
29                 $.ajatus.installer.installed_version_rev = version._rev;
30             }            
31         },
33         install: function()
34         {
35             var dbc = $.jqCouch.connection('db');
36             
37             var row = '';
38             var row_failed = '<span class="status_failed">' + $.ajatus.i10n.get('failed').toUpperCase() + '</span><br />';
39             var row_ok = '<span class="status_ok">' + $.ajatus.i10n.get('ok').toUpperCase() + '</span><br />';
40                         
41             $.ajatus.debug('Installing');
42             
43             var dialog = new $.ajatus.elements.dialog($.ajatus.i10n.get('Installing'), '', {
44                 closable: false
45             });
46             
47             dialog.open();
48             
49             row = $.ajatus.i10n.get('Installing application database') + '... ';
50             dialog.append_content(row);
51             // jqcouch_db.create($.ajatus.preferences.client.application_database);
53             row = row_failed;
54             if (dbc.create($.ajatus.preferences.client.application_database).ok) {
55                 row = row_ok;
56             }
57             dialog.append_content(row);
58             
59             row = $.ajatus.i10n.get('Preparing application database') + '... ';
60             dialog.append_content(row);
61             
62             row = row_failed;
63             if ($.jqCouch.connection('doc').put($.ajatus.preferences.client.application_database + '/preferences', {value: $.ajatus.preferences.local_defaults}).id) {
64                 row = row_ok;
65             }
66             if ($.jqCouch.connection('doc').put($.ajatus.preferences.client.application_database + '/version', {value: $.ajatus.version}).id) {
67                 row = row_ok;
68             }
69             dialog.append_content(row);
70             
71             row = $.ajatus.i10n.get('Installing application content database') + '... ';
72             dialog.append_content(row);
74             row = row_failed;
75             if (dbc.create($.ajatus.preferences.client.content_database).ok) {
76                 row = row_ok;
77             }
78             dialog.append_content(row);
79             
80             var close = jQuery('<br /><br /><span class="jqmClose">' + $.ajatus.i10n.get('Continue') + '</span>');
81             dialog.append_content(close);
82             jQuery('#' + dialog.id + ' .jqmClose').bind('click', function(e){
83                 dialog.close();
84                 $.ajatus.preload();
85             }).css({cursor: 'pointer'});
86                         
87             return true;
88         },
89         
90         uninstall: function()
91         {            
92             var dbc = $.jqCouch.connection('db');
93             
94             var row = '';
95             var row_failed = '<span class="status_failed">' + $.ajatus.i10n.get('failed').toUpperCase() + '</span><br />';
96             var row_ok = '<span class="status_ok">' + $.ajatus.i10n.get('ok').toUpperCase() + '</span><br />';
97             
98             $.ajatus.debug('uninstalling');
99             
100             var dialog = new $.ajatus.elements.dialog($.ajatus.i10n.get('Uninstalling'), '', {
101                 closable: false
102             });
103             
104             dialog.open();
105             
106             row = $.ajatus.i10n.get('Uninstalling application content database') + '... ';
107             dialog.append_content(row);
109             row = row_failed;
110             if (dbc.del($.ajatus.preferences.client.content_database).ok) {
111                 row = row_ok;
112             }
113             dialog.append_content(row);
115             row = $.ajatus.i10n.get('Uninstalling application database') + '... ';
116             dialog.append_content(row);
118             row = row_failed;
119             if (dbc.del($.ajatus.preferences.client.application_database).ok) {
120                 row = row_ok;
121             }
122             dialog.append_content(row);
123             
124             var close = jQuery('<br /><br /><span class="jqmClose">' + $.ajatus.i10n.get('Continue') + '</span>');
125             dialog.append_content(close);
126             jQuery('#' + dialog.id + ' .jqmClose').bind('click', function(e){
127                 dialog.close();
128                 window.location.reload();
129             }).css({cursor: 'pointer'});
130                         
131             return true;            
132         }
133     };
134     
135 })(jQuery);