Commit 85e25477 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Update gadget_erp5_page_map

   Clean up unrequired code
   Use domsugar rather them createElement for simplification
parent a0553cf5
.sensor-status {
min-width: 210px;
}
/* --------------------- CUSTOM MAP ----------------------- */ /* --------------------- CUSTOM MAP ----------------------- */
.custom-map-wrap { .custom-map-wrap {
position: relative; position: relative;
......
...@@ -71,7 +71,9 @@ ...@@ -71,7 +71,9 @@
</item> </item>
<item> <item>
<key> <string>content_type</string> </key> <key> <string>content_type</string> </key>
<value> <string>text/css</string> </value> <value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
...@@ -246,7 +248,7 @@ ...@@ -246,7 +248,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>964.17264.3291.60876</string> </value> <value> <string>1006.58340.40727.23620</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +268,7 @@ ...@@ -266,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1513789742.97</float> <float>1693252894.23</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
<!-- renderjs --> <!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script> <script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script> <script src="renderjs.js" type="text/javascript"></script>
<script src="domsugar.js" type="text/javascript"></script>
<!-- custom script --> <!-- custom script -->
<script src="leaflet.js" type="text/javascript"></script> <script src="leaflet.js" type="text/javascript"></script>
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.22055.19881.8430</string> </value> <value> <string>1009.49086.48551.49459</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1502452463.01</float> <float>1693252925.17</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*jslint nomen: true, maxlen:200, indent:2*/ /*jslint nomen: true, maxlen:200, indent:2*/
/*global window, document, rJS, console, RSVP, L, $, Image */ /*global window, rJS, console, RSVP, L, Image, domsugar */
(function (window, document, rJS, RSVP) { (function (window, rJS, RSVP, L, domsugar) {
"use strict"; "use strict";
rJS(window) rJS(window)
.ready(function (g) { .ready(function (g) {
g.props = {}; g.props = {};
})
.ready(function (g) {
g.props.deferred = new RSVP.defer(); g.props.deferred = new RSVP.defer();
}) })
.ready(function (g) {
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
.declareAcquiredMethod("notifyChange", "notifyChange") .declareAcquiredMethod("notifyChange", "notifyChange")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSetting", "getSetting")
...@@ -57,31 +49,12 @@ ...@@ -57,31 +49,12 @@
return gadget.props.deferred.resolve(); return gadget.props.deferred.resolve();
}); });
}) })
.declareMethod('getContent', function (options) {
var gadget = this,
result = [],
tmp,
i;
for (i = 0; i < gadget.props.new_marker_list.length; i += 1) {
tmp = gadget.props.new_marker_list[i].getLatLng();
result.push({latitude: tmp.lat, longitude: tmp.lng});
}
return result;
})
.declareService(function () { .declareService(function () {
var gadget = this, var gadget = this,
map_element,
latitude,
longitude,
zoom,
marker_list, marker_list,
new_marker_list = [], new_marker_list = [],
marker_link,
marker_label, marker_label,
marker_space,
marker_monitor_link,
group, group,
redIcon,
map, map,
osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osm, osm,
...@@ -91,7 +64,6 @@ ...@@ -91,7 +64,6 @@
'Imagery © <a href="http://mapbox.com">Mapbox</a>', 'Imagery © <a href="http://mapbox.com">Mapbox</a>',
marker, marker,
marker_options = {}, marker_options = {},
queue,
m, m,
i, i,
bounds, bounds,
...@@ -109,23 +81,20 @@ ...@@ -109,23 +81,20 @@
return gadget.props.deferred.promise; return gadget.props.deferred.promise;
}) })
.push(function () { .push(function () {
var l = [], var l = [];
marker_list = gadget.options.marker_list || []; marker_list = gadget.options.marker_list || [];
for (i = 0; i < marker_list.length; i += 1) { for (i = 0; i < marker_list.length; i += 1) {
l.push(gadget.getUrlFor({command: "change", l.push(gadget.getUrlFor({command: "change",
options: {jio_key: marker_list[i].jio_key, options: {jio_key: marker_list[i].jio_key,
page: "slap_controller"}})); page: "slap_controller"}}));
} }
l.push(gadget.getSetting("hateoas_url"));
return RSVP.all(l); return RSVP.all(l);
}) })
.push(function (url_list) { .push(function (url_list) {
var hateoas_url = url_list.pop(); var map_element = gadget.element.querySelector(".map"),
map_element = gadget.props.element.querySelector(".map"),
latitude = gadget.options.doc.latitude || 0, latitude = gadget.options.doc.latitude || 0,
longitude = gadget.options.doc.longitude || 0, longitude = gadget.options.doc.longitude || 0,
zoom = gadget.options.zoom || 0, zoom = gadget.options.zoom || 0,
marker_list = gadget.options.marker_list || [];
redIcon = L.icon({iconUrl: "hateoas/marker-icon-mod-100-70-10.png", redIcon = L.icon({iconUrl: "hateoas/marker-icon-mod-100-70-10.png",
shadowUrl: "hateoas/marker-shadow.png", shadowUrl: "hateoas/marker-shadow.png",
iconSize: [25, 41], iconSize: [25, 41],
...@@ -152,18 +121,9 @@ ...@@ -152,18 +121,9 @@
for (i = 0; i < marker_list.length; i += 1) { for (i = 0; i < marker_list.length; i += 1) {
m = marker_list[i]; m = marker_list[i];
marker_link = document.createElement("a"); marker_label = domsugar("div", {}, [
marker_link.href = url_list[i]; domsugar("a", {href: url_list[i], text: m.doc.title, 'class': "ui-btn-map"})
marker_link.text = m.doc.title; ]);
marker_link.className = "ui-btn-map";
marker_label = document.createElement("div");
marker_label.appendChild(marker_link);
marker_space = document.createElement("span");
marker_space.innerHTML = " &nbsp; &nbsp; | &nbsp; ";
marker_space.className = "ui-btn-map";
marker_label.appendChild(marker_space);
marker = new L.marker( marker = new L.marker(
[m.doc.latitude || 0, m.doc.longitude || 0], [m.doc.latitude || 0, m.doc.longitude || 0],
marker_options marker_options
...@@ -200,16 +160,13 @@ ...@@ -200,16 +160,13 @@
container = e.popup._container.querySelector('.leaflet-popup-content-wrapper'); container = e.popup._container.querySelector('.leaflet-popup-content-wrapper');
tmp = container.querySelector('.sensor-status'); tmp = container.querySelector('.sensor-status');
if (!tmp) { if (!tmp) {
tmp = document.createElement('div'); tmp = domsugar('div', {'class': 'sensor-status'});
tmp.className = 'sensor-status';
tmp.style['min-width'] = '210px';
container.appendChild(tmp); container.appendChild(tmp);
e.target._queue.push(function () { e.target._queue.push(function () {
return gadget.declareGadget('gadget_slapos_status.html', { return gadget.declareGadget('gadget_slapos_status.html', {
element: tmp element: tmp
}); });
}) }).push(function (compute_node) {
.push(function (compute_node) {
//xxxx repopup to resize popup //xxxx repopup to resize popup
new_marker_list[index].openPopup(); new_marker_list[index].openPopup();
return compute_node.render({ return compute_node.render({
...@@ -225,4 +182,4 @@ ...@@ -225,4 +182,4 @@
return RSVP.all(list); return RSVP.all(list);
}); });
}); });
}(window, document, rJS, RSVP)); }(window, rJS, RSVP, L, domsugar));
\ No newline at end of file \ No newline at end of file
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1010.49809.16983.53265</string> </value> <value> <string>1010.50117.59231.38434</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -258,7 +258,7 @@ ...@@ -258,7 +258,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1693251958.55</float> <float>1693270216.86</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment