]> git.sur5r.net Git - contagged/blob - scripts/gui.js
Use leafletjs + OpenStreetMap instead of google maps
[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  * Initialize everything when DOM is ready
106  */
107 $(document).ready(function() {
108
109     // autocompletion
110     $('#taglookup').Autocomplete({
111         source: 'ajax.php',
112         delay: 300,
113         helperClass: 'autocompleter',
114         selectClass: 'autocompleterSelect',
115         inputWidth: true,
116         minchars: 1
117         //multiple: true,
118         //multipleSeperator: ','
119     });
120     $('#tageditlookup').Autocomplete({
121         source: 'ajax.php',
122         delay: 300,
123         helperClass: 'autocompleter',
124         selectClass: 'autocompleterSelect',
125         inputWidth: true,
126         minchars: 1,
127         multiple: true,
128         multipleSeperator: ','
129     });
130     // autocompletion
131     $('input.ac').Autocomplete({
132         source: 'ajax.php',
133         delay: 300,
134         helperClass: 'autocompleter',
135         selectClass: 'autocompleterSelect',
136         inputWidth: true,
137         minchars: 1
138     });
139
140     // nice images
141     $.ImageBox.init({
142         loaderSRC: 'pix/imagebox/loading.gif',
143         closeHTML: '<img src="pix/imagebox/close.jpg" border="0" />'
144     });
145
146     // tag editing
147     if($('#tagedit').length){
148         var img       = new Image();
149         img.src       = 'pix/tag_blue_edit.png';
150         img.className = 'click';
151         img.id        = 'tagedit_start';
152         $('#tagedit').empty().after(img);
153         $(img).click(tagedit);
154     }
155
156     // note editing
157     if($('#noteedit').length){
158         var img;
159
160         img           = new Image();
161         img.src       = 'pix/note.png';
162         img.className = 'click ed';
163         $(img).click(function(){noteedit('note');});
164         $('#noteedit').append(img);
165
166         img           = new Image();
167         img.src       = 'pix/arrow_right.png';
168         img.className = 'click ed';
169         $(img).click(function(){noteedit('todo');});
170         $('#noteedit').append(img);
171
172         img           = new Image();
173         img.src       = 'pix/email.png';
174         img.className = 'click ed';
175         $(img).click(function(){noteedit('mail');});
176         $('#noteedit').append(img);
177
178         img           = new Image();
179         img.src       = 'pix/phone.png';
180         img.className = 'click ed';
181         $(img).click(function(){noteedit('call');});
182         $('#noteedit').append(img);
183     }
184
185
186     // set focus
187     if($('#searchfield').length) $('#searchfield').focus();
188     if($('#firstfield').length) $('#firstfield').focus();
189 });