// file = NodeMarker /* NodeMarker.js Description : Class managing nodes markers Contributors: Pascal Vitoux (pascal@vitoux.com) Flavien Gateuil (flavien@freephonie.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ var FreeBoxTypeText = new Array("Freebox V1","Freebox V2","Freebox V3","Freebox V4","Freebox HD"); function NodeMarker (name, idUser, idMarker, description, status, lng, lat, IPAddr, modemType, actif, site, perso) { this.isInDB = (idMarker != -1); this.idUser = idUser; this.idMarker= idMarker; this.name = name; this.description = description; this.status = status; this.lng = lng; this.lat = lat; this.IPAddr = IPAddr; this.modemType = modemType; this.actif = actif; this.site = site; this.visible = true; this.wifi = null; if (this.modemType == 5) { this.wifi = new EInsert(new GLatLng(this.lat,this.lng), "images/zone200.png", new GSize(14,14), 14); } this.liNode = null; this.submit = ""; this.perso = perso; this.pointDB = null; if (this.isInDB) { this.pointDB = new GLatLng(lat, lng); } this.putBack = function() { this.moveTo(this.pointDB); if (this.visible) { this.openInfoWindowHtml(this.getHtml()); } } this.getName = function() { return this.name; } this.setName = function(name) { this.name = name; this.isInDB = false; } this.getDescription = function() { return this.description; } this.setDescription = function(description) { this.description= description; this.isInDB = false; } this.getModemType = function() { return this.modemType; } this.setModemType = function(modemType) { this.modemType = modemType; this.isInDB = false; } this.getSite = function() { return this.site; } this.setSite = function(site) { this.site = site; this.isInDB = false; } var point = new GLatLng (lat, lng); if (this.perso) { this.statePretty = "Marqueur"; var icon = new GIcon (); icon.image = IMAGES_PATH + "/newImages/marker_bleu.png"; icon.iconSize = new GSize(20, 34); icon.iconAnchor = new GPoint(9, 34); icon.infoWindowAnchor = new GPoint(20, 1); NodeMarker.baseConstructor.call (this, point, icon); } else { if (this.status == POTENTIAL) { switch (this.modemType) { case 1 : case 2 : case 3 : case 4 : this.statePretty = "Noeud"; var icon = new GIcon (); icon.image = IMAGES_PATH + "/newImages/marker_apple.png"; icon.iconSize = new GSize(20, 34); icon.iconAnchor = new GPoint(9, 34); icon.infoWindowAnchor = new GPoint(20, 1); NodeMarker.baseConstructor.call (this, point, icon); break; case 5 : this.statePretty = "Noeud"; var icon = new GIcon (); icon.image = IMAGES_PATH + "/newImages/marker.png"; icon.iconSize = new GSize(20, 34); icon.iconAnchor = new GPoint(9, 34); icon.infoWindowAnchor = new GPoint(20, 1); NodeMarker.baseConstructor.call (this, point, icon); break; default : this.statePretty = "Noeud"; var icon = new GIcon (); icon.image = IMAGES_PATH + "/newImages/marker_potential.png"; icon.iconSize = new GSize(20, 34); icon.iconAnchor = new GPoint(9, 34); icon.infoWindowAnchor = new GPoint(20, 1); NodeMarker.baseConstructor.call (this, point, icon); break; } } else if (this.status == ACTIVE) { switch (this.modemType) { case 1 : case 2 : case 3 : case 4 : this.statePretty = "Noeud"; var icon = new GIcon (); icon.image = IMAGES_PATH + "/newImages/marker_green.png"; icon.iconSize = new GSize(20, 34); icon.iconAnchor = new GPoint(9, 34); icon.infoWindowAnchor = new GPoint(20, 1); NodeMarker.baseConstructor.call (this, point, icon); break; case 5 : this.statePretty = "Noeud"; var icon = new GIcon (); icon.image = IMAGES_PATH + "/newImages/marker_blood.png"; icon.iconSize = new GSize(20, 34); icon.iconAnchor = new GPoint(9, 34); icon.infoWindowAnchor = new GPoint(20, 1); NodeMarker.baseConstructor.call (this, point, icon); break; default : this.statePretty = "Noeud"; var icon = new GIcon (); icon.image = IMAGES_PATH + "/newImages/marker_orange.png"; icon.iconSize = new GSize(20, 34); icon.iconAnchor = new GPoint(9, 34); icon.infoWindowAnchor = new GPoint(20, 1); NodeMarker.baseConstructor.call (this, point, icon); break; } } else { alert ("Marqueur incorrect"); } } this.updateURL = function () { this.submit = "?idMarker=" + this.idMarker + "&modemType=" + URLEncode(this.modemType) + "&actif="; this.submit += URLEncode(this.actif) + "&lon=" + this.getPoint().lng() + "&lat=" + this.getPoint().lat() + "&desc="; this.submit += URLEncode(this.description) + "&IPAddr=" + URLEncode(this.IPAddr); } this.getSubmitURL = function() { return "?idMarker=" + this.idMarker + "&modemType=" + this.modemType + "&actif=" + this.actif + "&lon=" + this.getPoint().lng() + "&lat=" + this.getPoint().lat() + "&status=" + this.status + "&desc=" + escape(this.description) + "&IPAddr=" + this.IPAddr; } this.moveTo = function(point) { map.removeOverlay(this.wifi); this.wifi = new EInsert(point, "images/zone200.png", new GSize(28,28), 14); if ((this.modemType == '5') && (showWiFiCoverage.checked)) { map.addOverlay(this.wifi); } this.setPoint(point); this.isInDB = false; } this.getHtml = function () { var html = ""; var ModificationsAllowed = false; var thing = document.createElement ("div"); thing.className = "marker_balloon"; // Debug data //thing.appendChild (document.createTextNode ('Debug data : ' + this.name+","+this.description+","+this.IPAddr+","+this.confirm+","+this.modemType+","+this.actif+","+this.nodeUrl)); var chkbox; if (this.perso) { // Comments related to the data's modification var centerNode = document.createElement("center"); var italicNode = document.createElement("i"); var brNode = document.createElement("br"); var comments = document.createTextNode("Pour éditer les données, cliquez sur les champs correspondants"); italicNode.appendChild(comments); centerNode.appendChild(italicNode); thing.appendChild(centerNode); thing.appendChild(brNode); // Node name // var mainNode = document.createElement ("div"); // mainNode.className = "title"; // var bNode = document.createElement("b"); // bNode.appendChild(document.createTextNode('Nom : ')); // mainNode.appendChild(bNode); // var editableNode = document.createElement ("span"); // editableNode.className = "title"; // editableNode.id = "editableName"; // editableNode.style.cursor = "pointer"; // editableNode.style.color = "green"; // editableNode.appendChild(document.createTextNode(this.name)); // mainNode.appendChild (editableNode); // thing.appendChild (mainNode); // Modem type mainNode = document.createElement ("div"); mainNode.className ="position"; bNode = document.createElement("b"); bNode.appendChild(document.createTextNode("Type de FreeBox : ")); mainNode.appendChild(bNode); var FreeBoxSelect = document.createElement("select"); FreeBoxSelect.style.zIndex = "10"; FreeBoxSelect.setAttribute("OnChange", "javascript:currentMarker.modemType=this.value; currentMarker.updateURL();"); for (var i = 0; i < FreeBoxTypeText.length; i++) { var oOption = document.createElement("option"); oOption.value = ""+(i+1); oOption.appendChild(document.createTextNode(FreeBoxTypeText[i])); if (this.modemType == oOption.value) oOption.setAttribute("selected","true"); FreeBoxSelect.appendChild (oOption); } mainNode.appendChild (FreeBoxSelect); thing.appendChild (mainNode); // Node description mainNode = document.createElement ("div"); mainNode.className ="position"; bNode = document.createElement("b"); bNode.appendChild(document.createTextNode("Description : ")); mainNode.appendChild (bNode); var txtdata = this.description; if (txtdata == '') { // If the description is empty, "(vide)" is displayed txtdata = "(vide)"; } var uNode = document.createElement("u"); editableNode = document.createElement("span"); editableNode.className = "title"; editableNode.id="editableDesc"; editableNode.style.cursor = "pointer"; editableNode.style.color = "red"; editableNode.appendChild(document.createTextNode(txtdata)); uNode.appendChild(editableNode); mainNode.appendChild(uNode); //mainNode.appendChild(editableNode); thing.appendChild(mainNode); // Web site // mainNode = document.createElement ("div"); // mainNode.className ="position"; // bNode = document.createElement("b"); // bNode.appendChild(document.createTextNode("Site : ")); // mainNode.appendChild(bNode); // editableNode = document.createElement ("span"); // editableNode.className = "title"; // editableNode.id="editableSite"; // editableNode.style.cursor = "pointer"; // editableNode.style.color = "blue"; // editableNode.appendChild(document.createTextNode(this.site)); // mainNode.appendChild(editableNode); // thing.appendChild(mainNode); // Actif ? mainNode = document.createElement ("div"); mainNode.className ="position"; chkbox = document.createElement("input"); chkbox.setAttribute("id", "actifChkBox"); chkbox.setAttribute("class","checkbox"); chkbox.setAttribute("type","checkbox"); chkbox.setAttribute("onClick","javascript:var result; if (this.checked) result = true; else result = false; currentMarker.actif=result; currentMarker.updateURL();"); var chkboxlabel = document.createElement("label"); chkboxlabel.setAttribute("for", "actifChkBox"); var txtNode = document.createTextNode("WiFi actif"); chkboxlabel.appendChild (txtNode); mainNode.appendChild(chkbox); mainNode.appendChild(chkboxlabel); thing.appendChild (mainNode); var actionList = document.createElement ("ul"); // Add the marker in the database this.updateURL(); var addActionItem = document.createElement ("li"); var addActionLink = document.createElement ("a"); addActionLink.appendChild(document.createTextNode("Enregistrer ce marqueur")); //addActionLink.href = "javascript:window.open (url, 'window','menubar=no,scrollbars=yes,addressbar=no,locationbar=no,status=no,height=530,width=440'); void(0);"; addActionLink.href = "javascript:checkBefore();" addActionLink.onclick = "javascript:checkBefore();" addActionItem.appendChild(addActionLink); actionList.appendChild(addActionItem); // Delete the marker if (this.idMarker == -1) { var deleteActionItem = document.createElement ("li"); var deleteActionLink = document.createElement ("a"); deleteActionLink.appendChild(document.createTextNode("Supprimer ce marqueur")); deleteActionLink.href = "javascript:removeMarkerFromMap('"+encode64(this.name)+"');currentMarker=null;void(0);"; deleteActionItem.appendChild (deleteActionLink); actionList.appendChild (deleteActionItem); } // Put back the marker to the initial place if ((this.idMarker != -1) && ((this.getPoint().x!=this.pointDB.x) || (this.getPoint().y!=this.pointDB.y))) { var putBackActionItem = document.createElement ("li"); var putBackActionLink = document.createElement ("a"); putBackActionLink.appendChild(document.createTextNode("Annuler le d?placement")); putBackActionLink.href = "javascript:getMarker('"+encode64(this.name)+"').putBack();void(0);"; putBackActionItem.appendChild (putBackActionLink); actionList.appendChild (putBackActionItem); } thing.appendChild(actionList); } else { // Not editable node var mainNode = document.createElement ("div"); mainNode.className = "title"; var bNode = document.createElement ("b"); bNode.appendChild(document.createTextNode(this.name)); mainNode.appendChild (bNode); // If a description exists, we add it to the title if (this.description != 'Cliquez ici pour modifier') { mainNode.appendChild (document.createTextNode(' (' + this.description + ') ')); } // Web site if (this.site!='') { var brNode = document.createElement("br"); var aNode = document.createElement ("a"); aNode.href = this.site; aNode.target = "_blank"; var imgNode = document.createElement("img"); imgNode.src = 'images/home.gif'; imgNode.title = 'Site Web'; aNode.appendChild (imgNode); mainNode.appendChild(brNode); mainNode.appendChild(document.createTextNode("Mon site : ")); mainNode.appendChild (aNode); } // Title node thing.appendChild (mainNode); // mainNode = document.createElement ("div"); // mainNode.className ="position"; // bNode = document.createElement("b"); // bNode.appendChild(document.createTextNode("Type : ")); // mainNode.appendChild(bNode); // mainNode.appendChild(document.createTextNode(this.statePretty)); // thing.appendChild (mainNode); /* // Position node var brNode = document.createElement("br"); mainNode = document.createElement ("div"); mainNode.className = "position"; bNode = document.createElement("b"); bNode.appendChild(document.createTextNode("Latitude : ")); mainNode.appendChild(bNode); mainNode.appendChild(document.createTextNode("" + Math.round(this.getPoint().lat()*1000000)/1000000)); mainNode.appendChild(brNode); bNode = document.createElement("b"); bNode.appendChild(document.createTextNode("Longitude : ")); mainNode.appendChild(bNode); mainNode.appendChild(document.createTextNode("" + Math.round(this.getPoint().lng()*1000000)/1000000)); thing.appendChild (mainNode);*/ var centerNode = document.createElement("center"); mainNode = document.createElement ("div"); mainNode.style.fontSize = "15px"; bNode = document.createElement("b"); if (this.actif) { mainNode.style.color = "green"; bNode.appendChild(document.createTextNode("Wifi actif")); } else { mainNode.style.color = "red"; bNode.appendChild(document.createTextNode("Wifi inactif")); } mainNode.appendChild(bNode); centerNode.appendChild(mainNode); thing.appendChild (centerNode); /* var centerNode = document.createElement("center"); mainNode = document.createElement("div"); mainNode.className = "title"; bNode = document.createElement("b"); var aNode = document.createElement("a"); aNode.href = "javascript:void(0);"; aNode.onclick = function() {getMarker(encode64(this.name)).zoomTo();}; aNode.className = "zoomLink"; aNode.appendChild(document.createTextNode("zoom")); bNode.appendChild(aNode); mainNode.appendChild(bNode); centerNode.appendChild(mainNode); thing.appendChild(centerNode);*/ } var divNode = document.createElement ("div"); divNode.appendChild (thing); if (chkbox) { if (this.actif) { chkbox.setAttribute("checked","checked"); chkbox.checked = true; } else { chkbox.checked = false; } } return divNode.innerHTML; } this.select = function () { this.showTooltip(); } this.zoomTo = function () { this.destroyTooltip (); map.setCenter (this.getPoint(), 17); this.showTooltip(); } this.GetChangePropertyFunction = function (msg, propertyname, propertycurrentvalue) { return "javascript:var newname=renamePrompt('" + encode64 (propertycurrentvalue)+ "','"+msg+"'); if (newname!=null) {getMarker('"+encode64(this.name)+"')."+propertyname+"=newname; getMarker('"+encode64(this.name)+"').select();}"; } this.showTooltip = function () { //this.destroyTooltip(); this.openInfoWindowHtml(this.getHtml()); new EditableElement("editableDesc", 12, this); // new EditableElement("editableSite", 12, this); } this.destroyTooltip = function () { map.closeInfoWindow(); } GEvent.addListener (this, 'click', this.select); // GEvent.addListener (this, 'mouseover', this.showTooltip); // GEvent.addListener (this, 'mouseout', this.destroyTooltip); } NodeMarker.saveName extend = function(subClass, baseClass) { function inheritance() {} inheritance.prototype = baseClass.prototype; subClass.prototype = new inheritance(); subClass.prototype.constructor = subClass; subClass.baseConstructor = baseClass; subClass.superClass = baseClass.prototype; } extend(NodeMarker, GMarker);