define([ "dojo/_base/declare", "dojo/_base/array", "dojo/on", "dojo/topic", "dojo/dom-class", "dojo/dom-construct", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dojo/text!./templates/Header.html", "esri/tasks/query", "esri/tasks/QueryTask", "app/util" ], function (declare, array, on, topic, domClass, domConstruct, _WidgetBase, _TemplatedMixin, template, Query, QueryTask, util) { return declare("app.layout.Header", [_WidgetBase, _TemplatedMixin], { templateString: template, config: null, postCreate: function () { this.inherited(arguments); this._attachEventHandlers(); this.initUI(this.config); }, _attachEventHandlers: function () { var self = this; this.own( on(this.BurgerButton, "click", function(e) { self.domNode.style.overflow = "visible"; if(domClass.contains(this, "open")) { domClass.remove(this, "open"); domClass.remove(self.navbar, "open"); self.domNode.style.overflow = "hidden"; } else { domClass.add(this, "open"); domClass.add(self.navbar, "open"); } })//, /* [PA]: disabled as obsolete topic.subscribe("OutageLayerRefreshed", function(featureSet, index) { self.updateSummaryInfo(featureSet, index); }) */ ); }, initUI: function(config) { if(!config.app) return; this.logoImgLink.href = config.app.logo.linkTo; this.logoImg.src = config.app.logo.url; this.logoImg.title = config.app.company; this.Title.innerHTML = config.app.name; this.initLinks(config.app.headerLinks); }, initLinks: function(links) { if(!links) return; for(var i = 0; i < links.length; i++) { this._createLink(links[i]); } }, _createLink: function(link) { if(!link) return; var li = domConstruct.create("li"); var a = domConstruct.create("a", { href: link.url || "#", title: link.title || "" //, // target: "_blank" }, li); var aText = document.createTextNode(a.title); a.appendChild(aText); this.LinksNode.appendChild(li); }, updateSummaryInfo: function(featureSet, index) { var self = this; var bannerUpdateTime, currentdate; bannerUpdateTime = null; // var totalOutages = 0; // var totalCustomers = 0; // minutesToWait = 0; // totalOutagesCommas = ""; // totalCustomersCommas = ""; // var outageNumberList = []; // array.forEach(featureSet.features, function (feature) { // bannerUpdateTime = feature.attributes["TIMESTAMP"]; // totalCustomers = totalCustomers + feature.attributes[self.outageLayerConfigs[index].customerCountField]; // if (!outageNumberList.indexOf(feature.attributes[self.outageLayerConfigs[index].outageIdField]) == 0) { // totalOutages = totalOutages + 1; // } // else { // outageNumberList.push(feature.attributes[self.outageLayerConfigs[index].outageIdField]); // } // }); var query = new Query(); query.outFields = ['*']; query.returnGeometry = false; query.where = "1=1"; var queryResult = new QueryTask(this.config.bannerServiceUrl).execute(query); queryResult.then(function(results) { self.updateStaticText(results, index, true); }, function(err) { console.error(err.message); }); // totalOutagesCommas = numberWithCommas(totalOutages); // totalCustomersCommas = numberWithCommas(totalCustomers); // minutesToWait = outageLayerConfigs[index].outageLayerRefreshMinutes; }, updateStaticText: function(results, index, isUTC) { var statsText = ""; var bannerUpdateTime; var bannerDateTimeStampField = this.config.bannerDateTimeStampField; if (results.features && results.features.length > 0) { bannerUpdateTime = results.features[0].attributes[bannerDateTimeStampField]; } var dateTimeObj = util.formatDate(bannerUpdateTime, true); if(dateTimeObj.date&&dateTimeObj.time) { var refreshInterval = _Controller.Map.outageLayerConfigs[index].outageLayerRefreshMinutes; statsText = "
Last Updated: " + dateTimeObj.date + "" + " at " + dateTimeObj.time + ". " + "Updates provided every " + refreshInterval + " minutes.
"; this.updateStringContainer.innerHTML = statsText; } } }); });