~ubuntu-branches/ubuntu/saucy/phpmyadmin/saucy-proposed

« back to all changes in this revision

Viewing changes to js/gis_data_editor.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-08-04 13:24:37 UTC
  • mfrom: (1.2.44)
  • Revision ID: package-import@ubuntu.com-20130804132437-jznw8efwy4hr1nms
Tags: 4:4.0.5-1
* New upstream release.
  - Fixes security issue PMASA-2013-10.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
var gisEditorLoaded=false;function closeGISEditor(){$("#popup_background").fadeOut("fast");$("#gis_editor").fadeOut("fast",function(){$(this).empty()})}function prepareJSVersion(){$("#gis_editor input[name='gis_data[save]']").val(PMA_messages.strCopy).insertAfter($("#gis_data_textarea")).before("<br/><br/>");$("#gis_data_editor").prepend('<a class="close_gis_editor" href="#">'+PMA_messages.strClose+"</a>");$('<a class="cancel_gis_editor" href="#"> '+PMA_messages.strCancel+"</a>").insertAfter($("input[name='gis_data[save]']"));$("div#gis_data_output p").remove();$("#gis_editor input.add").each(function(c){var b=$(this);b.addClass("addJs").removeClass("add");var a=b.attr("class");b.replaceWith('<a class="'+a+'" name="'+b.attr("name")+'" href="#">+ '+b.val()+"</a>")})}function addDataPoint(a,b){return"<br/>"+$.sprintf(PMA_messages.strPointN,(a+1))+': <label for="x">'+PMA_messages.strX+'</label><input type="text" name="'+b+"["+a+'][x]" value=""/><label for="y">'+PMA_messages.strY+'</label><input type="text" name="'+b+"["+a+'][y]" value=""/>'}function initGISEditorVisualization(){selectVisualization();styleOSM();loadSVG();addZoomPanControllers();zoomAndPan()}function loadJSAndGISEditor(j,h,e,c,a){var f=document.getElementsByTagName("head")[0];var g;var d=["js/jquery/jquery.svg.js","js/jquery/jquery.mousewheel.js","js/jquery/jquery.event.drag-2.0.js","js/tbl_gis_visualization.js"];for(var b=0;b<d.length;b++){g=document.createElement("script");g.type="text/javascript";g.src=d[b];f.appendChild(g)}g=document.createElement("script");g.type="text/javascript";g.onreadystatechange=function(){if(this.readyState=="complete"){loadGISEditor(j,h,e,c,a)}};g.onload=function(){loadGISEditor(j,h,e,c,a)};g.src="js/openlayers/OpenLayers.js";f.appendChild(g);gisEditorLoaded=true}function loadGISEditor(d,e,c,f,b){var a=$("#gis_editor");$.post("gis_data_editor.php",{field:e,value:d,type:c,input_name:f,get_gis_editor:true,token:b,ajax_request:true},function(g){if(g.success==true){a.html(g.gis_editor);initGISEditorVisualization();prepareJSVersion()}else{PMA_ajaxShowMessage(g.error,false)}},"json")}function openGISEditor(){var d=document.documentElement.clientWidth;var h=document.documentElement.clientHeight;var e=d*0.9;var g=h*0.9;var c=h/2-g/2;var b=d/2-e/2;var a=$("#gis_editor");var f=$("#popup_background");a.css({top:c,left:b,width:e,height:g});f.css({opacity:"0.7"});a.append('<div id="gis_data_editor"><img class="ajaxIcon" id="loadingMonitorIcon" src="'+pmaThemeImage+'ajax_clock_small.gif" alt=""/></div>');f.fadeIn("fast");a.fadeIn("fast")}function insertDataAndClose(){var a=$("form#gis_data_editor_form");var b=a.find("input[name='input_name']").val();$.post("gis_data_editor.php",a.serialize()+"&generate=true&ajax_request=true",function(c){if(c.success==true){$("input[name='"+b+"']").val(c.result)}else{PMA_ajaxShowMessage(c.error,false)}},"json");closeGISEditor()}AJAX.registerTeardown("gis_data_editor.js",function(){$("#gis_editor input[name='gis_data[save]']").die("click");$("#gis_editor").die("submit");$("#gis_editor").find("input[type='text']").die("change");$("#gis_editor select.gis_type").die("change");$("#gis_editor a.close_gis_editor, #gis_editor a.cancel_gis_editor").die("click");$("#gis_editor a.addJs.addPoint").die("click");$("#gis_editor a.addLine.addJs").die("click");$("#gis_editor a.addJs.addPolygon").die("click");$("#gis_editor a.addJs.addGeom").die("click")});AJAX.registerOnload("gis_data_editor.js",function(){$("span.open_gis_editor a").removeClass("formLinkSubmit");$("#gis_editor input[name='gis_data[save]']").live("click",function(event){event.preventDefault();insertDataAndClose()});$("#gis_editor").live("submit",function(event){event.preventDefault();insertDataAndClose()});$("#gis_editor").find("input[type='text']").live("change",function(){var $form=$("form#gis_data_editor_form");$.post("gis_data_editor.php",$form.serialize()+"&generate=true&ajax_request=true",function(data){if(data.success==true){$("#gis_data_textarea").val(data.result);$("#placeholder").empty().removeClass("hasSVG").html(data.visualization);$("#openlayersmap").empty();eval(data.openLayers);initGISEditorVisualization()}else{PMA_ajaxShowMessage(data.error,false)}},"json")});$("#gis_editor select.gis_type").live("change",function(event){var $gis_editor=$("#gis_editor");var $form=$("form#gis_data_editor_form");$.post("gis_data_editor.php",$form.serialize()+"&get_gis_editor=true&ajax_request=true",function(data){if(data.success==true){$gis_editor.html(data.gis_editor);initGISEditorVisualization();prepareJSVersion()}else{PMA_ajaxShowMessage(data.error,false)}},"json")});$("#gis_editor a.close_gis_editor, #gis_editor a.cancel_gis_editor").live("click",function(){closeGISEditor()});$("#gis_editor a.addJs.addPoint").live("click",function(){var $a=$(this);var name=$a.attr("name");var prefix=name.substr(0,name.length-11);var $noOfPointsInput=$("input[name='"+prefix+"[no_of_points]']");var noOfPoints=parseInt($noOfPointsInput.val());var html=addDataPoint(noOfPoints,prefix);$a.before(html);$noOfPointsInput.val(noOfPoints+1)});$("#gis_editor a.addLine.addJs").live("click",function(){var $a=$(this);var name=$a.attr("name");var prefix=name.substr(0,name.length-10);var type=prefix.slice(prefix.lastIndexOf("[")+1,prefix.lastIndexOf("]"));var $noOfLinesInput=$("input[name='"+prefix+"[no_of_lines]']");var noOfLines=parseInt($noOfLinesInput.val());var html="<br/>";if(type=="MULTILINESTRING"){html+=PMA_messages.strLineString+" "+(noOfLines+1)+":";var noOfPoints=2}else{html+=PMA_messages.strInnerRing+" "+noOfLines+":";var noOfPoints=4}html+='<input type="hidden" name="'+prefix+"["+noOfLines+'][no_of_points]" value="'+noOfPoints+'"/>';for(var i=0;i<noOfPoints;i++){html+=addDataPoint(i,(prefix+"["+noOfLines+"]"))}html+='<a class="addPoint addJs" name="'+prefix+"["+noOfLines+'][add_point]" href="#">+ '+PMA_messages.strAddPoint+"</a><br/>";$a.before(html);$noOfLinesInput.val(noOfLines+1)});$("#gis_editor a.addJs.addPolygon").live("click",function(){var $a=$(this);var name=$a.attr("name");var prefix=name.substr(0,name.length-13);var $noOfPolygonsInput=$("input[name='"+prefix+"[no_of_polygons]']");var noOfPolygons=parseInt($noOfPolygonsInput.val());var html=PMA_messages.strPolygon+" "+(noOfPolygons+1)+":<br/>";html+='<input type="hidden" name="'+prefix+"["+noOfPolygons+'][no_of_lines]" value="1"/><br/>'+PMA_messages.strOuterRing+':<input type="hidden" name="'+prefix+"["+noOfPolygons+'][0][no_of_points]" value="4"/>';for(var i=0;i<4;i++){html+=addDataPoint(i,(prefix+"["+noOfPolygons+"][0]"))}html+='<a class="addPoint addJs" name="'+prefix+"["+noOfPolygons+'][0][add_point]" href="#">+ '+PMA_messages.strAddPoint+'</a><br/><a class="addLine addJs" name="'+prefix+"["+noOfPolygons+'][add_line]" href="#">+ '+PMA_messages.strAddInnerRing+"</a><br/><br/>";$a.before(html);$noOfPolygonsInput.val(noOfPolygons+1)});$("#gis_editor a.addJs.addGeom").live("click",function(){var $a=$(this);var prefix="gis_data[GEOMETRYCOLLECTION]";var $noOfGeomsInput=$("input[name='"+prefix+"[geom_count]']");var noOfGeoms=parseInt($noOfGeomsInput.val());var html1=PMA_messages.strGeometry+" "+(noOfGeoms+1)+":<br/>";var $geomType=$("select[name='gis_data["+(noOfGeoms-1)+"][gis_type]']").clone();$geomType.attr("name","gis_data["+noOfGeoms+"][gis_type]").val("POINT");var html2="<br/>"+PMA_messages.strPoint+' :<label for="x"> '+PMA_messages.strX+' </label><input type="text" name="gis_data['+noOfGeoms+'][POINT][x]" value=""/><label for="y"> '+PMA_messages.strY+' </label><input type="text" name="gis_data['+noOfGeoms+'][POINT][y]" value=""/><br/><br/>';$a.before(html1);$geomType.insertBefore($a);$a.before(html2);$noOfGeomsInput.val(noOfGeoms+1)})});
 
 
b'\\ No newline at end of file'
 
