/** * infoWindow的template * @author Wenyb * @date 2015/11/4 */ define([ "dojo", "dojo/_base/declare", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dojo/text!controls/infowindow/template.html", "dojo/_base/lang", "dojo/query", "dojo/dom-construct", "dojo/dom-style", "dojo/on", "dojo/dom-class", "dojo/dom-attr", "controls/searchbox/SearchBox", "base/AppEvent", "base/ConfigData", "dojo/domReady!" ], function( dojo, declare, _WidgetBase, _TemplatedMixin, template, lang, query, domConstruct, domStyle, on, domClass, domAttr, SearchBox, AppEvent, ConfigData ) { var Widget = declare([_WidgetBase, _TemplatedMixin], { templateString: template, _tabType: "fromHear", //fromHear,toHear,nearBy三种类型 constructor: function(options) { this._tabType = "fromHear"; this.routeStartSearchboxId = "InfowindowRouteStartSearchBox" + uuid(); this.routeEndSearchboxId = "InfowindowRouteEndSearchBox" + uuid(); this.nearbySearchBoxId = "InfowindowNearbySearchBox" + uuid(); this.nearbySearchWidgetId = "NearbySearchWidget"; }, postCreate: function() { this.inherited(arguments); this.nearbySearchboxControl = new SearchBox({ id: this.nearbySearchBoxId, baseClass: "infowindowNearbySearchbox", disableSuggest: true }, this.nearbySearchbox); this.nearbySearchboxControl.startup(); this.routeStartSearchboxControl = new SearchBox({ id: this.routeStartSearchboxId, baseClass: "infowindowRouteSearchbox", placeholder: "请选择到达地点" }, this.routeStartSearchbox); this.routeStartSearchboxControl.startup(); this.routeEndSearchboxControl = new SearchBox({ id: this.routeEndSearchboxId, hockId: ConfigData.hockId.routeEndSearchbox, baseClass: "infowindowRouteSearchbox", placeholder: "请选择出发地点" }, this.routeEndSearchbox); this.routeEndSearchboxControl.startup(); }, startup: function() { this.initEventHandler(); }, initEventHandler: function() { query(".custom-infotemplate-nearbysearch-poitype span").on("click", lang.hitch(this, function(evt) { var poiType = domAttr.get(evt.currentTarget, "data-poi-type"); var poiName = evt.currentTarget.innerHTML; AppEvent.dispatchAppEvent(AppEvent.NEARBY_SEARCH, { hockId: this.nearbySearchWidgetId, type: "updateState", graphic: this.getGraphic() }); AppEvent.dispatchAppEvent(AppEvent.NEARBY_SEARCH, { hockId: this.nearbySearchWidgetId, type: "search", poiType: poiType, poiName: poiName, model:"address" }); })); AppEvent.addAppEventListener(AppEvent.SEARCHBOX_QUERY, lang.hitch(this, this.onSearchboxQueryHandler)); AppEvent.addAppEventListener(AppEvent.ROUTE_ARGUMENT_CHANGED, lang.hitch(this, this.onRouteArgumentChanged)); }, onRouteArgumentChanged: function(evt) { switch (evt.type) { case "start": AppEvent.dispatchAppEvent(AppEvent.CHANGE_SEARCHBOX_STATE, { hockId: this.routeStartSearchboxId, type: "update", data: evt.data }); break; case "end": AppEvent.dispatchAppEvent(AppEvent.CHANGE_SEARCHBOX_STATE, { hockId: this.routeEndSearchboxId, type: "update", data: evt.data }); break; default: break; } }, onSearchboxQueryHandler: function(evt) { if (evt.hockId == this.routeStartSearchboxId) { this.routeStartSearchboxQueryHandler(evt); } else if (evt.hockId == this.routeEndSearchboxId) { this.routeEndSearchboxQueryHandler(evt); } else if (evt.hockId == this.nearbySearchBoxId) { this.nearbySearchboxQueryHandler(evt); } }, nearbySearchboxQueryHandler: function(evt) { switch (evt.type) { case "search": if (evt.args.keyword) { AppEvent.dispatchAppEvent(AppEvent.NEARBY_SEARCH, { hockId: this.nearbySearchWidgetId, type: "updateState", graphic: this.getGraphic() }); AppEvent.dispatchAppEvent(AppEvent.NEARBY_SEARCH, { hockId: this.nearbySearchWidgetId, type: "search", keyword: evt.args.keyword, poiType: null, poiName: "全部" }); } break; case "clear": AppEvent.dispatchAppEvent(AppEvent.NEARBY_SEARCH, { hockId: this.nearbySearchWidgetId, type: "clearState" }); break; default: break; } }, routeStartSearchboxQueryHandler: function(evt) { switch (evt.type) { case "suggest": AppEvent.dispatchAppEvent(AppEvent.CHANGE_ROUTE_ARGUMENT, { end: this.getGraphic(), start: null }); AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, { hockId: this.routeSearchWidgetId, type: "start", searchboxEventType: "suggest", poiId: evt.args.poiId }); break; case "search": AppEvent.dispatchAppEvent(AppEvent.CHANGE_ROUTE_ARGUMENT, { end: this.getGraphic(), start: null /*start: evt.args.keyword*/ }); AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, { hockId: this.routeSearchWidgetId, type: "start", searchboxEventType: "search", keyword: evt.args.keyword }); break; case "clear": AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, { hockId: this.routeSearchWidgetId, type: "start", searchboxEventType: "clear", }); break; default: break; } }, routeEndSearchboxQueryHandler: function(evt) { switch (evt.type) { case "suggest": AppEvent.dispatchAppEvent(AppEvent.CHANGE_ROUTE_ARGUMENT, { start: this.getGraphic(), end: null }); AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, { hockId: this.routeSearchWidgetId, type: "end", searchboxEventType: "suggest", poiId: evt.args.poiId }); break; case "search": AppEvent.dispatchAppEvent(AppEvent.CHANGE_ROUTE_ARGUMENT, { start: this.getGraphic(), end: null }); AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, { hockId: this.routeSearchWidgetId, type: "end", searchboxEventType: "search", keyword: evt.args.keyword }); break; case "clear": AppEvent.dispatchAppEvent(AppEvent.ROUTE_STOP_QUERY, { hockId: this.routeSearchWidgetId, type: "end", searchboxEventType: "clear", }); break; default: break; } }, _tabButtonClick: function(evt) { if (evt.target == this.fromHearButton) { this.switchTab("fromHear"); } else if (evt.target == this.toHearButton) { this.switchTab("toHear"); } else { this.switchTab("nearBy"); } }, switchTab: function(type) { switch (this._tabType) { case "fromHear": domClass.remove(this.fromHearButton); domClass.add(this.fromHearButton, "custom-infotemplate-tabbutton"); break; case "toHear": domClass.remove(this.toHearButton); domClass.add(this.toHearButton, "custom-infotemplate-tabbutton"); break; case "nearBy": domClass.remove(this.nearByButton); domClass.add(this.nearByButton, "custom-infotemplate-tabbutton"); break; } if (type == "fromHear") { this._tabType = type; domClass.remove(this.fromHearButton); domClass.add(this.fromHearButton, "custom-infotemplate-tabbutton-actived"); domStyle.set(this.nearByPanel, "display", "none"); domStyle.set(this.routeEnd, "display", "none"); domStyle.set(this.routeStart, "display", "block"); } else if (type == "toHear") { domClass.remove(this.toHearButton); domClass.add(this.toHearButton, "custom-infotemplate-tabbutton-actived"); domStyle.set(this.nearByPanel, "display", "none"); domStyle.set(this.routeStart, "display", "none"); domStyle.set(this.routeEnd, "display", "block"); this._tabType = type; } else if (type == "nearBy") { this._tabType = type; domClass.remove(this.nearByButton); domClass.add(this.nearByButton, "custom-infotemplate-tabbutton-actived"); domStyle.set(this.nearByPanel, "display", "block"); domStyle.set(this.routeStart, "display", "none"); domStyle.set(this.routeEnd, "display", "none"); } }, reset: function() { domStyle.set(this.tabcontainer, "display", "block"); domStyle.set(this.content, "bottom", ""); this.content.innerHTML = ""; domConstruct.empty(this.content); // this._tabType = "fromHear"; // this.routekeywordInput.innerHTML = ""; // domStyle.set(this.nearByPanel, "display", "none"); // domStyle.set(this.routePanel, "display", "block"); // domClass.remove(this.fromHearButton); // domClass.add(this.fromHearButton, "custom-infotemplate-tabbutton-actived"); // domClass.remove(this.toHearButton); // domClass.add(this.toHearButton, "custom-infotemplate-tabbutton"); // domClass.remove(this.nearByButton); // domClass.add(this.nearByButton, "custom-infotemplate-tabbutton"); //this.nearbySearchboxControl.clear(); }, setGraphic: function(graphic) { this.graphic = graphic; }, getGraphic: function(graphic) { return this.graphic; }, hideTab: function() { domStyle.set(this.tabcontainer, "display", "none"); domStyle.set(this.content, "bottom", "0px"); }, setContent: function(content) { if (typeof(content) == "string") { this.content.innerHTML = content; } else { domConstruct.place(content, this.content); } } }); return Widget; });