]> git.sur5r.net Git - contagged/blob - scripts/gui.js
e4a9a2688bbe5e0d895d0824519f50838cadb45b
[contagged] / scripts / gui.js
1
2 /**
3  * Inplace tag editing
4  */
5 function tagedit() {
6     var txt  = document.createElement('textarea');
7     txt.id   = 'tagedit_editor';
8     txt.name = 'marker';
9     txt.className = 'ipe';
10     $(txt).load('ajax.php',{loadtags: 'plain', dn: DN});
11     $(txt).Autocomplete({
12         source: 'ajax.php',
13         delay: 300,
14         helperClass: 'autocompleter',
15         selectClass: 'autocompleterSelect',
16         inputWidth: true,
17         minchars: 1,
18         multiple: true,
19         multipleSeperator: ','
20     });
21
22     var save       = new Image();
23     save.src       = 'pix/accept.png';
24     save.id        = 'tagedit_save';
25     save.className = 'click';
26     $(save).click(function(){
27         $('#taglist').load('ajax.php',{settags: $('#tagedit_editor').val(), dn: DN});
28         $('#tagedit_save').remove();
29         $('#tagedit_cancel').remove();
30         $('#tagedit_start').show();
31     });
32
33     var canc       = new Image();
34     canc.src       = 'pix/cancel.png';
35     canc.id        = 'tagedit_cancel';
36     canc.className = 'click';
37     $(canc).click(function(){
38         $('#taglist').load('ajax.php',{loadtags: 'html', dn: DN});
39         $('#tagedit_save').remove();
40         $('#tagedit_cancel').remove();
41         $('#tagedit_start').show();
42     });
43
44     $('#tagedit_start').hide();
45     $('#taglist').empty().prepend(txt);
46     $('#tagedit').append(save);
47     $('#tagedit').append(canc);
48     $('#tagedit_editor').focus();
49 }
50
51 /**
52  * Inplace note adding
53  */
54 function noteedit(type){
55     var txt  = document.createElement('textarea');
56     txt.id   = 'noteedit_editor';
57     txt.className = 'ipe';
58
59     // prepare text
60     var text = '';
61     if(type=='call'){
62         text += '**Call** ';
63     }else if(type=='mail'){
64         text += '**Mail** ';
65     }else if(type=='todo'){
66         text += '**Todo** ';
67     }else if(type=='note'){
68         text += '**Note** ';
69     }
70     var dt = new Date();
71     text += '//'+dt.formatDate('j. M y H:i')+' '+USER+'//: ';
72     $(txt).val(text);
73
74     var save       = new Image();
75     save.src       = 'pix/accept.png';
76     save.id        = 'noteedit_save';
77     save.className = 'click';
78     $(save).click(function(){
79         $('#notes').load('ajax.php',{addnote: $('#noteedit_editor').val(), dn: DN});
80         $('#noteedit_editor').remove();
81         $('#noteedit_save').remove();
82         $('#noteedit_cancel').remove();
83         $('#noteedit .ed').show()
84     });
85
86     var canc       = new Image();
87     canc.src       = 'pix/cancel.png';
88     canc.id        = 'noteedit_cancel';
89     canc.className = 'click';
90     $(canc).click(function(){
91         $('#noteedit_editor').remove();
92         $('#noteedit_save').remove();
93         $('#noteedit_cancel').remove();
94         $('#noteedit .ed').show();
95     });
96
97     $('#notes').prepend(txt);
98     $('#noteedit .ed').hide();
99     $('#noteedit').append(save);
100     $('#noteedit').append(canc);
101     $('#noteedit_editor').focus();
102 }
103
104
105
106 /**
107  * Initialize everything when DOM is ready
108  */
109 $(document).ready(function() {
110
111     // autocompletion
112     $('#taglookup').Autocomplete({
113         source: 'ajax.php',
114         delay: 300,
115         helperClass: 'autocompleter',
116         selectClass: 'autocompleterSelect',
117         inputWidth: true,
118         minchars: 1,
119         //multiple: true,
120         //multipleSeperator: ','
121     });
122     $('#tageditlookup').Autocomplete({
123         source: 'ajax.php',
124         delay: 300,
125         helperClass: 'autocompleter',
126         selectClass: 'autocompleterSelect',
127         inputWidth: true,
128         minchars: 1,
129         multiple: true,
130         multipleSeperator: ','
131     });
132     // autocompletion
133     $('input.ac').Autocomplete({
134         source: 'ajax.php',
135         delay: 300,
136         helperClass: 'autocompleter',
137         selectClass: 'autocompleterSelect',
138         inputWidth: true,
139         minchars: 1,
140     });
141
142     // nice images
143     $.ImageBox.init({
144         loaderSRC: 'pix/imagebox/loading.gif',
145         closeHTML: '<img src="pix/imagebox/close.jpg" border="0" />'
146     });
147
148     // tag editing
149     if($('#tagedit')){
150         var img       = new Image();
151         img.src       = 'pix/tag_blue_edit.png';
152         img.className = 'click';
153         img.id        = 'tagedit_start';
154         $('#tagedit').empty().after(img);
155         $(img).click(tagedit)
156     }
157
158     // note editing
159     if($('#noteedit')){
160         var img;
161
162         img           = new Image();
163         img.src       = 'pix/note.png';
164         img.className = 'click ed';
165         $(img).click(function(){noteedit('note');});
166         $('#noteedit').append(img);
167
168         img           = new Image();
169         img.src       = 'pix/arrow_right.png';
170         img.className = 'click ed';
171         $(img).click(function(){noteedit('todo');});
172         $('#noteedit').append(img);
173
174         img           = new Image();
175         img.src       = 'pix/email.png';
176         img.className = 'click ed';
177         $(img).click(function(){noteedit('mail');});
178         $('#noteedit').append(img);
179
180         img           = new Image();
181         img.src       = 'pix/phone.png';
182         img.className = 'click ed';
183         $(img).click(function(){noteedit('call');});
184         $('#noteedit').append(img);
185     }
186
187
188     // set focus
189     if($('#searchfield')) $('#searchfield').focus();
190     if($('#firstfield')) $('#firstfield').focus();
191
192 });