1
/* vim: set expandtab sw=4 ts=4 sts=4: */
 
2
/**
 
3
 * @fileoverview    functions used in GIS data editor
 
4
 *
 
5
 * @requires    jQuery
 
6
 *
 
7
 */
 
8
 
 
9
var gisEditorLoaded = false;
 
10
 
 
11
/**
 
12
 * Closes the GIS data editor and perform necessary clean up work.
 
13
 */
 
14
function closeGISEditor(){
 
15
    $("#popup_background").fadeOut("fast");
 
16
    $("#gis_editor").fadeOut("fast", function () {
 
17
        $(this).empty();
 
18
    });
 
19
}
 
20
 
 
21
/**
 
22
 * Prepares the HTML recieved via AJAX.
 
23
 */
 
24
function prepareJSVersion() {
 
25
    // Change the text on the submit button
 
26
    $("#gis_editor input[name='gis_data[save]']")
 
27
        .val(PMA_messages['strCopy'])
 
28
        .insertAfter($('#gis_data_textarea'))
 
29
        .before('<br/><br/>');
 
30
 
 
31
    // Add close and cancel links
 
32
    $('#gis_data_editor').prepend('<a class="close_gis_editor" href="#">' + PMA_messages['strClose'] + '</a>');
 
33
    $('<a class="cancel_gis_editor" href="#"> ' + PMA_messages['strCancel'] + '</a>')
 
34
        .insertAfter($("input[name='gis_data[save]']"));
 
35
 
 
36
    // Remove the unnecessary text
 
37
    $('div#gis_data_output p').remove();
 
38
 
 
39
    // Remove 'add' buttons and add links
 
40
    $('#gis_editor input.add').each(function(e) {
 
41
        var $button = $(this);
 
42
        $button.addClass('addJs').removeClass('add');
 
43
        var classes = $button.attr('class');
 
44
        $button.replaceWith(
 
45
            '<a class="' + classes + '" name="' + $button.attr('name')
 
46
                + '" href="#">+ ' + $button.val() + '</a>'
 
47
        );
 
48
    });
 
49
}
 
