source: extensions/GMaps/admin/gmaps_kmlfiles.tpl @ 31844

Last change on this file since 31844 was 16011, checked in by grum, 12 years ago

feature:2638- compatibility with Piwigo 2.4

  • Property svn:executable set to *
File size: 9.9 KB
Line 
1{combine_script id="jquery.ui" require='jquery' path="themes/default/js/ui/jquery.ui.core.js"}
2{combine_script id="jquery.ui.widget" require='jquery.ui' path="themes/default/js/ui/jquery.ui.widget.js"}
3{combine_script id="jquery.ui.mouse" require='jquery.ui.widget' path="themes/default/js/ui/jquery.ui.mouse.js"}
4{combine_script id="jquery.ui.position" require='jquery.ui.widget' path="themes/default/js/ui/jquery.ui.position.js"}
5{combine_script id="jquery.ui.sortable" require='jquery.ui.widget' path="themes/default/js/ui/jquery.ui.sortable.js"}
6{combine_script id="jquery.ui.dialog" require='jquery.ui.widget' src="themes/default/js/ui/jquery.ui.dialog.js"}
7{combine_script id="jquery.ui.slider" require='jquery.ui.widget' src="themes/default/js/ui/jquery.ui.slider.js"}
8
9{literal}
10
11<script type="text/javascript">
12
13
14  function kmlFileManager ()
15  {
16    var properties = {
17      id:'',
18    }
19
20
21    /**
22     * initialize the page
23     */
24    this.init = function ()
25    {
26
27      $('#iDialogEdit')
28        .dialog(
29          {
30            autoOpen:false,
31            width:800,
32            height:150,
33            modal: true,
34            dialogClass: 'gcBgTabSheet gcBorder',
35            title: '{/literal}{"gmaps_kml_file_management"|@translate}{literal}',
36            buttons:
37              {
38                '{/literal}{"gmaps_ok"|@translate}{literal}':
39                  function()
40                  {
41                    if(checkValidity()) doUpdate();
42                  },
43                '{/literal}{"gmaps_cancel"|@translate}{literal}':
44                  function()
45                  {
46                    $('#iDialogEdit').dialog("close");
47                  }
48              }
49          }
50        );
51
52      loadList();
53    }
54
55
56    /**
57     * open the dialog box to edit the kml file properties
58     *
59     * @param String id : if set to '' => open dialogbox in 'add' mode
60     *                    otherwise edit the given kml file
61     */
62    this.editKmlFile = function (id)
63    {
64      properties.id=id;
65      updateDialog('');
66
67      $('#iErrorMsg').css('display', 'none');
68
69      $('#iDialogEdit')
70        .bind('dialogopen', function ()
71          {
72            if(properties.id!='')
73            {
74              displayProcessing(true);
75
76              $.ajax(
77                {
78                  type: "POST",
79                  url: "{/literal}{$datas.urlRequest}{literal}",
80                  async: true,
81                  data: { ajaxfct:"admin.kmlFiles.getFile", token:'{/literal}{$token}{literal}', id:properties.id },
82                  success:
83                    function(msg)
84                    {
85                      updateDialog(msg);
86                      displayProcessing(false);
87                    }
88                }
89              );
90            }
91          }
92        )
93        .dialog("open");
94    }
95
96    /**
97     * delete a kml file
98     *
99     * @param String id : id of the kml file to delete
100     */
101    this.deleteKmlFile = function (id)
102    {
103      $('#iErrorMsg').css('display', 'none');
104
105      $('#iDialogDelete')
106        .html('<br>{/literal}{"gmaps_pleaseConfirmKml_1"|@translate}<br><br>{"gmaps_pleaseConfirmKml_2"|@translate}{literal}')
107        .dialog(
108          {
109            autoOpen:true,
110            modal: true,
111            dialogClass: 'gcBgTabSheet gcBorder',
112            title: '{/literal}{"gmaps_deleteKml"|@translate}{literal}',
113            buttons:
114              {
115                '{/literal}{"gmaps_delete"|@translate}{literal}':
116                  function()
117                  {
118                    $(this).html("<br><img src='./plugins/GrumPluginClasses/icons/processing.gif'>");
119                    $.ajax(
120                      {
121                        type: "POST",
122                        url: "{/literal}{$datas.urlRequest}{literal}",
123                        async: true,
124                        data: { ajaxfct:"admin.kmlFiles.deleteFile", token:'{/literal}{$token}{literal}', id:id },
125                        success:
126                          function(msg)
127                          {
128                            $('#iDialogDelete').dialog("destroy");
129                            loadList();
130                          }
131                      }
132                    );
133                  },
134                '{/literal}{"gmaps_cancel"|@translate}{literal}':
135                  function()
136                  {
137                    $('#iDialogDelete').dialog("destroy");
138                  }
139              }
140          }
141        );
142    }
143
144    /**
145     * update values of the dialog box
146     *
147     * @param String items : json string ; if empty assume to reset all fields
148     *                       with blank
149     */
150    var updateDialog = function (items)
151    {
152      if(items=='')
153      {
154        $('#iBDKmlId').val('');
155        $('#iBDKmlName').val('');
156        $('#iBDKmlCurrentFile').html('').css('display', 'none');
157      }
158      else
159      {
160        tmp=$.parseJSON(items);
161
162        $('#iBDKmlId').val(tmp.id);
163        $('#iBDKmlName').val(tmp.name);
164        $('#iBDKmlCurrentFile').html(tmp.file+' ('+tmp.fileSizeUnits+', '+tmp.fileDate+')').css('display', 'block');
165
166        properties.id=tmp.id;
167      }
168      $('#iBDKmlFile').val('');
169    }
170
171    /**
172     * reload the assocation list
173     */
174    var loadList = function ()
175    {
176      $('#iListKml').html("<br>{/literal}{'gmaps_loading'|@translate}{literal}<br><img src='./plugins/GrumPluginClasses/icons/processing.gif'>");
177
178      $.ajax(
179        {
180          type: "POST",
181          url: "{/literal}{$datas.urlRequest}{literal}",
182          async: true,
183          data: { ajaxfct:"admin.kmlFiles.getList", token:'{/literal}{$token}{literal}' },
184          success:
185            function(msg)
186            {
187              $("#iListKml").html(msg);
188            }
189        }
190      );
191    }
192
193
194    /**
195     * check for the validity of the map settings
196     */
197    var checkValidity = function ()
198    {
199      $('.error').removeClass('error');
200      ok=true;
201
202      if($('#iBDKmlId').val()=='' && $('#iBDKmlFile').val()=='')
203      {
204        $('#iBDKmlFile').addClass('error');
205        alert('{/literal}{"gmaps_file_required"|@translate}{literal}');
206        ok=false;
207      }
208
209      re=/.*(\.kml|\.kmz)$/i;
210      if($('#iBDKmlFile').val()!='' && re.exec($('#iBDKmlFile').val())==null)
211      {
212        $('#iBDKmlFile').addClass('error');
213        alert('{/literal}{"gmaps_file_is_not_kml_kmz"|@translate}{literal}');
214        ok=false;
215      }
216
217      return(ok);
218    }
219
220    /**
221     * send assoc update to the server, and close the dialog box if everything
222     * is ok
223     */
224    var doUpdate = function ()
225    {
226      displayProcessing(true);
227
228      if($('#iBDKmlFile').val()!='')
229      {
230        /*
231         * because it's not possible to upload file through ajax, using the
232         * standard FORM method
233         */
234
235        $('#iBDKmlForm').get(0).submit();
236      }
237      else
238      {
239        // there is only the name to change, use an ajax call
240        $.ajax(
241          {
242            type: "POST",
243            url: "{/literal}{$datas.urlRequest}{literal}",
244            async: true,
245            data: { ajaxfct:"admin.kmlFiles.setFile", token:'{/literal}{$token}{literal}', id:properties.id, name:$('#iBDKmlName').val() },
246            success:
247              function(msg)
248              {
249                displayProcessing(false);
250
251                if(msg.match(/^[0-9]+$/i)!=null)
252                {
253                  // result Ok ! => close the dialog box and reload the list
254                  $('#iDialogEdit').dialog("close");
255                  loadList();
256                }
257                else
258                {
259                  returned=msg.split('!');
260                  if(returned[0]!='') $('#'+returned[0]).addClass('error');
261                  alert(returned[1]);
262                }
263              }
264          }
265        );
266      }
267
268    }
269
270    /**
271     * display or hide the processing flower
272     */
273    var displayProcessing = function (visible)
274    {
275      if(visible)
276      {
277        $('#iBDProcessing').css("display", "block");
278      }
279      else
280      {
281        $('#iBDProcessing').css("display", "none");
282      }
283    }
284
285    this.init();
286  }
287
288
289</script>
290
291{/literal}
292
293
294
295<h2>{'gmaps_kml_files_management'|@translate}</h2>
296
297
298<div class='addMap'>
299  <a onclick="km.editKmlFile('');">{'gmaps_add_a_new_kmlFile'|@translate}</a>
300</div>
301
302
303<table id='iHeaderListMaps' class="littlefont">
304  <tr>
305    <th>{'gmaps_name'|@translate}</th>
306    <th style="width:300px;">{'gmaps_file'|@translate}</th>
307    <th style="width:180px;">{'gmaps_date'|@translate}</th>
308    <th style="width:90px;">{'gmaps_file_size'|@translate}</th>
309    <th style="width:90px;">{'gmaps_nb_assoc'|@translate}</th>
310    <th width="40px">&nbsp;</th>
311
312  </tr>
313</table>
314
315
316
317<div id='iListKml' class="{$themeconf.name}">
318</div>
319<div id="iListKmlNb"></div>
320
321<div id="iDialogDelete">
322</div>
323
324<div id="iDialogEdit">
325  <div id='iBDProcessing' style="display:none;position:absolute;width:100%;height:100%;background:#000000;opacity:0.75">
326      <img src="plugins/GrumPluginClasses/icons/processing.gif" style="margin-top:100px;">
327  </div>
328
329  <form id='iBDKmlForm' action="{$datas.urlRequest}" method="POST" enctype="multipart/form-data">
330
331    <table class="formtable">
332      <tr>
333        <td>{'gmaps_name'|@translate}</td>
334        <td>
335          <input type='hidden' id='iToken' name ="token" value='{$token}'>
336          <input type='hidden' id='iBDKmlId' name ="id" value=''>
337          <input type='hidden' id='iBDKmlAjaxFct' name="ajaxfct" value='admin.kmlFiles.setFile'>
338          <input type='text' id='iBDKmlName' name='name' value='' maxlength=255 size=60>
339        </td>
340      </tr>
341
342      <tr id='iBDKmlFileInputRow'>
343        <td>{'gmaps_file'|@translate}</td>
344        <td>
345          <div id='iBDKmlCurrentFile' name='iBDKmlCurrentFile' class='gcBorderInput gcBgInput gcTextInput' style='display:block;margin-bottom:2px;padding:2px;'></div>
346          <input type='file' size=60 id='iBDKmlFile' name="file" value='' accept='kml'>
347        </td>
348      </tr>
349
350    </table>
351
352  </form>
353</div>
354
355
356
357
358
359{literal}
360<script type="text/javascript">
361  var km=new kmlFileManager();
362</script>
363{/literal}
364
Note: See TracBrowser for help on using the repository browser.