Added check to frontpage view if the type should be shown in the list.
[ajatus.git] / js / ajatus.installer.js
blob9b67b14799ea09a7f65323b7d52c2e81cb70bfe8
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         
21         is_installed: function()
22         {
23             if ($.jqCouch.connection('db').exists($.ajatus.preferences.client.application_database)) {
24                 $.ajatus.installer.installed = true;
25             }
26         },
28         install: function()
29         {
30             var dbc = $.jqCouch.connection('db');
31             
32             var row = '';
33             var row_failed = '<span class="status_failed">' + $.ajatus.i10n.get('failed').toUpperCase() + '</span><br />';
34             var row_ok = '<span class="status_ok">' + $.ajatus.i10n.get('ok').toUpperCase() + '</span><br />';
35                         
36             $.ajatus.debug('Installing');
37             
38             var dialog = new $.ajatus.elements.dialog($.ajatus.i10n.get('Installing'), '', {
39                 closable: false
40             });
41             
42             dialog.open();
43             
44             row = $.ajatus.i10n.get('Installing application database') + '... ';
45             dialog.append_content(row);
46             // jqcouch_db.create($.ajatus.preferences.client.application_database);
48             row = row_failed;
49             if (dbc.create($.ajatus.preferences.client.application_database).ok) {
50                 row = row_ok;
51             }
52             dialog.append_content(row);
53             
54             row = $.ajatus.i10n.get('Preparing application database') + '... ';
55             dialog.append_content(row);
56             
57             row = row_failed;
58             if ($.jqCouch.connection('doc').put($.ajatus.preferences.client.application_database + '/preferences', {value: $.ajatus.preferences.local_defaults}).id) {
59                 row = row_ok;
60             }
61             if ($.jqCouch.connection('doc').put($.ajatus.preferences.client.application_database + '/version', {value: $.ajatus.version}).id) {
62                 row = row_ok;
63             }
64             dialog.append_content(row);
65             
66             row = $.ajatus.i10n.get('Installing application content database') + '... ';
67             dialog.append_content(row);
69             row = row_failed;
70             if (dbc.create($.ajatus.preferences.client.content_database).ok) {
71                 row = row_ok;
72             }
73             dialog.append_content(row);
74             
75             var close = jQuery('<br /><br /><span class="jqmClose">' + $.ajatus.i10n.get('Continue') + '</span>');
76             dialog.append_content(close);
77             jQuery('#' + dialog.id + ' .jqmClose').bind('click', function(e){
78                 dialog.close();
79                 $.ajatus.preload();
80             }).css({cursor: 'pointer'});
81                         
82             return true;
83         },
84         
85         uninstall: function()
86         {            
87             var dbc = $.jqCouch.connection('db');
88             
89             var row = '';
90             var row_failed = '<span class="status_failed">' + $.ajatus.i10n.get('failed').toUpperCase() + '</span><br />';
91             var row_ok = '<span class="status_ok">' + $.ajatus.i10n.get('ok').toUpperCase() + '</span><br />';
92             
93             $.ajatus.debug('uninstalling');
94             
95             var dialog = new $.ajatus.elements.dialog($.ajatus.i10n.get('Uninstalling'), '', {
96                 closable: false
97             });
98             
99             dialog.open();
100             
101             row = $.ajatus.i10n.get('Uninstalling application content database') + '... ';
102             dialog.append_content(row);
104             row = row_failed;
105             if (dbc.del($.ajatus.preferences.client.content_database).ok) {
106                 row = row_ok;
107             }
108             dialog.append_content(row);
110             row = $.ajatus.i10n.get('Uninstalling application database') + '... ';
111             dialog.append_content(row);
113             row = row_failed;
114             if (dbc.del($.ajatus.preferences.client.application_database).ok) {
115                 row = row_ok;
116             }
117             dialog.append_content(row);
118             
119             var close = jQuery('<br /><br /><span class="jqmClose">' + $.ajatus.i10n.get('Continue') + '</span>');
120             dialog.append_content(close);
121             jQuery('#' + dialog.id + ' .jqmClose').bind('click', function(e){
122                 dialog.close();
123                 window.location.reload();
124             }).css({cursor: 'pointer'});
125                         
126             return true;            
127         }
128     };
129     
130 })(jQuery);