50
 
 
51
/**
 
52
 * Returns the HTML for a data point.
 
53
 *
 
54
 * @param pointNumber point number
 
55
 * @param prefix      prefix of the name
 
56
 * @returns the HTML for a data point
 
57
 */
 
58
function addDataPoint(pointNumber, prefix) {
 
59
    return '<br/>' + $.sprintf(PMA_messages['strPointN'], (pointNumber + 1)) + ': '
 
60
        + '<label for="x">' + PMA_messages['strX'] + '</label>'
 
61
        + '<input type="text" name="' + prefix + '[' + pointNumber + '][x]" value=""/>'
 
62
        + '<label for="y">' + PMA_messages['strY'] + '</label>'
 
63
        + '<input type="text" name="' + prefix + '[' + pointNumber + '][y]" value=""/>';
 
64
}
 
65
 
 
66
/**
 
67
 * Initialize the visualization in the GIS data editor.
 
68
 */
 
69
function initGISEditorVisualization() {
 
70
    // Loads either SVG or OSM visualization based on the choice
 
71
    selectVisualization();
 
72
    // Adds necessary styles to the div that coontains the openStreetMap
 
73
    styleOSM();
 
74
    // Loads the SVG element and make a reference to it
 
75
    loadSVG();
 
76
    // Adds controllers for zooming and panning
 
77
    addZoomPanControllers();
 
78
    zoomAndPan();
 
79
}
 
