]> dev.renevier.net Git - syp.git/blobdiff - js/admin.js
admin as default login user
[syp.git] / js / admin.js
index 85a28ddca09ee94712d9ba3e547bd01a6745a30f..cc02a60a00b040b40cb0238dbc5612465e6d2c8e 100644 (file)
@@ -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,
@@ -269,7 +329,6 @@ var Admin = {
 
     addNewFeature: function () {
         userMgr.close();
-
         function cancel() {
             $(document).unbind("keydown");
             Admin.reset()
@@ -281,7 +340,7 @@ var Admin = {
             }
         });
 
-        $("#newfeature_button").val("annuler");
+        $("#newfeature_button").val(SypStrings.Cancel);
         $("#newfeature_button").unbind("click").click(cancel);
 
         $("#instructions").text(SypStrings.AddHowto);
@@ -398,6 +457,10 @@ var FeatureMgr = {
     },
 
     add: function(evt) {
+        alert (SypStrings.DisabledForDemo);
+        $(document).unbind("keydown");
+        Admin.reset()
+        return;
         var map = Admin.map;
         var pos = map.getLonLatFromViewPortPx(evt.xy);
         feature = this.update (null, pos, "", "", "");
@@ -429,6 +492,8 @@ var FeatureMgr = {
     },
 
     del: function (feature) {
+        alert (SypStrings.DisabledForDemo);
+        return;
         var form = $("#feature_delete");
         form.find('input[name="fid"]').val(feature.fid);
         AjaxMgr.add({
@@ -923,6 +988,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);
@@ -932,6 +1003,10 @@ var userMgr = {
 
         this.commError("");
 
+        this.disableForms();
+        alert (SypStrings.DisabledForDemo);
+        return;
+
         AjaxMgr.add({
             form: $("#changepass"),
             oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
@@ -1008,7 +1083,16 @@ var userMgr = {
             return;
         }
 
+        if (!newuser_pass) {
+            this.commError(SypStrings.emptyPasswordError);
+            $("#pass_new").focus().select();
+            return;
+        }
+
         this.commError("");
+        this.disableForms();
+        alert (SypStrings.DisabledForDemo);
+        return;
 
         AjaxMgr.add({
             form: $("#newuser"),
@@ -1167,6 +1251,8 @@ $(window).load(function () {
         return false;
     });
     $("#image_delete").click(function() {
+            alert (SypStrings.DisabledForDemo);
+            return;
             $("#img").removeAttr('src');
             // needs to rebuild element otherwise some browsers still
             // display image.