From bc4640e70e4dc76a7c49fb4b96ae1b8cf054e244 Mon Sep 17 00:00:00 2001
From: Armand Bahi <armand.bahi@veremes.com>
Date: Tue, 13 Nov 2018 11:47:36 +0100
Subject: [PATCH] =?UTF-8?q?Utilisation=20de=20deux=20champs=20au=20lieu=20?=
 =?UTF-8?q?d'une=20checkbox=20pour=20la=20g=C3=A9n=C3=A9ration=20des=20lie?=
 =?UTF-8?q?ns=20dans=20le=20mode=20vMap.=20fix=20#21?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../javascript/app/vmap/tools/urlexporter.js  | 48 +++++++++++--------
 .../module/template/tools/urlexporter.html    | 32 ++++++-------
 2 files changed, 43 insertions(+), 37 deletions(-)

diff --git a/src/module_vmap/module/javascript/app/vmap/tools/urlexporter.js b/src/module_vmap/module/javascript/app/vmap/tools/urlexporter.js
index d89684f2..b0b93b9c 100644
--- a/src/module_vmap/module/javascript/app/vmap/tools/urlexporter.js
+++ b/src/module_vmap/module/javascript/app/vmap/tools/urlexporter.js
@@ -68,35 +68,38 @@ nsVmap.nsToolsManager.Urlexporter.prototype.urlExporterController = function ($s
     /**
      * @type {string}
      */
-    this["urlToExport"] = "";
+    this["privateExportUrl"] = "";
+
     /**
-     * @type {boolean}
+     * @type {string}
      */
-    this["usePublicToken"] = false;
-
-    this["urlConstructor"]();
+    this["publicExportUrl"] = "";
 
     // recalcule l'url quand on change de carte
     oVmap['scope'].$on('mapChanged', function () {
-        this_["urlConstructor"]();
+        this_["privateExportUrl"] = this_.getExportUrl();
+        this_["publicExportUrl"] = this_.getExportUrl(true);
     });
 
-    $scope.$watch("ctrl.usePublicToken", function(){
-        this_["urlConstructor"]();
-    })
-
+    // recalcule l'url quand on bouge la  carte
     oVmap.getMap().getOLMap().on("moveend", function(event){
-        this_["urlConstructor"]();
+        this_["privateExportUrl"] = this_.getExportUrl();
+        this_["publicExportUrl"] = this_.getExportUrl(true);
     });
+
+    // Recalcule l'URL
+    this_["privateExportUrl"] = this_.getExportUrl();
+    this_["publicExportUrl"] = this_.getExportUrl(true);
 };
 
 /**
- * Display the user form in display mode
- * @returns {undefined}
+ * Generates and return the export URL
+ * @param  {boolean} bPublic
+ * @return {string}
  * @export
  */
-nsVmap.nsToolsManager.Urlexporter.prototype.urlExporterController.prototype.urlConstructor = function () {
-    oVmap.log("nsVmap.nsToolsManager.Urlexporter.urlExporterController.urlConstructor");
+nsVmap.nsToolsManager.Urlexporter.prototype.urlExporterController.prototype.getExportUrl = function (bPublic) {
+    oVmap.log("nsVmap.nsToolsManager.Urlexporter.urlExporterController.getExportUrl");
 
     var sUrl = this['properties']['web_server_name'] + "/" + this['properties']['application'];
 
@@ -114,7 +117,7 @@ nsVmap.nsToolsManager.Urlexporter.prototype.urlExporterController.prototype.urlC
     sUrl += "map_id=" + iMapId;
 
     // si public add token
-    if (this["usePublicToken"]){
+    if (bPublic === true){
         sUrl += "&token=" + this['properties']['public_token'];
     }
 
@@ -122,20 +125,23 @@ nsVmap.nsToolsManager.Urlexporter.prototype.urlExporterController.prototype.urlC
     var sExtent = oVmap.getMap().getOLMap().getView().calculateExtent(oVmap.getMap().getOLMap().getSize()).join("|");
     sUrl += "&extent=" + encodeURI(sExtent);
 
-    this["urlToExport"] = sUrl;
+    return sUrl;
 };
 
-
 /**
  * Copy the generated URL on the clipboard
- *
+ * @param  {boolean} bPublic
  * @export
  */
-nsVmap.nsToolsManager.Urlexporter.prototype.urlExporterController.prototype.copyUrl = function () {
+nsVmap.nsToolsManager.Urlexporter.prototype.urlExporterController.prototype.copyUrl = function (bPublic) {
     oVmap.log("nsVmap.nsToolsManager.Urlexporter.urlExporterController.copyUrl");
 
     /* Get the text field */
-    var copyText = document.getElementById("urlExporterField");
+    if (bPublic === true) {
+        var copyText = document.getElementById("publicExportUrlField");
+    } else {
+        var copyText = document.getElementById("privateExportUrlField");
+    }
 
     /* Select the text field */
     copyText.select();
diff --git a/src/module_vmap/module/template/tools/urlexporter.html b/src/module_vmap/module/template/tools/urlexporter.html
index c10845a6..a1602e30 100644
--- a/src/module_vmap/module/template/tools/urlexporter.html
+++ b/src/module_vmap/module/template/tools/urlexporter.html
@@ -2,29 +2,29 @@
 <div class="row margin-sides-0 margin-10">
     <div class="col-md-12">
         <div class="left">
-            <label for="urlExporterField" class="control-label">Lien vers la carte en cours</label>
-        </div>
-        <div class="right" ng-if="ctrl.properties.allow_public_connection">
-            <div class="checkbox checkbox-info checkbox-inline">
-                <input id="publicAccountCheckbox"
-                        type="checkbox"
-                        style="cursor:pointer;"
-                        title=">Activer / Désactiver le mode public"
-                        ng-model="ctrl.usePublicToken">
-                <label for="publicAccountCheckbox"
-                       style="cursor:pointer"
-                       title="Activer / Désactiver le mode public">
-                    Public
-                </label>
-            </div>
+            <label for="privateExportUrlField" class="control-label">Lien vers la carte en cours</label>
         </div>
     </div>
     <div class="col-md-12">
         <div class="input-group">
-            <input type="text" class="form-control" ng-model="ctrl.urlToExport" id="urlExporterField">
+            <span class="input-group-btn">
+                <button type="button" class="btn btn-default" disabled><span class="fa fa-lock"></span></button>
+            </span>
+            <input type="text" class="form-control" ng-model="ctrl.privateExportUrl" id="privateExportUrlField">
             <span class="input-group-btn">
                 <button type="button" class="btn btn-default" ng-click="ctrl.copyUrl()"><span class="icon-copy"></span></button>
             </span>
         </div>
     </div>
+    <div class="col-md-12 margin-10" ng-if="ctrl.properties.allow_public_connection">
+        <div class="input-group">
+            <span class="input-group-btn">
+                <button type="button" class="btn btn-default" disabled><span class="fa fa-unlock"></span></button>
+            </span>
+            <input type="text" class="form-control" ng-model="ctrl.publicExportUrl" id="publicExportUrlField">
+            <span class="input-group-btn">
+                <button type="button" class="btn btn-default" ng-click="ctrl.copyUrl(true)"><span class="icon-copy"></span></button>
+            </span>
+        </div>
+    </div>
 </div>
-- 
GitLab