80
 
 
81
/**
 
82
 * Loads JavaScript files and the GIS editor.
 
83
 *
 
84
 * @param value      current value of the geometry field
 
85
 * @param field      field name
 
86
 * @param type       geometry type
 
87
 * @param input_name name of the input field
 
88
 * @param token      token
 
89
 */
 
90
function loadJSAndGISEditor(value, field, type, input_name, token) {
 
91
    var head = document.getElementsByTagName('head')[0];
 
92
    var script;
 
93
 
 
94
    // Loads a set of small JS file needed for the GIS editor
 
95
    var smallScripts = [ 'js/jquery/jquery.svg.js',
 
96
                     'js/jquery/jquery.mousewheel.js',
 
97
                     'js/jquery/jquery.event.drag-2.0.js',
 
98
                     'js/tbl_gis_visualization.js' ];
 
99
 
 
100
    for (var i = 0; i < smallScripts.length; i++) {
 
101
        script = document.createElement('script');
 
102
        script.type = 'text/javascript';
 
103
        script.src = smallScripts[i];
 
104
        head.appendChild(script);
 
105
    }
 
106
 
 
107
    // OpenLayers.js is BIG and takes time. So asynchronous loading would not work.
 
108
    // Load the JS and do a callback to load the content for the GIS Editor.
 
109
    script = document.createElement('script');
 
110
    script.type = 'text/javascript';
 
111
 
 
112
    script.onreadystatechange = function() {
 
113
        if (this.readyState == 'complete') {
 
114
            loadGISEditor(value, field, type, input_name, token);
 
115
        }
 
116
    };
 
117
    script.onload = function() {
 
118
        loadGISEditor(value, field, type, input_name, token);
 
119
    };
 
120
 
 
121
    script.src = 'js/openlayers/OpenLayers.js';
 
122
    head.appendChild(script);
 
123
 
 
124
    gisEditorLoaded = true;
 
125
}
 
126
 
 
127
/**
 
128
 * Loads the GIS editor via AJAX
 
129
 *
 
130
 * @param value      current value of the geometry field
 
131
 * @param field      field name
 
132
 * @param type       geometry type
 
133
 * @param input_name name of the input field
 
134
 * @param token      token
 
135
 */
 
136
function loadGISEditor(value, field, type, input_name, token) {
 
137
 
 
138
    var $gis_editor = $("#gis_editor");
 
139
    $.post('gis_data_editor.php', {
 
140
        'field' : field,
 
141
        'value' : value,
 
142
        'type' : type,
 
143
        'input_name' : input_name,
 
144
        'get_gis_editor' : true,
 
145
        'token' : token,
 
146
        'ajax_request': true
 
147
    }, function(data) {
 
148
        if (data.success == true) {
 
149
            $gis_editor.html(data.gis_editor);
 
150
            initGISEditorVisualization();
 
151
            prepareJSVersion();
 
152
        } else {
 
153
            PMA_ajaxShowMessage(data.error, false);
 
154
        }
 
155
    }, 'json');
 
156
}
 
