X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=js%2Fadmin.js;h=71daf2c7cc93ca4ecf6ad97dfa64ed98b9de34a8;hp=e1dfe5f7f04562be72a470b5ea1903beb74959c5;hb=19730f2e2bbf61f389882c646f58349df3bcd848;hpb=939514b912738c5784b04a0d207db1afd918eb69 diff --git a/js/admin.js b/js/admin.js index e1dfe5f..71daf2c 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1,6 +1,66 @@ /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD * license. */ +/* + * Fix canvas rendering engine race condition. See js/syp.js for more explanation. + */ +OpenLayers.Renderer.Canvas.prototype = OpenLayers.Util.extend({ + needsRedraw: false, + imagesLoading: 0, +}, OpenLayers.Renderer.Canvas.prototype); +OpenLayers.Renderer.Canvas.prototype.oldRedraw = OpenLayers.Renderer.Canvas.prototype.redraw; +OpenLayers.Renderer.Canvas.prototype.redraw = function() { + if (this.imagesLoading > 0) { + this.needsRedraw = true; + return; + } + OpenLayers.Renderer.Canvas.prototype.oldRedraw.apply(this, arguments); +} +OpenLayers.Renderer.Canvas.prototype.drawExternalGraphic = function(pt, style) { + var img = new Image(); + img.src = style.externalGraphic; + + if(style.graphicTitle) { + img.title=style.graphicTitle; + } + + var width = style.graphicWidth || style.graphicHeight; + var height = style.graphicHeight || style.graphicWidth; + width = width ? width : style.pointRadius*2; + height = height ? height : style.pointRadius*2; + var xOffset = (style.graphicXOffset != undefined) ? + style.graphicXOffset : -(0.5 * width); + var yOffset = (style.graphicYOffset != undefined) ? + style.graphicYOffset : -(0.5 * height); + var opacity = style.graphicOpacity || style.fillOpacity; + + var context = { img: img, + x: (pt[0]+xOffset), + y: (pt[1]+yOffset), + width: width, + height: height, + canvas: this.canvas }; + + var self = this; + this.imagesLoading++; + img.onerror = function() { + self.imagesLoading--; + if ((self.imagesLoading == 0) && (self.needsRedraw)) { + self.needsRedraw = false; + self.redraw(); + } + } + img.onload = OpenLayers.Function.bind( function() { + self.imagesLoading--; + if ((self.imagesLoading == 0) && (self.needsRedraw)) { + self.needsRedraw = false; + self.redraw(); + } else { + this.canvas.drawImage(this.img, this.x, + this.y, this.width, this.height); + } + }, context); +} // drag feature with tolerance OpenLayers.Control.SypDragFeature = OpenLayers.Class (OpenLayers.Control.DragFeature, { startPixel: null, @@ -281,7 +341,7 @@ var Admin = { } }); - $("#newfeature_button").val("annuler"); + $("#newfeature_button").val(SypStrings.Cancel); $("#newfeature_button").unbind("click").click(cancel); $("#instructions").text(SypStrings.AddHowto); @@ -473,6 +533,11 @@ var FeatureMgr = { } var xml = new OpenLayers.Format.XML().read(data); + if (!xml.documentElement) { + this.commError(SypStrings.UnconsistentError); + $("title").focus(); + return; + } switch (xml.documentElement.nodeName.toLowerCase()) { case "error": @@ -723,7 +788,15 @@ var pwdMgr = { }, 0); return; } + var xml = new OpenLayers.Format.XML().read(data); + if (!xml.documentElement) { + this.commError(SypStrings.UnconsistentError); + $("#login_error").show(); + window.setTimeout(function() { + $("#user").focus().select(); + }, 0); + } switch (xml.documentElement.nodeName.toLowerCase()) { case "error": @@ -910,6 +983,12 @@ var userMgr = { return; } + if (!newpass) { + this.commError(SypStrings.emptyPasswordError); + $("#pass_new").focus().select(); + return; + } + var curpass = $("#pass_current").val(); if (newpass == curpass) { this.commError(SypStrings.changeSamePass); @@ -995,6 +1074,12 @@ var userMgr = { return; } + if (!newuser_pass) { + this.commError(SypStrings.emptyPasswordError); + $("#pass_new").focus().select(); + return; + } + this.commError(""); AjaxMgr.add({ @@ -1024,10 +1109,20 @@ var userMgr = { return; } + var xml = new OpenLayers.Format.XML().read(data); + if (!xml.documentElement) { + // here, we need a timeout because onsend timeout sometimes has not been triggered yet + var self = this; + window.setTimeout(function() { + self.enableForms(); + }, 0); + this.commError(SypStrings.UnconsistentError); + return; + } + var needFormEnabling = true; var focusEl = null; - var xml = new OpenLayers.Format.XML().read(data); switch (xml.documentElement.nodeName.toLowerCase()) { case "error": switch (xml.documentElement.getAttribute("reason")) {