source: extensions/GMaps/admin/gmaps_category_maps.tpl @ 7479

Last change on this file since 7479 was 7479, checked in by grum, 13 years ago

implement feature:1950

File size: 16.5 KB
Line 
1{known_script id="jquery.ui" src=$ROOT_URL|@cat:"themes/default/js/ui/packed/ui.core.packed.js"}
2{known_script id="jquery.ui.sortable" src=$ROOT_URL|@cat:"themes/default/js/ui/packed/ui.sortable.packed.js"}
3{known_script id="jquery.ui.dialog" src=$ROOT_URL|@cat:"themes/default/js/ui/packed/ui.dialog.packed.js"}
4{known_script id="gpc.ui.iconSelector" src=$ROOT_URL|@cat:"plugins/GrumPluginClasses/js/ui.iconSelector.packed.js"}
5{known_script id="gpc.ui.categorySelector" src=$ROOT_URL|@cat:"plugins/GrumPluginClasses/js/ui.categorySelector.packed.js"}
6{known_script id="maps.google.com/api" src="http://maps.google.com/maps/api/js?sensor=false"}
7
8{literal}
9
10<script type="text/javascript">
11
12
13  function assocManager ()
14  {
15    var properties = {
16      id:'',
17    }
18
19
20    /**
21     * initialize the page
22     */
23    this.init = function ()
24    {
25
26      $('#iDialogEdit')
27        .dialog(
28          {
29            autoOpen:false,
30            width:800,
31            height:510,
32            modal: true,
33            dialogClass: 'gcBgTabSheet gcBorder',
34            title: '{/literal}{"gmaps_manage_assoc"|@translate}{literal}',
35            open: function () {
36                $('#iBDAssocCatId').categorySelector('listMaxHeight', $('#iDialogEdit').height()-$('#iBDAssocCatId').position().top-$('#iBDAssocCatId').height());
37              },
38
39            buttons:
40              {
41                '{/literal}{"gmaps_ok"|@translate}{literal}':
42                  function()
43                  {
44                    if(checkValidity()) doUpdate();
45                  },
46                '{/literal}{"gmaps_cancel"|@translate}{literal}':
47                  function()
48                  {
49                    $('#iDialogEdit').dialog("close");
50                  }
51              }
52          }
53        );
54
55      $('#iBDAssocCatId').categorySelector(
56        {
57          listMaxWidth:600,
58          listMaxHeight:500,
59          displayStatus:true,
60          levelIndent:20,
61          userMode:'admin',
62          load: function (event) { $(this).categorySelector('expand', ':all+0'); }
63        }
64      );
65
66      $('#iBDAssocIcon').iconSelector(
67        {
68          images:[
69          {/literal}
70            {foreach from=$datas.icons item=icon name=list}
71              "plugins/GMaps/img/{$icon.file}"
72              {if !$smarty.foreach.list.last},{/if}
73            {/foreach}
74          {literal}
75          ],
76          cellWidth:42,
77          cellHeight:28
78        }
79      );
80
81      $('#iBDAssocMarker').iconSelector(
82        {
83          images:[
84          {/literal}
85            {foreach from=$datas.markers item=marker name=list}
86              "plugins/GMaps/img/{$marker.file}"
87              {if !$smarty.foreach.list.last},{/if}
88            {/foreach}
89          {literal}
90          ],
91          cellWidth:32,
92          cellHeight:40,
93          numCols:13,
94          numRows:4
95        }
96      );
97
98      $('#iBDAssocMapId').bind('change', changeMapDisplayType);
99      $('[name=fBDAssocKmlFile]').bind('change', changeKmlFileSource);
100
101      loadList();
102    }
103
104
105    /**
106     * called when the source of kml file changed
107     */
108    var changeKmlFileSource = function ()
109    {
110      switch($('[name=fBDAssocKmlFile]:checked').val())
111      {
112        case 'N':
113          $('#iBDAssocKmlFileId').css('display', 'none');
114          $('#iBDAssocKmlFileUrl').css('display', 'none');
115          $('#iBDKmlWarning').css('display', 'none');
116          $('#iBDAssocForceDisplayDiv').css('display', 'none');
117          break;
118        case 'S':
119          $('#iBDAssocKmlFileId').css('display', 'block');
120          $('#iBDAssocKmlFileUrl').css('display', 'none');
121          $('#iBDKmlWarning').css('display', 'block');
122          $('#iBDAssocForceDisplayDiv').css('display', 'block');
123          break;
124        case 'U':
125          $('#iBDAssocKmlFileId').css('display', 'none');
126          $('#iBDAssocKmlFileUrl').css('display', 'block');
127          $('#iBDKmlWarning').css('display', 'block');
128          $('#iBDAssocForceDisplayDiv').css('display', 'block');
129          break;
130      }
131    }
132
133    /**
134     * called when the map is changed
135     * refresh the icon list
136     */
137    var changeMapDisplayType = function ()
138    {
139      switch($('#iBDAssocMapId option:selected').attr('dtype'))
140      {
141        case 'IC':
142        case 'IP':
143          $('#iBDAssocIconRow').show();
144          break;
145        case 'MP':
146          $('#iBDAssocIconRow').hide();
147          break;
148      }
149    }
150
151
152    /**
153     * manage the tabsheet
154     *
155     * @param String tabsheet : id of the tabsheet to display
156     */
157    this.displayTab = function (tabsheet)
158    {
159      switch(tabsheet)
160      {
161        case 'integration':
162          $('#iTabIntegration').css('display', 'block');
163          $('#iTabAssoc').css('display', 'none');
164          break;
165        case 'assoc':
166          $('#iTabIntegration').css('display', 'none');
167          $('#iTabAssoc').css('display', 'block');
168          break;
169      }
170    }
171
172
173    /**
174     * open the dialog box to edit the association properties
175     *
176     * @param String id : if set to '' => open dialogbox in 'add' mode
177     *                    otherwise edit the given association
178     */
179    this.editAssoc = function (id)
180    {
181      properties.id=id;
182      updateDialog('');
183      this.displayTab('assoc');
184      // >> because li items don't have id... :-(
185      $('#itab2 li').removeClass('selected_tab').addClass('normal_tab');
186      $('#itab2 li:first').addClass('selected_tab');
187      // <<
188
189      $('#iDialogEdit')
190        .bind('dialogopen', function ()
191          {
192            if(properties.id!='')
193            {
194              displayProcessing(true);
195
196              $.ajax(
197                {
198                  type: "POST",
199                  url: "{/literal}{$datas.urlRequest}{literal}",
200                  async: true,
201                  data: { ajaxfct:"admin.assoc.getAssoc", id:properties.id },
202                  success:
203                    function(msg)
204                    {
205                      updateDialog(msg);
206                      displayProcessing(false);
207                    }
208                }
209              );
210            }
211          }
212        )
213        .dialog("open");
214    }
215
216    /**
217     * delete an association
218     *
219     * @param String id : id of the association to delete
220     */
221    this.deleteAssoc = function (id)
222    {
223      $('#iDialogDelete')
224        .html("<br>{/literal}{'gmaps_pleaseConfirmDeletingAssoc'|@translate}{literal}")
225        .dialog(
226          {
227            autoOpen:true,
228            modal: true,
229            dialogClass: 'gcBgTabSheet gcBorder',
230            title: '{/literal}{"gmaps_deleteAssoc"|@translate}{literal}',
231            buttons:
232              {
233                '{/literal}{"gmaps_delete"|@translate}{literal}':
234                  function()
235                  {
236                    $(this).html("<br><img src='./plugins/GrumPluginClasses/icons/processing.gif'>");
237                    $.ajax(
238                      {
239                        type: "POST",
240                        url: "{/literal}{$datas.urlRequest}{literal}",
241                        async: true,
242                        data: { ajaxfct:"admin.assoc.deleteAssoc", id:id },
243                        success:
244                          function(msg)
245                          {
246                            $('#iDialogDelete').dialog("destroy");
247                            loadList();
248                          }
249                      }
250                    );
251                  },
252                '{/literal}{"gmaps_cancel"|@translate}{literal}':
253                  function()
254                  {
255                    $('#iDialogDelete').dialog("destroy");
256                  }
257              }
258          }
259        );
260    }
261
262    /**
263     * update values of the dialog box
264     *
265     * @param String items : json string ; if empty assume to reset all fields
266     *                       with blank
267     */
268    var updateDialog = function (items)
269    {
270      if(items=='')
271      {
272        $('#iBDAssocCatId').categorySelector('value', ':first');
273        $('#iBDAssocMapId').val($('#iBDAssocMapId option:first').val());
274        $('#iBDAssocApplySubCat').val('y');
275        $('#iBDAssocKmlNone').attr('checked', true);
276        $('#iBDAssocKmlFileId').val($('#iBDAssocKmlFileId option:first').val());
277        $('#iBDAssocKmlFileUrl').val('');
278        $('#iBDAssocIcon, #iBDAssocMarker').iconSelector('value', ':first');
279        $('#iBDAssocTitle').val('');
280        $('#iBDAssocForceDisplay').attr('checked', false);
281      }
282      else
283      {
284        tmp=$.parseJSON(items);
285
286        $('#iBDAssocCatId').categorySelector('value', tmp.categoryId).categorySelector('expand', tmp.categoryId+'+');
287        $('#iBDAssocMapId').val(tmp.mapId);
288        $('#iBDAssocApplySubCat').val(tmp.applySubCat);
289        if(tmp.kmlFileId>0)
290        {
291          $('#iBDAssocKmlSelect').attr('checked', true);
292        }
293        else if(tmp.kmlFileUrl!='')
294        {
295          $('#iBDAssocKmlUrl').attr('checked', true);
296        }
297        else
298        {
299          $('#iBDAssocKmlNone').attr('checked', true);
300        }
301        $('#iBDAssocKmlFileId').val(tmp.kmlFileId);
302        $('#iBDAssocKmlFileUrl').val(tmp.kmlFileUrl);
303        $('#iBDAssocIcon').iconSelector('value', 'plugins/GMaps/img/'+tmp.icon);
304        $('#iBDAssocMarker').iconSelector('value', 'plugins/GMaps/img/'+tmp.marker);
305        $('#iBDAssocTitle').val(tmp.title);
306        $('#iBDAssocForceDisplay').attr('checked', tmp.forceDisplay=='y');
307      }
308
309      changeMapDisplayType();
310      changeKmlFileSource();
311    }
312
313    /**
314     * reload the assocation list
315     */
316    var loadList = function ()
317    {
318      $('#iListAssoc').html("<br>{/literal}{'gmaps_loading'|@translate}{literal}<br><img src='./plugins/GrumPluginClasses/icons/processing.gif'>");
319
320      $.ajax(
321        {
322          type: "POST",
323          url: "{/literal}{$datas.urlRequest}{literal}",
324          async: true,
325          data: { ajaxfct:"admin.assoc.getList" },
326          success:
327            function(msg)
328            {
329              $("#iListAssoc").html(msg);
330            }
331        }
332      );
333    }
334
335
336    /**
337     * check for the validity of the map settings
338     */
339    var checkValidity = function ()
340    {
341      $('.error').removeClass('error');
342      ok=true;
343/*
344      if(checkIdValidity($('#iBDMapId').val())==false)
345      {
346        $('#iBDMapId').addClass('error');
347        alert('{/literal}{"gmaps_invalidId"|@translate}{literal}');
348        ok=false;
349      }
350*/
351      return(ok);
352    }
353
354    /**
355     * send assoc update to the server, and close the dialog box if everything
356     * is ok
357     */
358    var doUpdate = function ()
359    {
360      displayProcessing(true);
361
362      // build datas
363      datas = {
364        categoryId:$('#iBDAssocCatId').categorySelector('value'),
365        mapId:$('#iBDAssocMapId').val(),
366        applySubCat:$('#iBDAssocApplySubCat').val(),
367        kmlFileId:($('#iBDAssocKmlSelect').attr('checked'))?$('#iBDAssocKmlFileId').val():0,
368        kmlFileUrl:($('#iBDAssocKmlSelect').attr('checked'))?'':$('#iBDAssocKmlFileUrl').val(),
369        icon:$('#iBDAssocIcon').iconSelector('value'),
370        marker:$('#iBDAssocMarker').iconSelector('value'),
371        title:$('#iBDAssocTitle').val(),
372        forceDisplay:$('#iBDAssocForceDisplay').attr('checked')?'y':'n',
373      }
374
375      $.ajax(
376        {
377          type: "POST",
378          url: "{/literal}{$datas.urlRequest}{literal}",
379          async: true,
380          data: { ajaxfct:"admin.assoc.setAssoc", id:properties.id, datas:datas },
381          success:
382            function(msg)
383            {
384              displayProcessing(false);
385
386              if(msg.match(/^[0-9]+$/i)!=null)
387              {
388                // result Ok ! => close the dialog box and reload the list
389                $('#iDialogEdit').dialog("close");
390                loadList();
391              }
392              else
393              {
394                returned=msg.split('!');
395                if(returned[0]!='') $('#'+returned[0]).addClass('error');
396                alert(returned[1]);
397              }
398            }
399        }
400      );
401    }
402
403    /**
404     * display or hide the processing flower
405     */
406    var displayProcessing = function (visible)
407    {
408      if(visible)
409      {
410        $('#iBDProcessing').css("display", "block");
411      }
412      else
413      {
414        $('#iBDProcessing').css("display", "none");
415      }
416    }
417
418    this.init();
419  }
420
421
422</script>
423
424{/literal}
425
426
427
428<h2>{'gmaps_associate_category_maps'|@translate}</h2>
429
430
431<div class='addMap'>
432  <a onclick="am.editAssoc('');">{'gmaps_add_a_new_association'|@translate}</a>
433</div>
434
435
436<table id='iHeaderListMaps' class="littlefont">
437  <tr>
438    <th>{'gmaps_category'|@translate}</th>
439    <th style="width:90px;">{'gmaps_apply_subcat'|@translate}</th>
440    <th style="width:150px;">{'gmaps_mapType'|@translate}</th>
441    <th style="width:350px;">{'gmaps_map'|@translate}</th>
442    <th style="width:220px;">{'gmaps_map_associate_kmlfile'|@translate}</th>
443    <th width="40px">&nbsp;</th>
444  </tr>
445</table>
446
447
448
449<div id='iListAssoc' class="{$themeconf.name}">
450</div>
451<div id="iListAssocNb"></div>
452
453<div id="iDialogDelete">
454</div>
455
456<div id="iDialogEdit">
457  <div id='iBDProcessing' style="display:none;position:absolute;width:100%;height:100%;background:#000000;opacity:0.75">
458      <img src="plugins/GrumPluginClasses/icons/processing.gif" style="margin-top:100px;">
459  </div>
460
461  {$mapTabsheet}
462  <form>
463
464    <div id='iTabsContainer' style='height:100px;'>
465
466
467      <div id='iTabAssoc' style='display:none;'>
468        <table class="formtable">
469          <tr>
470            <td>{'gmaps_map'|@translate}</td>
471            <td>
472              <select id='iBDAssocMapId'>
473                  {foreach from=$datas.maps key=group item=mapGroup}
474                    <optgroup label="{'gmaps_displayTypeShort'|cat:$group|@translate}">
475                    {foreach from=$mapGroup item=map}
476                      <option value='{$map.id}' dtype='{$group}'>{$map.name}</option>
477                    {/foreach}
478                    </optgroup>
479                  {/foreach}
480              </select>
481            </td>
482          </tr>
483
484          <tr>
485            <td>{'gmaps_category'|@translate}</td>
486            <td>
487              <div id='iBDAssocCatId'></div>
488            </td>
489          </tr>
490
491          <tr>
492            <td>{'gmaps_apply_subcat'|@translate}</td>
493            <td>
494              <select id='iBDAssocApplySubCat'>
495                <option value='y'>{'gmaps_y'|@translate}</option>
496                <option value='n'>{'gmaps_n'|@translate}</option>
497              </select>
498            </td>
499          </tr>
500
501        </table>
502      </div>
503
504
505      <div id='iTabIntegration' style='display:none;'>
506        <table class='formtable'>
507
508          <tr id='iBDAssocTitleRow'>
509            <td>{'gmaps_map_title'|@translate}</td>
510            <td>
511              <input type="text" id='iBDAssocTitle' value='{$datas.title}' maxlength='200' size='55'>
512            </td>
513          </tr>
514
515          <tr id='iBDAssocIconRow'>
516            <td>{'gmaps_map_icon'|@translate}</td>
517            <td>
518              <div id='iBDAssocIcon'></div>
519              <p id='iBDKmlIconWarning' class='helps' style="width:520px;padding-right:20px;">{'gmaps_icon_info'|@translate}</p>
520            </td>
521          </tr>
522
523
524          <tr>
525            <td>{'gmaps_map_marker'|@translate}</td>
526            <td>
527              <div id='iBDAssocMarker'></div>
528            </td>
529          </tr>
530
531
532          <tr>
533            <td>{'gmaps_map_associate_kmlfile'|@translate}</td>
534            <td>
535              <label><input type="radio" id='iBDAssocKmlNone' name="fBDAssocKmlFile" value="N">&nbsp;{'gmaps_kml_file_none'|@translate}</label><br>
536              <label><input type="radio" id='iBDAssocKmlSelect' name="fBDAssocKmlFile" value="S">&nbsp;{'gmaps_kml_file_selected'|@translate}</label><br>
537              <select style="margin-left:20px;margin-bottom:10px;"  id="iBDAssocKmlFileId">
538                {foreach from=$datas.kmlFiles item=file}
539                  <option value='{$file.id}'>{$file.name}</option>
540                {/foreach}
541              </select>
542
543              <label><input type="radio" id='iBDAssocKmlUrl' name="fBDAssocKmlFile" value="U">&nbsp;{'gmaps_kml_file_url'|@translate}</label><br>
544              <input style="margin-left:20px;" type="text" id="iBDAssocKmlFileUrl" maxlength='255' size='55' value=""><br>
545              <p id='iBDKmlWarning' class='helps' style="width:520px;padding-right:20px;">{'gmaps_kml_file_access'|@translate}</p>
546
547              <div id='iBDAssocForceDisplayDiv' style='display:none;'><label><input type="checkbox" id='iBDAssocForceDisplay'>&nbsp;{'gmaps_force_display'|@translate}</label></div>
548
549            </td>
550          </tr>
551
552
553        </table>
554      </div>
555
556    </div>
557
558  </form>
559</div>
560
561
562
563
564
565{literal}
566<script type="text/javascript">
567  var am=new assocManager();
568</script>
569{/literal}
570
Note: See TracBrowser for help on using the repository browser.