157
 
 
158
/**
 
159
 * Opens up the dialog for the GIS data editor.
 
160
 */
 
161
function openGISEditor() {
 
162
 
 
163
    // Center the popup
 
164
    var windowWidth = document.documentElement.clientWidth;
 
165
    var windowHeight = document.documentElement.clientHeight;
 
166
    var popupWidth = windowWidth * 0.9;
 
167
    var popupHeight = windowHeight * 0.9;
 
168
    var popupOffsetTop = windowHeight / 2 - popupHeight / 2;
 
169
    var popupOffsetLeft = windowWidth / 2 - popupWidth / 2;
 
170
 
 
171
    var $gis_editor = $("#gis_editor");
 
172
    var $backgrouond = $("#popup_background");
 
173
 
 
174
    $gis_editor.css({"top": popupOffsetTop, "left": popupOffsetLeft, "width": popupWidth, "height": popupHeight});
 
175
    $backgrouond.css({"opacity":"0.7"});
 
176
 
 
177
    $gis_editor.append('<div id="gis_data_editor"><img class="ajaxIcon" id="loadingMonitorIcon" src="'
 
178
            + pmaThemeImage + 'ajax_clock_small.gif" alt=""/></div>'
 
179
    );
 
180
 
 
181
    // Make it appear
 
182
    $backgrouond.fadeIn("fast");
 
183
    $gis_editor.fadeIn("fast");
 
184
}
 
185
 
 
186
/**
 
187
 * Prepare and insert the GIS data in Well Known Text format
 
188
 * to the input field.
 
189
 */
 
190
function insertDataAndClose() {
 
191
    var $form = $('form#gis_data_editor_form');
 
192
    var input_name = $form.find("input[name='input_name']").val();
 
193
 
 
194
    $.post('gis_data_editor.php', $form.serialize() + "&generate=true&ajax_request=true", function(data) {
 
195
        if (data.success == true) {
 
196
            $("input[name='" + input_name + "']").val(data.result);
 
197
        } else {
 
198
            PMA_ajaxShowMessage(data.error, false);
 
199
        }
 
200
    }, 'json');
 
201
    closeGISEditor();
 
202
}
 
203
 
 
204
/**
 
205
 * Unbind all event handlers before tearing down a page
 
206
 */
 
207
AJAX.registerTeardown('gis_data_editor.js', function() {
 
208
    $("#gis_editor input[name='gis_data[save]']").die('click');
 
209
    $('#gis_editor').die('submit');
 
210
    $('#gis_editor').find("input[type='text']").die('change');
 
211
    $("#gis_editor select.gis_type").die('change');
 
212
    $('#gis_editor a.close_gis_editor, #gis_editor a.cancel_gis_editor').die('click');
 
213
    $('#gis_editor a.addJs.addPoint').die('click');
 
214
    $('#gis_editor a.addLine.addJs').die('click');
 
215
    $('#gis_editor a.addJs.addPolygon').die('click');
 
216
    $('#gis_editor a.addJs.addGeom').die('click');
 
217
});
 
218
 
 
219
AJAX.registerOnload('gis_data_editor.js', function() {
 
220
 
 
221
    // Remove the class that is added due to the URL being too long.
 
222
    $('span.open_gis_editor a').removeClass('formLinkSubmit');
 
223
 
 
224
    /**
 
225
     * Prepares and insert the GIS data to the input field on clicking 'copy'.
 
226
     */
 
227
    $("#gis_editor input[name='gis_data[save]']").live('click', function(event) {
 
228
        event.preventDefault();
 
229
        insertDataAndClose();
 
230
    });
 
231
 
 
232
    /**
 
233
     * Prepares and insert the GIS data to the input field on pressing 'enter'.
 
234
     */
 
235
    $('#gis_editor').live('submit', function(event) {
 
236
        event.preventDefault();
 
237
        insertDataAndClose();
 
238
    });
 
239
 
 
240
    /**
 
241
     * Trigger asynchronous calls on data change and update the output.
 
242
     */
 
243
    $('#gis_editor').find("input[type='text']").live('change', function() {
 
244
        var $form = $('form#gis_data_editor_form');
 
245
        $.post('gis_data_editor.php', $form.serialize() + "&generate=true&ajax_request=true", function(data) {
 
246
            if (data.success == true) {
 
247
                $('#gis_data_textarea').val(data.result);
 
248
                $('#placeholder').empty().removeClass('hasSVG').html(data.visualization);
 
249
                $('#openlayersmap').empty();
 
250
                eval(data.openLayers);
 
251
                initGISEditorVisualization();
 
252
            } else {
 
253
                PMA_ajaxShowMessage(data.error, false);
 
254
            }
 
255
        }, 'json');
 
256
    });
 
257
 
 
258
    /**
 
259
     * Update the form on change of the GIS type.
 
260
     */
 
261
    $("#gis_editor select.gis_type").live('change', function(event) {
 
262
        var $gis_editor = $("#gis_editor");
 
263
        var $form = $('form#gis_data_editor_form');
 
264
 
 
265
        $.post('gis_data_editor.php', $form.serialize() + "&get_gis_editor=true&ajax_request=true", function(data) {
 
266
            if (data.success == true) {
 
267
                $gis_editor.html(data.gis_editor);
 
268
                initGISEditorVisualization();
 
269
                prepareJSVersion();
 
270
            } else {
 
271
                PMA_ajaxShowMessage(data.error, false);
 
272
            }
 
273
        }, 'json');
 
274
    });
 
275
 
 
276
    /**
 
277
     * Handles closing of the GIS data editor.
 
278
     */
 
279
    $('#gis_editor a.close_gis_editor, #gis_editor a.cancel_gis_editor').live('click', function() {
 
280
        closeGISEditor();
 
281
    });
 
282
 
 
283
    /**
 
284
     * Handles adding data points
 
285
     */
 
286
    $('#gis_editor a.addJs.addPoint').live('click', function() {
 
287
        var $a = $(this);
 
288
        var name = $a.attr('name');
 
289
        // Eg. name = gis_data[0][MULTIPOINT][add_point] => prefix = gis_data[0][MULTIPOINT]
 
290
        var prefix = name.substr(0, name.length - 11);
 
291
        // Find the number of points
 
292
        var $noOfPointsInput = $("input[name='" + prefix + "[no_of_points]" + "']");
 
293
        var noOfPoints = parseInt($noOfPointsInput.val());
 
294
        // Add the new data point
 
295
        var html = addDataPoint(noOfPoints, prefix);
 
296
        $a.before(html);
 
297
        $noOfPointsInput.val(noOfPoints + 1);
 
298
    });
 
299
 
 
300
    /**
 
301
     * Handles adding linestrings and inner rings
 
302
     */
 
303
    $('#gis_editor a.addLine.addJs').live('click', function() {
 
304
        var $a = $(this);
 
305
        var name = $a.attr('name');
 
306
 
 
307
        // Eg. name = gis_data[0][MULTILINESTRING][add_line] => prefix = gis_data[0][MULTILINESTRING]
 
308
        var prefix = name.substr(0, name.length - 10);
 
309
        var type = prefix.slice(prefix.lastIndexOf('[') + 1, prefix.lastIndexOf(']'));
 
310
 
 
311
        // Find the number of lines
 
312
        var $noOfLinesInput = $("input[name='" + prefix + "[no_of_lines]" + "']");
 
313
        var noOfLines = parseInt($noOfLinesInput.val());
 
314
 
 
315
        // Add the new linesting of inner ring based on the type
 
316
        var html = '<br/>';
 
317
        if (type == 'MULTILINESTRING') {
 
318
            html += PMA_messages['strLineString'] + ' ' + (noOfLines + 1) + ':';
 
319
            var noOfPoints = 2;
 
320
        } else {
 
321
            html += PMA_messages['strInnerRing'] + ' ' + noOfLines + ':';
 
322
            var noOfPoints = 4;
 
323
        }
 
324
        html += '<input type="hidden" name="' + prefix + '[' + noOfLines + '][no_of_points]" value="' + noOfPoints + '"/>';
 
325
        for (var i = 0; i < noOfPoints; i++) {
 
326
            html += addDataPoint(i, (prefix + '[' + noOfLines + ']'));
 
327
        }
 
328
        html += '<a class="addPoint addJs" name="' + prefix + '[' + noOfLines + '][add_point]" href="#">+ '
 
329
            + PMA_messages['strAddPoint'] + '</a><br/>';
 
330
 
 
331
        $a.before(html);
 
332
        $noOfLinesInput.val(noOfLines + 1);
 
333
    });
 
334
 
 
335
    /**
 
336
     * Handles adding polygons
 
337
     */
 
338
    $('#gis_editor a.addJs.addPolygon').live('click', function() {
 
339
        var $a = $(this);
 
340
        var name = $a.attr('name');
 
341
        // Eg. name = gis_data[0][MULTIPOLYGON][add_polygon] => prefix = gis_data[0][MULTIPOLYGON]
 
342
        var prefix = name.substr(0, name.length - 13);
 
343
        // Find the number of polygons
 
344
        var $noOfPolygonsInput = $("input[name='" + prefix + "[no_of_polygons]" + "']");
 
345
        var noOfPolygons = parseInt($noOfPolygonsInput.val());
 
346
 
 
347
        // Add the new polygon
 
348
        var html = PMA_messages['strPolygon'] + ' ' + (noOfPolygons + 1) + ':<br/>';
 
349
        html += '<input type="hidden" name="' + prefix + '[' + noOfPolygons + '][no_of_lines]" value="1"/>'
 
350
            + '<br/>' + PMA_messages['strOuterRing'] + ':'
 
351
            + '<input type="hidden" name="' + prefix + '[' + noOfPolygons + '][0][no_of_points]" value="4"/>';
 
352
        for (var i = 0; i < 4; i++) {
 
353
            html += addDataPoint(i, (prefix + '[' + noOfPolygons + '][0]'));
 
354
        }
 
355
        html += '<a class="addPoint addJs" name="' + prefix + '[' + noOfPolygons + '][0][add_point]" href="#">+ '
 
356
            + PMA_messages['strAddPoint'] + '</a><br/>'
 
357
            + '<a class="addLine addJs" name="' + prefix + '[' + noOfPolygons + '][add_line]" href="#">+ '
 
358
            + PMA_messages['strAddInnerRing'] + '</a><br/><br/>';
 
359
 
 
360
        $a.before(html);
 
361
        $noOfPolygonsInput.val(noOfPolygons + 1);
 
362
    });
 
363
 
 
364
    /**
 
365
     * Handles adding geoms
 
366
     */
 
367
    $('#gis_editor a.addJs.addGeom').live('click', function() {
 
368
        var $a = $(this);
 
369
        var prefix = 'gis_data[GEOMETRYCOLLECTION]';
 
370
        // Find the number of geoms
 
371
        var $noOfGeomsInput = $("input[name='" + prefix + "[geom_count]" + "']");
 
372
        var noOfGeoms = parseInt($noOfGeomsInput.val());
 
373
 
 
374
        var html1 = PMA_messages['strGeometry'] + ' ' + (noOfGeoms + 1) + ':<br/>';
 
375
        var $geomType = $("select[name='gis_data[" + (noOfGeoms - 1) + "][gis_type]']").clone();
 
376
        $geomType.attr('name', 'gis_data[' + noOfGeoms + '][gis_type]').val('POINT');
 
377
        var html2 = '<br/>' + PMA_messages['strPoint'] + ' :'
 
378
            + '<label for="x"> ' + PMA_messages['strX'] + ' </label>'
 
379
            + '<input type="text" name="gis_data[' + noOfGeoms + '][POINT][x]" value=""/>'
 
380
            + '<label for="y"> ' + PMA_messages['strY'] + ' </label>'
 
381
            + '<input type="text" name="gis_data[' + noOfGeoms + '][POINT][y]" value=""/>'
 
382
            + '<br/><br/>';
 
383
 
 
384
        $a.before(html1); $geomType.insertBefore($a); $a.before(html2);
 
385
        $noOfGeomsInput.val(noOfGeoms + 1);
 
386
    });
 
387
});