String.prototype.has = function(str, ignoreCase) {return (ignoreCase) ? this.toLowerCase().indexOf(str) >= 0: this.indexOf(str) >= 0;} String.create = function(chr, length) {var res = "";for(var i=0;i 0;} Idaligo.Core.isArray = function(smth) {return Idaligo.Core.defined(smth) && Idaligo.Core.isNumber(smth.length);} Idaligo.Core.isString = function(smth) {return Idaligo.Core.defined(smth) && (typeof(smth) == "string");} Idaligo.Core.isNotEmptyArray = function(smth) {return Idaligo.Core.isArray(smth) && smth.length > 0;} Idaligo.TxBld = function(parent) {this._pr = Idaligo.Core.def(parent, null); this.level = (Idaligo.Core.defined(this._pr)) ? (this._pr.level + 1) : 0; this.r = ""; }; Idaligo.TxBld.prototype.add = function(txt) {if (Idaligo.Core.defined(this._pr)) this._pr.add(String.create(' ', this.level * 4) + txt); else this.r += txt;}; Idaligo.TxBld.prototype.addLine = function(txt) {this.add(txt + "\r\n");}; Idaligo.TxBld.prototype.toString = function() {return (Idaligo.Core.defined(this._pr)) ? this._pr.toString() : this.r;} Idaligo.TxBld.prototype.reset = function() {if (Idaligo.Core.defined(this._pr)) this._pr.reset(); else {this.r = "";}} Idaligo.Calc = function() {}; Idaligo.Calc.dec2hex = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; Idaligo.Calc.random = function(from, to) {return from + Math.round(Math.random() * (to - from));} Idaligo.Colour = function() {}; Idaligo.Colour.random = function() {var r = ""; for(var i=0;i<6;i++) r += Idaligo.Calc.dec2hex[Idaligo.Calc.random(0, 15)]; return r;} Idaligo.Agent = function(){}; Idaligo.Agent.TYPE = {IE:(navigator.userAgent.toLowerCase().indexOf("msie") >= 0), FF:(navigator.userAgent.toLowerCase().indexOf("firefox") >= 0)} Idaligo.Agent.getVersion = function() { var navigator = window.navigator.userAgent.toLowerCase(); if (Idaligo.Agent.TYPE.IE) { var indicator = "msie" var starts = navigator.indexOf(indicator); if (starts < 0) throw new Error(Idaligo.Error.MSG.UNABLE_TO_GET_VERSION); starts += indicator.length; var ends = navigator.indexOf(";", starts); if (ends < starts) throw new Error(Idaligo.Error.MSG.UNABLE_TO_GET_VsERSION); return parseInt(navigator.substring(starts, ends)); } else if (Idaligo.Agent.TYPE.FF) { return navigator.userAgent; } } Idaligo.Agent.getName = function() { var result; try { result = navigator.userAgent.toLowerCase(); } catch (e) { result = "Unable to get the agent name. Reason: " + e; } return result; } Idaligo.Error = function() {}; Idaligo.Error.MSG = { CLIENT_NOT_SUPPORTED: "Client is not supported: " + Idaligo.Agent.getName() , INVALID_OPERATION: 'Invalid operation.' , ARGUMENT_UNDEFINED: function(name) {return "Parameter \"" + name + "\" is not specified.";} , ARGUMENT_MUST_BE_ARRAY: function(name) {return "Parameter \"" + name + "\" is expcted to be an array.";} , ARGUMENT_MUST_BE_NUMBER: function(name) {return "Parameter \"" + name + "\" is expcted to be a number.";} , ARGUMENT_MUST_BE_DATE: function(name) {return "Parameter \"" + name + "\" is expcted to be a date.";} , ARGUMENT_EMPTY_STRING: function(name) {return "Parameter \"" + name + "\" is expected to be a not empty string.";} , UNABLE_TO_GET_VERSION: "Unable to get the user agent version." } Idaligo.Error.checkArgument = function(value, name) {if (! Idaligo.Core.defined(value)) throw new Error(Idaligo.Error.MSG.ARGUMENT_UNDEFINED(name)); return value;} Idaligo.Error.checkArgumentAsArray = function(value, name) { Idaligo.Error.checkArgument(value, name); if (! Idaligo.Core.defined(value.length)) throw new Error(Idaligo.Error.MSG.ARGUMENT_MUST_BE_ARRAY(name)); return value;} Idaligo.Error.checkArgumentAsNumber = function(value, name) { Idaligo.Error.checkArgument(value, name); if (! Idaligo.Core.isNumber(value)) throw new Error(Idaligo.Error.MSG.ARGUMENT_MUST_BE_NUMBER(name)); return value; } Idaligo.Error.checkArgumentAsDate = function(value, name) { Idaligo.Error.checkArgument(value, name); if (! Idaligo.Core.isDate(value)) throw new Error(Idaligo.Error.MSG.ARGUMENT_MUST_BE_DATE(name)); return value; } Idaligo.Error.checkArgumentAsNotEmptyString = function(value, name) { Idaligo.Error.checkArgument(value, name); if (Idaligo.Core.emptyString(value)) throw new Error(Idaligo.Error.MSG.ARGUMENT_EMPTY_STRING(name)); return Idaligo.Core.trimString(value); } Idaligo.Error.checkElement = function(element, name) {if (! Idaligo.Core.defined(element)) throw new Error("Element \"" + name + "\" cannot be find."); else return element;} Idaligo.Geo = function() {}; Idaligo.Event = function(e) { var Pt = Idaligo.Geo.Pt; this.e = e; this.keyCode = e.keyCode; if (Idaligo.Agent.TYPE.IE) { this.target = e.toElement; this.source = e.srcElement; this.screenPt = new Pt(e.screenX, e.screenY); this.clientPt = new Pt(e.clientX, e.clientY); this.offsetPt = new Pt(e.offsetX, e.offsetY); } else if (Idaligo.Agent.TYPE.FF) { this.target = e.relatedTarget; this.source = e.target; this.screenPt = new Pt(e.screenX, e.screenY); this.clientPt = new Pt(e.clientX, e.clientY); this.offsetPt = new Pt(e.layerX, e.layerY); } else { throw new Error(Idaligo.Error.MSG.CLIENT_NOT_SUPPORTED); } }; Idaligo.Event.prototype.stopPropagation = function() { if (Idaligo.Core.defined(this.e.stopPropagation)) { this.e.stopPropagation(); } if (Idaligo.Core.defined(this.e.preventDefault)) { this.e.preventDefault(); } this.e.cancelBubble = true; this.e.resultValue = false; } Idaligo.Event.TYPE = {MOUSEUP:"mouseup", MOUSEDOWN:"mousedown", CLICK:"click", MOUSEMOVE:"mousemove", MOUSEOVER:'mouseover', MOUSEOUT:'mouseout', RESIZE:'resize', BLUR:'blur', FOCUS:'focus', KEYDOWN:'keydown', DOUBLECLICK:'doubleclick', CHANGE:'change', SCROLL:'scroll'}; Idaligo.Event.handle = function(holder, sender, event, handler) { if (Idaligo.Core.isundef(handler)) throw new Error(Idaligo.Error.MSG.ARGUMENT_UNDEFINED("handler")); var hook; if (Idaligo.Agent.TYPE.IE) {hook = function(e){return handler.call(holder, sender, new Idaligo.Event(e))}; sender.attachEvent("on" + event, hook);} else if (Idaligo.Agent.TYPE.FF) {hook = function(e){return handler.call(holder, sender, new Idaligo.Event(e));}; sender.addEventListener(event, hook, false);} else throw new Error(Idaligo.Error.MSG.CLIENT_NOT_SUPPORTED); return hook; } Idaligo.Event.unhandle = function(sender, event, hook) { if (Idaligo.Core.isundef(hook)) throw new Error(Idaligo.Error.MSG.ARGUMENT_UNDEFINED("hook")); if (Idaligo.Agent.TYPE.IE) sender.detachEvent("on" + event, hook); else if (Idaligo.Agent.TYPE.FF) sender.removeEventListener(event, hook, false); else throw new Error(Idaligo.Error.MSG.CLIENT_NOT_SUPPORTED); } Idaligo.Debug = function() {}; Idaligo.Debug.DUMP_MODE = {NONE:0, WITH_PROP:1, WITH_FUNC:2}; Idaligo.Debug.dump = function(smth, depth, mode) { if (! Idaligo.Core.defined(smth)) return ""; mode = Idaligo.Core.def(mode, Idaligo.Debug.DUMP_MODE.WITH_PROP); depth = Idaligo.Core.def(depth, 0); var tb = new Idaligo.TxBld(); Idaligo.Debug.dump_(smth, mode, depth, tb); var res = tb.toString(); if (Idaligo.Core.defined(Idaligo.Debug.dumper)) { Idaligo.Debug.dumper(res); } return res; } Idaligo.Debug.dump_ = function(smth, mode, depth, tb) { for (var i in smth) { try { var obj = eval("smth." + i); var v = "" + obj; if (Idaligo.Core.defined(obj)) { if (v.has("function") && (mode & Idaligo.Debug.DUMP_MODE.WITH_FUNC) === Idaligo.Debug.DUMP_MODE.WITH_FUNC) { tb.addLine(i + ": " + v); } else if (!v.has("function") && (mode & Idaligo.Debug.DUMP_MODE.WITH_PROP) === Idaligo.Debug.DUMP_MODE.WITH_PROP) { tb.addLine(i + ": " + v); } if (tb.level < depth) { Idaligo.Debug.dump_(obj, mode,depth, new Idaligo.TxBld(tb)); } } else { tb.addLine(i + ": [NULL]"); } } catch (e) { tb.addLine(i + ": [ERROR: " + e + "]"); } } } Idaligo.Debug.dumper = function(txt) {alert(txt);} Idaligo.Debug.trace = function(txt) {Idaligo.Debug.dumper(txt);} Idaligo.Debug.traceLn = function(txt) {Idaligo.Debug.trace(txt + "\r\n");} Idaligo.Debug.runTests = function(tests) {if (Idaligo.Core.isundef(tests, tests.length)) throw new Error("\"tests\" are expected to be an array of functions."); var p = 0; var f = 0; for(var i=0; i"; this.appendElement(text, makeItRoot_); } else if (Idaligo.Agent.TYPE.FF) { this.appendElement("input", makeItRoot_); if (Idaligo.Core.defined(attributes_)) { this.withAttribute("type", type); for (var index = 0; index < attributes_.length; index ++) { var attribute = attributes_[index]; this.withAttribute(attribute.n, attribute.v); } } } else { throw new Error(Idaligo.Error.MSG.CLIENT_NOT_SUPPORTED); } } catch (e) { throw new Error("Unable to create an INPUT element. Reason: " + e.toString()); } return this; } this.appendText = function(text) { Idaligo.Error.checkArgument(text, "text"); var newElement = document.createTextNode(text); _current.appendChild(newElement); return this; } this.startWith = function(element) { Idaligo.Error.checkArgument(element, "element"); _elements.push(_current); _current = element return this; } this.stepBack = function() { if (_elements.length > 0) { _current = _elements.pop(); } return this; } this.removeChildNodes = function() { Idaligo.Dom.removeChildNodes(_current); return this; } this.getRootElement = function() { if (_elements.length > 0) { return _elements[0]; } else { return _current; } } this.getCurrentElement = function() { return _current; } } Idaligo.Dom.Builder.createElement = function(name) { Idaligo.Error.checkArgumentAsNotEmptyString(name, "name"); var startWith = document.createElement(name); return new Idaligo.Dom.Builder(startWith); } Idaligo.Css = function() {} Idaligo.Css.toggleClass = function(className, yesNo) {return className + ((yesNo) ? '' : '_off');} Idaligo.Css.setVisible = function(elm, yesNo) {elm.style.visibility = ((yesNo) ? 'visible' : 'hidden');} Idaligo.Css.getPos = function(ctl, relative_) { relative_ = Idaligo.Core.def(relative_, false); var x = 0; var y = 0; do { var s = ctl.style; x += ctl.offsetLeft || 0; y += ctl.offsetTop || 0; x += parseInt(s.borderLeftWidth) || 0; y += parseInt(s.borderTopWidth) || 0; ctl = ctl.offsetParent; if (relative_ && (ctl.style.position == 'relative' || ctl.style.position == 'absolute')) { break; } } while (ctl); return new Idaligo.Geo.Pt(x, y); } Idaligo.Css.getScrollPos = function() { var pt = new Idaligo.Geo.Pt(document.documentElement.scrollLeft, document.documentElement.scrollTop); return pt;} Idaligo.Css.getClientSize = function() {var sz = new Idaligo.Geo.Pt(document.documentElement.clientWidth, document.documentElement.clientHeight); return sz;} Idaligo.Css.getDocSize = function() {var sz = new Idaligo.Geo.Pt(document.documentElement.scrollWidth, document.documentElement.scrollHeight); return sz;} Idaligo.Css.makePosAbs = function(ctl) {ctl.style.position = 'absolute';} Idaligo.Css.makePosRel = function(ctl) {ctl.style.position = 'relative';} Idaligo.Css.makePosFixed = function(ctl) {ctl.style.position = 'fixed';} Idaligo.Css.setPos = function(ctl, pt) {ctl.style.left = pt.x + 'px'; ctl.style.top = pt.y + 'px';} Idaligo.Css.shift = function(ctl, by) {var pt = Idaligo.Css.getPos(ctl); pt.add(by); Idaligo.Dom.setPos(ctl, pt);} Idaligo.Css.setSize = function(ctl, sz) {var s = ctl.style; s.width = sz.x + 'px'; s.height = sz.y + 'px';} Idaligo.Css.getSize = function(ctl) {return new Idaligo.Geo.Pt(ctl.clientWidth, ctl.clientHeight);} Idaligo.Css.setDisplay = function(ctl, blockNone) {ctl.style.display = (blockNone) ? 'block' : 'none';} Idaligo.UI = function () {} Date.prototype.getHour = function() { var hours = this.getHours() % 12; return (hours == 0) ? 12 : hours; } Date.prototype.getAmPm = function() { return (this.getHours() < 12) ? 'AM' : 'PM'; } Date.prototype.addSecond = function(sec) {return new Date(this.getTime() + sec * Idaligo.Time.STEP.SEC);} Date.prototype.addMinute = function(min) {return new Date(this.getTime() + min * Idaligo.Time.STEP.MIN);} Date.prototype.addHour = function(hr) {return new Date(this.getTime() + hr * Idaligo.Time.STEP.HOUR);} Date.prototype.addDay = function(day) {return new Date(this.getTime() + day * Idaligo.Time.STEP.DAY);} Date.prototype.addWeek = function(wk) {return new Date(this.getTime() + wk * Idaligo.Time.STEP.WEEK);} Date.prototype.date = function() { return new Date(this.getFullYear(), this.getMonth(), this.getDate()); } Date.prototype.getDateSuffix = function() { var r = this.getDate(); if (r == 11 || r == 12 || r == 13) return 'TH'; else { r = r % 10; if (r > 3) return 'TH'; else if (r > 2) return 'RD'; else if (r > 1) return 'ND'; else if (r > 0) return 'ST'; else return 'TH';}} Date.prototype.addMonth = function(n) { var date = this.getDate(); var month = this.getMonth() + n; var year = this.getFullYear(); var hour = this.getHours(); var min = this.getMinutes(); var sec = this.getSeconds(); var msec = this.getMilliseconds(); var maxDate = new Date(year, month + 1, 1).addDay(-1).getDate(); if (date > maxDate) date = maxDate; return new Date(year, month, date, hour, min, sec, msec); } Idaligo.Time = function() {}; Idaligo.Time.SCALE = {SEC:0, MIN:1, HOUR:2, DAY:3, WEEK:4, MONTH:5, YEAR:6}; Idaligo.Time.STEP = {SEC:1000, MIN:60000, HOUR:3600000, DAY:86400000, WEEK:604800000}; Idaligo.Time.monthShortNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; Idaligo.Time.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; Idaligo.Core.NameValues = function() { var keys = new Array(); var values = new Array(); this.indexOf = function(key) { Idaligo.Error.checkArgument(key, "key"); var found = -1; for (var index = 0; index < keys.length; index ++) { if (keys[index] == key) { found = index; break; } } return found; } this.findValues = function(key) { Idaligo.Error.checkArgument(key, "key"); var found = this.indexOf(key); if (found < 0) { return null; } else { return values[found]; } } this.findFirst = function(key) { Idaligo.Error.checkArgument(key, "key"); var found = this.findValues(key); if (Idaligo.Core.defined(found)) { if (found.length < 0) { return null; } else { return found[0]; } } else { return null; } } this.add = function(key, value) { Idaligo.Error.checkArgument(key, "key"); var found = this.findValues(key); if (Idaligo.Core.defined(value)) { if (Idaligo.Core.defined(found)) { found.push(value); } else { keys.push(key); found = new Array(); found.push(value); values.push(found); } } else { // NULL instead of some value, // in this case clear the array of old values or just create an empty array if (Idaligo.Core.defined(found)) { while (found.length > 0) { found.pop(); } } else { keys.push(key); found = new Array(); values.push(found); } } } this.walkThroughWhile = function(action) { Idaligo.Error.checkArgument(action, "action"); for (var keyIndex = 0; keyIndex < keys.length; keyIndex ++) { var key = keys[keyIndex]; var found = this.findValues(key); if (! Idaligo.Core.defined(found)) throw new Error("Key \"" + key + "\" doesn't have an associated array of values."); if (! action(key, found)) { break; } } } this.clone = function() { var result = new Idaligo.Core.NameValues(); this.walkThroughWhile(function(key, values) { for (var index = 0; index < values.length; index ++) { var value = values[index]; result.add(key, value); } return true; }); return result; } } Idaligo.Core.QueryString = function(values_) { var _values = Idaligo.Core.def(values_, new Idaligo.Core.NameValues()); this.add = function(key, value) { Idaligo.Error.checkArgument(key, "key"); Idaligo.Error.checkArgument(value, "value"); _values.add(key, value); } this.addNull = function(key, value) { Idaligo.Error.checkArgument(key, "key"); _values.add(key, null); } this.addBoolean = function(key, value) { Idaligo.Error.checkArgument(key, "key"); Idaligo.Error.checkArgument(value, "value"); _values.add(key, ((value) ? 1 : 0)); } this.addGLatLong = function(key, value) { Idaligo.Error.checkArgument(key, "key"); Idaligo.Error.checkArgument(value, "value"); _values.add(key + "lt", value.lat()); _values.add(key + "ln", value.lng()); } this.addDate = function(key, value) { Idaligo.Error.checkArgument(key, "key"); Idaligo.Error.checkArgument(value, "value"); _values.add(key, (value.getMonth() + 1) + "/" + value.getDate() + "/" + value.getFullYear() + " " + value.getHours() + ":" + value.getMinutes() + ":" + value.getSeconds()); } this.toString = function() { var result = ""; var notFirst = false; _values.walkThroughWhile(function(key, values) { if (notFirst) { result += "&"; } else { notFirst = true; } if (values[0] != null) { result += key + "=" + encodeURI(values[0]); for (var index = 1; index < values.length; index ++) { result += "," + encodeURI(values[index]); } } else { result += key + "="; } return true; }); return result; } this.clone = function() { return new Idaligo.Core.QueryString(_values.clone()) } } Idaligo.Core.QueryString.parse = function(queryString) { Idaligo.Error.checkArgument(queryString, "queryString"); if (Idaligo.Core.emptyString(queryString)) { return new Idaligo.Core.QueryString(); } else { var values = new Idaligo.Core.NameValues(); var tokens = queryString.split("&"); if (Idaligo.Core.defined(tokens) && tokens.length > 0) { for (var index = 0; index < tokens.length; index ++) { var token = tokens[index]; var keyValue = token.split("="); if (Idaligo.Core.defined(keyValue)) { if (keyValue.length > 0) { var key = keyValue[0]; if (keyValue.length > 1) { var value = decodeURIComponent(keyValue[1]); values.add(key, value); Idaligo.Debug.traceLn(key + ": " + value); } else { Idaligo.Debug.traceLn(key + ": NULL"); values.add(key, null); } } } } } return new Idaligo.Core.QueryString(values); } }/// Idaligo.Geo.Rg = function(f, t){this.f=f, this.t=t;}; Idaligo.Geo.Rg.prototype.length = function() {if (this.hasFrom() && this.hasTo()) return this.t - this.f; else throw new Error(Idaligo.Error.MSG.INVALID_OPERATION);} Idaligo.Geo.Rg.prototype.isWithin = function(v) {return ((this.hasFrom()) ? v >= this.f : true) && ((this.hasTo()) ? v < this.t : true);} Idaligo.Geo.Rg.prototype.hitAbs = function(v) {if (v < this.f) return -this.f+v; else if (v >= this.t) return v-this.t; else return 0; } Idaligo.Geo.Rg.prototype.hitRgAbs = function(rg) {var f=0; var t=0; if (rg.f < this.f) f = -this.f + rg.f; else if(rg.f >= this.t) f = rg.f - this.t; if (rg.t < this.f) t = -this.f + rg.t; else if (rg.t >= this.t) t=rg.t - this.t; return new Idaligo.Geo.Rg(f, t);} Idaligo.Geo.Rg.prototype.trim = function(n) {if (this.hasFrom() && n < this.f) return this.f; else if (this.hasTo() && n > this.t) return this.t; else return n;} Idaligo.Geo.Rg.prototype.toString = function() {return "f: " + this.f + " w: " + (this.t - this.f);} Idaligo.Geo.Rg.prototype.hasFrom = function() {return Idaligo.Core.defined(this.f);} Idaligo.Geo.Rg.prototype.hasTo = function() {return Idaligo.Core.defined(this.t);} Idaligo.Geo.Rg.prototype.hasAll = function() {return this.hasTo() && this.hasFrom();} Idaligo.Geo.Rg.createUndefined = function() {return new Idaligo.Geo.Rg(null, null);} Idaligo.Geo.Pt = function(x, y) {this.x = x; this.y = y;} Idaligo.Geo.Pt.prototype.add = function(v) {this.x += v.x; this.y += v.y;return this;} Idaligo.Geo.Pt.prototype.inverse = function() {this.x = -this.x; this.y = -this.y; return this;} Idaligo.Geo.Pt.prototype.toString = function() {return "x: " + this.x + ", y: " + this.y; } Idaligo.Geo.Pt.prototype.isZero = function() {return this.x === 0 && this.y === 0;} Idaligo.Geo.Pt.prototype.clone = function () {return new Idaligo.Geo.Pt(this.x, this.y);} Idaligo.Geo.Pt.prototype.getLen = function() {return Math.sqrt(this.x * this.x + this.y * this.y);} Idaligo.Geo.Pt.prototype.withY = function(y) {this.y = y; return this;} Idaligo.Geo.Pt.prototype.withX = function(x) {this.x = x; return this;} Idaligo.Geo.Pt.prototype.withXround = function(x) {this.x = Math.round(x); return this;} Idaligo.Geo.Pt.prototype.withYround = function(y) {this.y = Math.round(y); return this;} Idaligo.Geo.Pt.prototype.module = function() {return Math.sqrt(this.x * this.x + this.y * this.y);} Idaligo.Geo.Pt.prototype.absX = function() {return (this.x < 0) ? - this.x : this.x;} Idaligo.Geo.Pt.prototype.absY = function() {return (this.y < 0) ? - this.y : this.y;} Idaligo.Geo.Pt.prototype.addX = function(dx) {this.x += dx; return this;} Idaligo.Geo.Pt.prototype.addY = function(dy) {this.y += dy; return this;} Idaligo.Geo.Pt.prototype.mult = function(c) {this.x *= c; this.y *= c; return this;} Idaligo.Geo.Pt.subtract = function(from, what) {return new Idaligo.Geo.Pt(from.x - what.x, from.y - what.y);} Idaligo.Geo.Pt.inverse = function(v) {return new Idaligo.Geo.Pt(-v.x, -v.y);} Idaligo.Geo.Pt.multCoord = function(v1, v2) {return new Idaligo.Geo.Pt(v1.x * v2.x, v1.y * v2.y);} Idaligo.Geo.Pt.add = function(v1, v2) {return new Idaligo.Geo.Pt(v1.x + v2.x, v1.y + v2.y);} Idaligo.Geo.Pt.zero = function() {return new Idaligo.Geo.Pt(0,0);} Idaligo.Geo.Ang = function () {}; Idaligo.Geo.Ang.DIR = {RIGHT:0, UP:1, LEFT:2, DOWN:3}; Idaligo.Geo.Ang.dir2vect = [new Idaligo.Geo.Pt(1, 0), new Idaligo.Geo.Pt(0, -1), new Idaligo.Geo.Pt(-1, 0), new Idaligo.Geo.Pt(0, 1)]; Idaligo.Geo.Ang.nextDirCCW = function(d){if (d > 2) return 0; else return d + 1;} Idaligo.Geo.Ang.nextDirCW = function(d){if (d < 1) return 3; else if (d > 3) return 3; else return d - 1;} Idaligo.Geo.Rc = function(l, t, r, b) {this.l=l;this.t=t;this.r=r;this.b=b;} Idaligo.Geo.Rc.prototype.moveBy = function(v) {this.l += v.x; this.r += v.x; this.b += v.y; this.t += v.y;} Idaligo.Geo.Rc.prototype.w = function() {return this.r - this.l;} Idaligo.Geo.Rc.prototype.h = function() {return this.b - this.t;} Idaligo.Geo.Rc.prototype.toString = function() {return "l: " + this.l + " t: " + this.t + " r: " + this.r + " (" + (this.r - this.l) + ") b: " + this.b + " (" + (this.b - this.t) + ")"; } Idaligo.Geo.Rc.prototype.hitPtRel = function(pt) {var x=0;var y=0;var w=this.w();var h=this.h(); if (pt.x >= this.r) x = parseInt((pt.x - this.l) / w); else if (pt.x < this.l) x = - parseInt((this.r - pt.x) / w); if (pt.y >= this.b) y = parseInt((pt.y - this.t) / h); else if (pt.y < this.t) y = - parseInt((this.b - pt.y) / h); return new Idaligo.Geo.Pt(x, y);} Idaligo.Geo.Rc.prototype.hitPtAbs = function(pt) {var x=0;var y=0;var w=this.w();var h=this.h(); if (pt.x >= this.r) x = pt.x - this.r; else if (pt.x < this.l) x = - this.l + pt.x; if (pt.y >= this.b) y = this.b - pt.y; else if (pt.y < this.u) y = - this.u + pt.y; return new Idaligo.Geo.Pt(x, y);} Idaligo.Geo.Rc.prototype.hitRcAbs = function(rc) {var l=0;var r=0;var t=0;var b=0;if(rc.r>=this.r) r=rc.r-this.r; else if(rc.r=this.r) l=rc.l-this.r; else if(rc.l=this.b) b=rc.b-this.b; else if(rc.b=this.b) t=rc.t-this.b; else if(rc.t this.r - sz.x) x = this.r - sz.x - at.x; else if (at.x + by.x < this.l) x = this.l - at.x; if (at.y + by.y > this.b - sz.y) y = this.b - sz.y - at.y; else if (at.y + by.y < this.t) y = this.t - at.y; return new Idaligo.Geo.Pt(x, y);} Idaligo.Geo.Gd = function(smth) {this.value = smth;this.t=null;this.b=null;this.l=null;this.r=null;} Idaligo.Geo.Gd.movers = { prev: [function(){return this.l;}, function(){return this.b;}, function(){return this.r;}, function(){return this.t;}] , next: [function(){return this.r;}, function(){return this.t;}, function(){return this.l;}, function(){return this.b;}] } Idaligo.Geo.Gd.prototype.prev = function (dir) {return Idaligo.Geo.Gd.movers.prev[dir].call(this);} Idaligo.Geo.Gd.prototype.next = function (dir) {return Idaligo.Geo.Gd.movers.next[dir].call(this);} Idaligo.Geo.Gd.prototype.toString = function() {return this.value.toString();} Idaligo.Geo.Gd.prototype.walkAround = function(dir, action) { var cr = this; do { action(cr); cr = cr.next(dir); } while (cr !== this); } Idaligo.Geo.Gd.prototype.width = function() {var n = 0; this.walkAround(Idaligo.Geo.Ang.DIR.RIGHT, function() {n ++;}); return n;} Idaligo.Geo.Gd.prototype.height = function() {var n = 0; this.walkAround(Idaligo.Geo.Ang.DIR.UP, function() {n ++;}); return n;} Idaligo.Geo.Gd.prototype.walkThrough = function(action) { this.walkAround(Idaligo.Geo.Ang.DIR.LEFT, function(outer) { outer.walkAround(Idaligo.Geo.Ang.DIR.DOWN, function(inner) { action(inner); }); }); } Idaligo.Geo.Gd.prototype.walkBy = function(by, action) { var cur = this; if (by.x > 0) { for (var i = 0; i < by.x; i ++) { cur = cur.r; action(cur, Idaligo.Geo.Ang.DIR.RIGHT); } } else if (by.x < 0) { for (var i = 0; i < - by.x; i ++) { cur = cur.l; action(cur, Idaligo.Geo.Ang.DIR.LEFT); } } if (by.y > 0) { for (var i = 0; i < by.y; i ++) { cur = cur.b; action(cur, Idaligo.Geo.Ang.DIR.DOWN); } } else if (by.y < 0) { for (var i = 0; i < -by.y; i ++) { cur = cur.t; action(cur, Idaligo.Geo.Ang.DIR.UP); } } return cur; } Idaligo.Geo.Gd.prototype.dump = function() { var tb = new Idaligo.TxBld(); tb.add(""); var r = this; do { tb.add(""); var c = r; do { tb.add(""); c = c.r; } while (c !== r); tb.add(""); r = r.b; } while (r !== this); tb.add("
" + c.t.value + "
" + c.l.value + "" + c.value + "" + c.r.value + "
" + c.b.value + "
"); return tb.toString(); } Idaligo.Geo.Gd.create = function(nx, ny, contentMaker) { if (nx <= 0) throw new Error("\"nx\" must be greater than 0."); if (ny <= 0) throw new Error("\"ny\" must be greater than 0."); var fr = null; // first row, which is going to be result of the function var prc = null; // previous row column for (var i = 0; i < ny; i++) { var fc = null; // first column in row var pc = null; // previous column for (var j = 0; j < nx; j++) { var gd = new Idaligo.Geo.Gd(contentMaker(i, j)); if (pc === null) { fc = gd; pc = gd; } else { gd.l = pc; pc.r = gd; } if (prc !== null) { gd.t = prc; prc.b = gd; prc = prc.r; } pc = gd; } // here we have fc and pc, where pc points to the last column, we're gonna create a loop fc.l = pc; pc.r = fc; if (prc === null) {prc = fc;fr = fc;} else {prc = prc.b;} } // fr/prc - first/last row we're gonna create a loop var cr = fr; do { cr.t = prc; prc.b = cr; cr = cr.r; prc = prc.r; } while (cr !== fr); return fr; } Idaligo.Geo.Gd.prototype.appendSE = function(nx, contentMaker) { if (nx <= 0) throw new Error("\"n\" must be greater than 0."); var i = 0; var prc = null; this.walkAround(Idaligo.Geo.Ang.DIR.DOWN, function(node) { //debugger; var pc = node; for (var j = 0; j < nx; j++) { var gd = new Idaligo.Geo.Gd(contentMaker(i, j)); gd.l = pc; gd.r = pc.r; pc.r = gd; pc = gd; if (prc != null) {gd.t = prc; prc.b = gd; prc = prc.r;} } pc.r.l = pc; // linking the very first element to the newly created last one prc = node.r; i++; }); var cr = this.r; do { cr.t = prc; prc.b = cr; prc = prc.r; cr = cr.r } while (cr.t == null); } /// /// /// Idaligo.UI.ScanPane = function ( elmRoot , paneSz , tileConfigurations , tileContentCreator , tileModifier , allowed , zoom ) { Idaligo.Dom.removeChildNodes(elmRoot); this.configurations = tileConfigurations; this.verticalScan = allowed.vertical; this.horizontalScan = allowed.horizontal; //this.move = new Idaligo.Anima.MoveBy(); this.zoom = zoom; this.bodyAt = new Idaligo.Geo.Pt(0, 0); this.boundRc = Idaligo.Geo.Rc.createZero(); this.mover = new Idaligo.Anima.MoveBy(this, this._moverBy, 40); elmRoot.style.position = 'relative'; var elmScoller = document.createElement("DIV"); elmScoller.style.overflow = 'hidden'; elmScoller.style.position = 'relative'; elmScoller.style.height = paneSz.y + 'px'; var elmBody = document.createElement("DIV"); elmBody.style.position = 'relative'; if (paneSz.x > 0) { elmBody.style.width = paneSz.x + 'px'; } elmBody.style.backgroundColor = 'Red'; Idaligo.Css.setSize(elmBody, new Idaligo.Geo.Pt(1,1)); this.elmBody = elmBody this.elmScroller = elmScoller; this.tileContentCreator = tileContentCreator; this.tileModifier = tileModifier; elmScoller.appendChild(elmBody); elmRoot.appendChild(elmScoller); this.elmRoot = elmRoot; // getting actual size of the scan window this.paneSz = Idaligo.Css.getSize(elmScoller); // creating a grid for each zoom level var me = this; var tileSz = this.configurations[zoom].tileSz; var nx = Math.ceil(this.paneSz.x / tileSz.x) + ((this.horizontalScan) ? 1 : 0); var ny = Math.ceil(this.paneSz.y / tileSz.y) + ((this.verticalScan) ? 1 : 0); this.grid = Idaligo.Geo.Gd.create(nx, ny, function(i, j) { return me.createTile(i, j, tileSz, zoom); }); this._fixZOrder(); this._mouseTracking = false; this._mouseTracker = document; Idaligo.Event.handle(this, elmRoot, Idaligo.Event.TYPE.MOUSEDOWN, this._mouseDown); Idaligo.Event.handle(this, this._mouseTracker, Idaligo.Event.TYPE.MOUSEUP, this._mouseUp); Idaligo.Event.handle(this, window, Idaligo.Event.TYPE.RESIZE, this._windowResize); if (Idaligo.Agent.TYPE.IE) elmRoot.onselectstart = function(){return false;} } Idaligo.UI.ScanPane.prototype.createTile = function(i, j, tileSz, zoom) { var tile = this.tileContentCreator(new Idaligo.Geo.Pt(j, i), tileSz.clone(), zoom); var elmTile = tile.getTileElement(); var pt = new Idaligo.Geo.Pt(j * tileSz.x, i * tileSz.y); this.elmBody.appendChild(elmTile); Idaligo.Css.makePosAbs(elmTile) Idaligo.Css.setSize(elmTile, tileSz); Idaligo.Css.setPos(elmTile, pt); Idaligo.Css.setVisible(elmTile, false); return {element:elmTile, tile:tile, pt:pt, idx:new Idaligo.Geo.Pt(j,i), zoom:zoom}; } Idaligo.UI.ScanPane.prototype._mouseDown = function(s, e) { this.last = e.screenPt; this.mover.stop(); if (Idaligo.Core.defined(this._mouseMoveHook)) { Idaligo.Event.unhandle(this._mouseTracker, Idaligo.Event.TYPE.MOUSEMOVE, this._mouseMoveHook); this._mouseMoveHook = null; } this._mouseMoveHook = Idaligo.Event.handle(this, this._mouseTracker, Idaligo.Event.TYPE.MOUSEMOVE, this._mouseMove); } Idaligo.UI.ScanPane.prototype._mouseUp = function(s, e) { var that = this; this._mouseTracking = true; // stop in a while if the mouse is still window.setTimeout(function(){that._mouseStopTracking();}, 30); } Idaligo.UI.ScanPane.prototype._mouseStopTracking = function() { this._mouseTracking = false; if (Idaligo.Core.defined(this._mouseMoveHook)) { Idaligo.Event.unhandle(this._mouseTracker, Idaligo.Event.TYPE.MOUSEMOVE, this._mouseMoveHook); this._mouseMoveHook = null; } } Idaligo.UI.ScanPane.prototype._mouseMove = function(s, e) { var now = e.screenPt; var mouseOffset = Idaligo.Geo.Pt.subtract(now, this.last); if (this._mouseTracking) { // stop tracking this._mouseStopTracking(); // move mechanically (by inertia) this.moveBy(mouseOffset.mult(10)); } else { this.jumpBy(mouseOffset); } this.last = now; } Idaligo.UI.ScanPane.prototype.addStillElement = function(elmControl, pt) { Idaligo.Css.makePosAbs(elmControl); elmControl.style.zIndex = 50; if (Idaligo.Core.defined(pt)) { Idaligo.Css.setPos(elmControl, pt); } this.elmRoot.insertBefore(elmControl, this.elmScroller); } Idaligo.UI.ScanPane.prototype.jumpBy = function(by) { if (! this.verticalScan) by.y = 0; if (! this.horizontalScan) by.x = 0; // top left corner of the scan panel if (! this.boundRc.isZero()) { var beforeRc = new Idaligo.Geo.Rc.createByPtSz(Idaligo.Geo.Pt.inverse(this.bodyAt), this.paneSz); var afterRc = new Idaligo.Geo.Rc.createByPtSz(Idaligo.Geo.Pt.add(this.bodyAt, by).inverse(), this.paneSz); var afterHit = afterRc.hitRcAbs(this.boundRc); if (afterHit.l == 0 && by.x > 0) by.x = (beforeRc.l > this.boundRc.l) ? beforeRc.l - this.boundRc.l : 0; if (afterHit.r == 0 && by.x < 0) by.x = (beforeRc.r < this.boundRc.r) ? beforeRc.r - this.boundRc.r : 0; if (afterHit.t == 0 && by.y > 0) by.y = (beforeRc.t > this.boundRc.t) ? beforeRc.t - this.boundRc.t : 0; if (afterHit.b == 0 && by.y < 0) by.y = (beforeRc.b > this.boundRc.b) ? beforeRc.b - this.boundRc.b : 0; } if (by.isZero()) return false; var at = this.bodyAt.add(by); var paneAt = Idaligo.Geo.Pt.inverse(at); // to be used in anonymous function var zoom = this.zoom; var grid = this.grid; var tileSz = this.configurations[zoom].tileSz; var tileModifier = this.tileModifier; // check if the coner is outside the safe box var hit = Idaligo.Geo.Rc.createByPtSz(grid.value.pt, tileSz).hitPtRel(paneAt); if (! hit.isZero()) { grid = grid.walkBy(hit, function(outerGd, outerDir) { var innerDir = Idaligo.Geo.Ang.nextDirCCW(outerDir); if (outerDir == Idaligo.Geo.Ang.DIR.RIGHT || outerDir == Idaligo.Geo.Ang.DIR.DOWN) { outerGd.walkAround(innerDir, function(innerGd) { var prevGd = innerGd.prev(outerDir); var lastGd = prevGd.prev(outerDir); var vect = Idaligo.Geo.Ang.dir2vect[outerDir]; prevGd.value.pt = Idaligo.Geo.Pt.add(lastGd.value.pt, Idaligo.Geo.Pt.multCoord(tileSz, vect)); prevGd.value.idx = Idaligo.Geo.Pt.add(lastGd.value.idx, vect); tileModifier(prevGd.value.tile, prevGd.value.idx.clone(), prevGd.value.pt.clone(), zoom); Idaligo.Css.setPos(prevGd.value.element, prevGd.value.pt); }); } else { outerGd.walkAround(innerDir, function(innerGd) { var prevGd = innerGd.prev(outerDir); var vect = Idaligo.Geo.Ang.dir2vect[outerDir]; innerGd.value.pt = Idaligo.Geo.Pt.add(prevGd.value.pt, Idaligo.Geo.Pt.multCoord(tileSz, vect)); innerGd.value.idx = Idaligo.Geo.Pt.add(prevGd.value.idx, vect); tileModifier(innerGd.value.tile, innerGd.value.idx.clone(), innerGd.value.pt.clone(), zoom); Idaligo.Css.setPos(innerGd.value.element, innerGd.value.pt); }); } }); this._fixZOrder(); } // set a new start grid element and its position this.grid = grid; Idaligo.Css.setPos(this.elmBody, at); return true; }; Idaligo.UI.ScanPane.prototype._fixZOrder = function() { // fixing z-order, starting with the most right tile, going vertically this.grid.l.walkAround(Idaligo.Geo.Ang.DIR.UP, function(row) { var zIndex = 0; // for each row going horizontally row.walkAround(Idaligo.Geo.Ang.DIR.LEFT, function(cell) { cell.value.tile.elmTile.style.zIndex = zIndex; zIndex ++; }); }); } Idaligo.UI.ScanPane.prototype.moveBy = function(by) { //Idaligo.Debug.traceLn('****************'); //Idaligo.Debug.traceLn('Rect ' + this.boundRc); //Idaligo.Debug.traceLn('Body at: ' + this.bodyAt) this.mover.destPt.add(this.mover.curPt.inverse()); this.mover.curPt = new Idaligo.Geo.Pt(0, 0); var at = this.bodyAt.clone().add(this.mover.destPt); //Idaligo.Debug.traceLn('Before: ' + this.mover.destPt); if (! this.boundRc.isZero()) { //Idaligo.Debug.traceLn('Original: ' + by); var correctedBy = this.boundRc.byInBoundaries(Idaligo.Geo.Pt.inverse(at), Idaligo.Geo.Pt.inverse(by), this.paneSz).inverse(); //Idaligo.Debug.traceLn('Corrected: ' + correctedBy); this.mover.destPt.add(correctedBy); //Idaligo.Debug.traceLn('After: ' + this.mover.destPt); } else { this.mover.destPt.add(by); } this.mover.start(); } Idaligo.UI.ScanPane.prototype._moverBy = function(by) { return this.jumpBy(by); } Idaligo.UI.ScanPane.prototype.onResize = null; Idaligo.UI.ScanPane.prototype._windowResize = function() { if (! this._fixingResize) { this._fixingResize = true; var me = this; window.setTimeout(function() { me._fixResize(); me._fixingResize = false; if (Idaligo.Core.defined(me.onResize)) { me.onResize(); } }, 1000); } } Idaligo.UI.ScanPane.prototype._fixResize = function() { var me = this; var zoom = this.zoom; var tileSz = this.configurations[zoom].tileSz; var paneSzBefore = this.paneSz.clone(); var paneSzAfter = this.paneSz = Idaligo.Css.getSize(this.elmScroller); var dx = paneSzAfter.x - this.grid.width() * tileSz.x; if (dx > 0) { var nx = Math.ceil(dx / tileSz.x) + ((this.horizontalScan) ? 1 : 0); var grid = this.grid.l; grid.appendSE(nx, function(i, j) { i = i + grid.value.idx.y; j = j + grid.value.idx.x + 1; var result = me.createTile(i, j, tileSz, zoom); me.tileModifier(result.tile, result.idx.clone(), result.pt.clone(), zoom); return result; }); } else if (dx < 0) { } } Idaligo.UI.ScanPane.prototype.getTileSz = function() { return this.configurations[this.zoom].tileSz; } Idaligo.UI.ScanPane.prototype.getScale = function() { return this.configurations[this.zoom].scale; } Idaligo.UI.ScanPane.prototype.getCurrentPt = function() { return this.bodyAt.clone().inverse(); } Idaligo.UI.ScanPane.prototype.getVisibleHRg = function() { var at = this.getCurrentPt(); return new Idaligo.Geo.Rg(at.x, at.x + this.paneSz.x); } /// /// /// Idaligo.UI.TimeLine = function(elmRoot, startDt, zoom, handler) { Idaligo.Error.checkArgument(elmRoot, "elmRoot"); var height = 60; var self = this; this.clickHandler = handler; this.pane = new Idaligo.UI.ScanPane ( elmRoot , new Idaligo.Geo.Pt(0, height) , [ {tileSz:new Idaligo.Geo.Pt(50, height), scale:Idaligo.Time.STEP.HOUR} , {tileSz:new Idaligo.Geo.Pt(Idaligo.UI.TimeLine.Tile.width, height), scale:Idaligo.Time.STEP.DAY} ] , function(idx, sz, zm) {return self._createTile.call(self, idx, sz, zm);} , function(tile, idx, pt, zm) {return self._modifyTile.call(self, tile, idx, pt, zm);} , {vertical:false, horizontal:true} , zoom ); //this.pane.addStillElement(this._createControls(), new Idaligo.Geo.Pt(2, 2)); this.pane.addStillElement(this._createButton(true), new Idaligo.Geo.Pt(4, 2)); this.elmRightBtn = this._createButton(false); this.pane.addStillElement(this.elmRightBtn, new Idaligo.Geo.Pt(this.pane.paneSz.x - 6 - 20, 2)); this.tm = { zero: startDt.getTime() , dataTmRg: Idaligo.Geo.Rg.createUndefined() , allowedTmRg: Idaligo.Geo.Rg.createUndefined() }; this.onDataRangeChanged = null; } Idaligo.UI.TimeLine.ZOOM = {DAY: 0, MONTH:1} Idaligo.UI.TimeLine.barSz = new Idaligo.Geo.Pt(0, 10); Idaligo.UI.TimeLine.CSS = {Control:'idgTmlCtl', Tile:'idgTmlTile', Bar:'idgTmlBar', Button:'idgTmlBtn', Label:'idgTmlLb'}; Idaligo.UI.TimeLine.folderOfPics = 'pics'; Idaligo.UI.TimeLine.visibleMarginWidth = 40; Idaligo.UI.TimeLine.prototype.initialize = function(time, zoom) { var me = this; var grid = this.pane.grid; var config = this.pane.configurations[zoom]; //debugger; if (Idaligo.Core.defined(time.at)) { this.tm.current = time.at.getTime(); } if (Idaligo.Core.defined(time.from)) { this.tm.dataTmRg.f = time.from.getTime(); } else {this.tm.dataTmRg.f = null; this.tm.dataTmRg.t = null;} if (Idaligo.Core.defined(time.to)) { this.tm.dataTmRg.t = time.to.getTime(); } else {this.tm.dataTmRg.f = null; this.tm.dataTmRg.t = null;} if (Idaligo.Core.defined(time.max)) this.tm.allowedTmRg.t = time.max.getTime(); if (Idaligo.Core.defined(time.min)) this.tm.allowedTmRg.f = time.min.getTime(); this.pane.boundRc = Idaligo.UI.TimeLine.calcBoundaries(this.pane.paneSz, config.tileSz, config.scale, this.tm.zero, this.tm.allowedTmRg); this.pane.onResize = function() { var config = me.pane.configurations[me.pane.zoom]; me.pane.boundRc = Idaligo.UI.TimeLine.calcBoundaries(me.pane.paneSz, config.tileSz, config.scale, me.tm.zero, me.tm.allowedTmRg); Idaligo.Css.setPos(me.elmRightBtn, new Idaligo.Geo.Pt(me.pane.paneSz.x - 6 - 20, 2)); }; grid.walkThrough(function(node) { me._modifyTile(node.value.tile, node.value.idx, node.valueOf.pt, zoom); }); if (Idaligo.Core.declared(time.from) || Idaligo.Core.declared(time.to)) { this.makeVisible(this.tm.dataTmRg); if (Idaligo.Core.defined(this.onDataRangeChanged)) { this.onDataRangeChanged(this.tm.dataTmRg); } } } Idaligo.UI.TimeLine.prototype._createButton = function(isLeft) { var elmButton = document.createElement('DIV'); elmButton.className = Idaligo.Css.toggleClass(Idaligo.UI.TimeLine.CSS.Button, false); elmButton.style.padding = parseInt((this.pane.paneSz.y - 20)/2) + 'px 4px'; var elmImg = document.createElement('IMG'); elmButton.appendChild(elmImg); if (isLeft) { elmButton.title = 'Backward'; elmImg.src = Idaligo.UI.TimeLine.folderOfPics + '/back_ar.gif'; Idaligo.Event.handle(this, elmButton, Idaligo.Event.TYPE.CLICK, function() {this.pane.moveBy(new Idaligo.Geo.Pt(-this.pane.paneSz.x, 0));}); } else { elmButton.title = 'Forward'; elmImg.src = Idaligo.UI.TimeLine.folderOfPics + '/forw_ar.gif'; Idaligo.Event.handle(this, elmButton, Idaligo.Event.TYPE.CLICK, function() {this.pane.moveBy(new Idaligo.Geo.Pt(this.pane.paneSz.x, 0));}); } Idaligo.Event.handle(this, elmButton, Idaligo.Event.TYPE.MOUSEOVER, function(s, e) {s.className = Idaligo.Css.toggleClass(Idaligo.UI.TimeLine.CSS.Button, true);}); Idaligo.Event.handle(this, elmButton, Idaligo.Event.TYPE.MOUSEOUT, function(s, e) {s.className = Idaligo.Css.toggleClass(Idaligo.UI.TimeLine.CSS.Button, false);}); return elmButton; } Idaligo.UI.TimeLine.calcBoundaries = function(paneSz, tileSz, scale, zeroTm, allowedTmRg) { var l = (allowedTmRg.hasFrom()) ? (- paneSz.x - tileSz.x * (zeroTm - allowedTmRg.f) / scale) : 0; var r = (allowedTmRg.hasTo()) ? (paneSz.x + tileSz.x * (allowedTmRg.t - zeroTm) / scale) : 0; return new Idaligo.Geo.Rc(l, 0, r, 0); } Idaligo.UI.TimeLine.createBar = function() { var elmBar = document.createElement('DIV'); Idaligo.Css.makePosAbs(elmBar); elmBar.className = Idaligo.UI.TimeLine.CSS.Bar; Idaligo.Css.setSize(elmBar, Idaligo.UI.TimeLine.barSz.withX(0)); return elmBar; } Idaligo.UI.TimeLine.initializeBar = function(elmBar, tmRg, dataTmRg, tileSz) { var scale = tmRg.length(); // only beginning var hit = tmRg.hitRgAbs(dataTmRg); var xfk = (hit.f == 0) ? (dataTmRg.f - tmRg.f) / scale : 0; var xtk = (hit.t == 0) ? 1 - (tmRg.t - dataTmRg.t) / scale : ((hit.t > 0) ? ((hit.f > 0) ? 0 : 1) : 0); if (xfk == 0 && xtk == 0) { Idaligo.Css.setVisible(elmBar, false); } else { Idaligo.Css.setVisible(elmBar, true); var xf = Math.round(tileSz.x * xfk); var xt = Math.round(tileSz.x * xtk); elmBar.style.left = xf + 'px'; elmBar.style.width = (xt - xf) + 'px'; elmBar.title = 'Results shown from ' + new Date(dataTmRg.f).toLocaleString() + ', to ' + new Date(dataTmRg.t).toLocaleString(); } } Idaligo.UI.TimeLine.createLabel = function() { var elmLabel = document.createElement('SPAN'); Idaligo.Css.makePosAbs(elmLabel); elmLabel.className = 'idgTmlLb_off'; return elmLabel; } // Tile Idaligo.UI.TimeLine.prototype._createTile = function(idx, sz, zoom) { sz.y -= 1; return new Idaligo.UI.TimeLine.Tile(this.clickHandler, sz); }; Idaligo.UI.TimeLine.prototype._modifyTile = function(tile, idx, pt, zoom) { var scale = this.pane.configurations[zoom].scale; var dt = new Date(this.tm.zero); var startTm = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate() + idx.x).getTime();// this.tm.zero + idx.x * scale; var endTm = startTm + scale; var tmRg = new Idaligo.Geo.Rg(startTm, endTm); var dataTmRg = this.tm.dataTmRg; switch (zoom) { case Idaligo.UI.TimeLine.ZOOM.DAY: { tile.modify(tmRg, dataTmRg, this.tm.allowedTmRg); break; } case Idaligo.UI.TimeLine.ZOOM.MONTH: { tile.modify(tmRg, dataTmRg, this.tm.allowedTmRg); break; } default: throw new Error('Unexpected zoom: ' + zoom); } } Idaligo.UI.TimeLine.standsOnSuper = function(dt, zoom) { switch (zoom) { case Idaligo.UI.TimeLine.ZOOM.MONTH: return dt.getDate() == 1; case Idaligo.UI.TimeLine.ZOOM.DAY: return dt.getHours() == 0; default: throw new Error('Unexpected zoom: ' + zoom); } } // Controls Idaligo.UI.TimeLine.prototype._createControls = function() { var pt = new Idaligo.Geo.Pt(0, 0); var elmControl = document.createElement('DIV'); var elmDay = document.createElement('DIV'); elmDay.className = Idaligo.UI.TimeLine.CSS.Control; Idaligo.Css.makePosAbs(elmDay); Idaligo.Css.setPos(elmDay, pt); elmControl.appendChild(elmDay); Idaligo.Event.handle(this, elmDay, Idaligo.Event.TYPE.CLICK, function(s, e) { alert('Day'); }); elmDay.appendChild(document.createTextNode('day')); var elmMonth = document.createElement('DIV'); elmMonth.className = Idaligo.UI.TimeLine.CSS.Control; Idaligo.Css.makePosAbs(elmMonth); Idaligo.Css.setPos(elmMonth, pt.addY(17)); elmControl.appendChild(elmMonth); Idaligo.Event.handle(this, elmMonth, Idaligo.Event.TYPE.CLICK, function(s, e) { alert('Month'); }); elmMonth.appendChild(document.createTextNode('month')); return elmControl; } // Time shift Idaligo.UI.TimeLine.prototype.getCurrentTime = function() { return new Date(this.tm.current); } Idaligo.UI.TimeLine.prototype.moveBy = function(ticks) { this.moveTo(new Date(this.getCurrentTime() + ticks)); } Idaligo.UI.TimeLine.prototype.moveTo = function(dt) { //debugger; var destDt = (dt.constructor === Date) ? dt : new Date(dt); destDt = new Date(this.tm.allowedTmRg.trim(destDt.getTime())); this.clickHandler(destDt); } Idaligo.UI.TimeLine.prototype.gotoNextHour = function() { this.moveTo(this.getCurrentTime().addHour(1)); } Idaligo.UI.TimeLine.prototype.gotoPrevHour = function() { this.moveTo(this.getCurrentTime().addHour(-1)); } Idaligo.UI.TimeLine.prototype.gotoNextDay = function() { this.moveTo(this.getCurrentTime().addDay(1)); } Idaligo.UI.TimeLine.prototype.gotoPrevDay = function() { this.moveTo(this.getCurrentTime().addDay(-1)); } Idaligo.UI.TimeLine.prototype.gotoNextMonth = function() { this.moveTo(this.getCurrentTime().addMonth(1)); } Idaligo.UI.TimeLine.prototype.gotoPrevMonth = function() { this.moveTo(this.getCurrentTime().addMonth(-1)); } Idaligo.UI.TimeLine.prototype.makeVisible = function(tmRg) { Idaligo.Error.checkArgument(tmRg, "tmRg"); if (tmRg.hasFrom()) { var at = this.pane.getCurrentPt(); var rg = this.getRgByTmRg(tmRg); var vRg = this.pane.getVisibleHRg(); vRg.f += Idaligo.UI.TimeLine.visibleMarginWidth; vRg.t -= Idaligo.UI.TimeLine.visibleMarginWidth; var distance = vRg.f - rg.f; if (vRg.f < vRg.t) { if (tmRg.hasTo()) { var hit = vRg.hitRgAbs(rg); if (hit.f == 0 && hit.t == 0) { // do nothing // date range is withing visible range distance = 0; } else { if (hit.f = 0 && hit.t > 0) { debugger; if (rg.f - vRg.f > hit.t) { debugger; distance = hit.f; } } } } } distance = Math.round(distance); if (distance != 0) { this.pane.moveBy(new Idaligo.Geo.Pt(distance, 0)); } } else { // do nothing } } Idaligo.UI.TimeLine.prototype.getPtByDt = function(tm) { Idaligo.Error.checkArgument(tm, "tm"); var zero = this.tm.zero; return new Idaligo.Geo.Pt(Math.round(((tm - zero) / this.pane.getScale()) * this.pane.getTileSz().x), 0); } Idaligo.UI.TimeLine.prototype.getRgByTmRg = function(tmRg) { Idaligo.Error.checkArgument(tmRg, "tmRg"); var rg = Idaligo.Geo.Rg.createUndefined(); if (tmRg.hasFrom()) rg.f = this.getPtByDt(tmRg.f).x; if (tmRg.hasTo()) rg.t = this.getPtByDt(tmRg.t).x; return rg; } Idaligo.UI.TimeLine.prototype.getDistanceTo = function(dt) { Idaligo.Error.checkArgumentAsDate(dt, "dt"); var span = this.getTimeSpanTo(dt); return Math.round((span / this.pane.getScale()) * this.pane.getTileSz().x); } Idaligo.UI.TimeLine.prototype.getTimeSpanTo = function(dt) { Idaligo.Error.checkArgumentAsDate(dt, "dt"); return dt.getTime() - this.getCurrentTicks(); } Idaligo.UI.TimeLine.prototype.hide = function() { Idaligo.Css.setVisible(this.pane.elmRoot, false); } Idaligo.UI.TimeLine.prototype.show = function() { Idaligo.Css.setVisible(this.pane.elmRoot, true); } Idaligo.UI.TimeLine.prototype.getCurrentTicks = function() { var at = this.pane.getCurrentPt(); var scale = this.pane.getScale(); var tileSz = this.pane.getTileSz(); var zero = this.tm.zero; return zero + (at.x / tileSz.x) * scale; } Idaligo.UI.TimeLine.prototype.tryGetDataFrom = function() { if (this.tm.dataTmRg.hasFrom()) { return new Date(this.tm.dataTmRg.f); } return null; } Idaligo.UI.TimeLine.prototype.tryGetDataTo = function() { if (this.tm.dataTmRg.hasTo()) { return new Date(this.tm.dataTmRg.t); } return null; } Idaligo.UI.TimeLine.Tile = function(clickHandler, sz) { this.sz = sz; this.enabled = true; this.hasData = false; var elmTile = this.elmTile = document.createElement('DIV'); var elmSuperLb = this.elmSuperLb = Idaligo.UI.TimeLine.createLabel(); elmTile.appendChild(elmSuperLb); elmSuperLb.appendChild(document.createTextNode('')); Idaligo.Css.setPos(elmSuperLb, new Idaligo.Geo.Pt(0, 5)); var elmBar = this.elmBar = Idaligo.UI.TimeLine.createBar(); elmTile.appendChild(elmBar); Idaligo.Css.setPos(elmBar, new Idaligo.Geo.Pt(0, 50)); var elmLb = this.elmLb = Idaligo.UI.TimeLine.createLabel(Idaligo.Time.SCALE.DAY); elmTile.appendChild(elmLb); elmLb.appendChild(document.createTextNode('')); var elmLbSup = document.createElement('SUP'); elmLb.appendChild(elmLbSup); elmLbSup.appendChild(document.createTextNode('')); Idaligo.Css.setPos(elmLb, new Idaligo.Geo.Pt(0, 27)); var that = this; var handler = function(s, e) { if (that.enabled) { clickHandler(new Date(that.tmRg.f)); } return false; }; Idaligo.Event.handle(this, elmLb, Idaligo.Event.TYPE.CLICK, handler); Idaligo.Event.handle(this, elmSuperLb, Idaligo.Event.TYPE.CLICK, handler); Idaligo.Event.handle(this, elmLb, Idaligo.Event.TYPE.MOUSEDOWN, function(s, e) {e.stopPropagation();}); Idaligo.Event.handle(this, elmSuperLb, Idaligo.Event.TYPE.MOUSEDOWN, function(s, e) {e.stopPropagation();}); Idaligo.Event.handle(this, elmLb, Idaligo.Event.TYPE.MOUSEOVER, function(s, e) {if (this.enabled) s.className = Idaligo.Css.toggleClass(Idaligo.UI.TimeLine.CSS.Label, true);}); Idaligo.Event.handle(this, elmLb, Idaligo.Event.TYPE.MOUSEOUT, function(s, e) {s.className = Idaligo.Css.toggleClass(Idaligo.UI.TimeLine.CSS.Label, false);}); Idaligo.Event.handle(this, elmSuperLb, Idaligo.Event.TYPE.MOUSEOVER, function(s, e) {if (this.enabled) s.className = Idaligo.Css.toggleClass(Idaligo.UI.TimeLine.CSS.Label, true);}); Idaligo.Event.handle(this, elmSuperLb, Idaligo.Event.TYPE.MOUSEOUT, function(s, e) {s.className = Idaligo.Css.toggleClass(Idaligo.UI.TimeLine.CSS.Label, false);}); } Idaligo.UI.TimeLine.Tile.width = 35; Idaligo.UI.TimeLine.Tile.prototype.getTileElement = function() { return this.elmTile; } Idaligo.UI.TimeLine.Tile.prototype.modify = function(tmRg, dataTmRg, allowedTmRg) { this.tmRg = tmRg; var dt = new Date(tmRg.f); var elmTile = this.elmTile; var elmLb = this.elmLb; var elmSuperLb = this.elmSuperLb; var elmBar = this.elmBar; var zoom = Idaligo.UI.TimeLine.ZOOM.MONTH; var isOnSuper = Idaligo.UI.TimeLine.standsOnSuper(dt, zoom); elmSuperLb.firstChild.nodeValue = Idaligo.Time.monthNames[dt.getMonth()] + ', ' + dt.getFullYear(); Idaligo.Css.setVisible(elmSuperLb, isOnSuper); elmLb.firstChild.nodeValue = dt.getDate(); elmLb.firstChild.nextSibling.firstChild.nodeValue = dt.getDateSuffix().toLowerCase(); Idaligo.UI.TimeLine.initializeBar(elmBar, tmRg, dataTmRg, this.sz); Idaligo.Css.setVisible(elmTile, true); this.hasData = dataTmRg.isWithin(tmRg.f); this.enabled = allowedTmRg.isWithin(tmRg.f); elmTile.className = Idaligo.Css.toggleClass(Idaligo.UI.TimeLine.CSS.Tile, this.enabled); } /// Idaligo.UI.Tabs = function(elmMain, activeTabIndex) { if (! Idaligo.Core.defined(elmMain)) throw new Error("Main element for tabs is not specified."); activeTabIndex = Idaligo.Core.def(activeTabIndex, 0); this.elmMain = elmMain; this.elmMain.className = Idaligo.UI.Tabs.CSS.Main; this.items = new Array(); this.active = null; var tabElements = this.elmMain.getElementsByTagName("SPAN"); if (tabElements.length < 1) throw new Error("There are no tabs defined under " + this.elmMain.id + "."); for (var index = 0; index < tabElements.length; index ++) { var elmItem = tabElements[index]; elmItem.className = Idaligo.UI.Tabs.CSS.UnactiveItem; var bodyId = Idaligo.UI.Tabs.extractBodyId(elmItem.id); var elmBody = document.getElementById(bodyId); if (! Idaligo.Core.defined(elmBody)) throw new Error("Item body element has not been found by ID " + bodyId + "."); var item = new Idaligo.UI.Tabs.Item(this, elmItem, elmBody); this.items.push(item); elmItem = Idaligo.Dom.nextSiblingElement(elmItem, "SPAN"); } this.activateByIndex(activeTabIndex); } Idaligo.UI.Tabs.extractBodyId = function(id) { var index = id.indexOf("TabItem"); if (index > 0) { return id.substr(0, index); } else { throw new Error("Invalid id of the item \"" + id + "\", must be like TabItem."); } } Idaligo.UI.Tabs.CSS = {Main:'idgTabs', UnactiveItem:'idgTabsItm', ActiveItem:'idgTabsItmOn', UnactiveItemBody:'idgTabsBd', ActiveItemBody:'idgTabsBdOn'}; Idaligo.UI.Tabs.Item = function(parent, elmHead, elmBody) { if (! Idaligo.Core.defined(parent)) throw new Error("Parent is not specified."); if (! Idaligo.Core.defined(elmHead)) throw new Error("Head element is not specified."); if (! Idaligo.Core.defined(elmBody)) throw new Error("Body element is not specified."); this.elmHead = elmHead; this.elmBody = elmBody; Idaligo.Event.handle(this, this.elmHead, Idaligo.Event.TYPE.CLICK, function() {parent.activate(this);}); } Idaligo.UI.Tabs.Item.prototype.activate = function() { this.elmHead.className = Idaligo.UI.Tabs.CSS.ActiveItem; this.elmBody.className = Idaligo.UI.Tabs.CSS.ActiveItemBody; } Idaligo.UI.Tabs.Item.prototype.disactivate = function() { this.elmHead.className = Idaligo.UI.Tabs.CSS.UnactiveItem; this.elmBody.className = Idaligo.UI.Tabs.CSS.UnactiveItemBody; } Idaligo.UI.Tabs.prototype.activateByIndex = function(tabIndex) { if (this.items.length <= tabIndex) throw new Error("Requested active tab index (" + tabIndex + ") exceeds the number of tabs (" + this.items.length + ")."); var item = this.items[tabIndex]; this.activate(item); } Idaligo.UI.Tabs.prototype.activate = function(item) { if (! Idaligo.Core.defined(item)) throw new Error("Item to activate is not specified."); this.disactivate(); item.activate(); this.active = item; } Idaligo.UI.Tabs.prototype.disactivate = function() { if (Idaligo.Core.defined(this.active)) { this.active.disactivate(); this.active = null; } } Idaligo.UI.Tabs.prototype.getActive = function() { return this.active; }/// /// Idaligo.Anima = function() {}; Idaligo.Anima.delay = 20; Idaligo.Anima.Tick = function() { this.doers = new Array(); this.id = null; } Idaligo.Anima.Tick.prototype.register = function(holder, action) { this.doers.push({holder:holder, action:action}); } Idaligo.Anima.Tick.prototype.start = function() { if (Idaligo.Core.defined(this.id)) { return false; } else { if (this.doers.length > 0) { var that = this; this.id = window.setInterval ( function() { for (var i=0; i < that.doers.length; i++) { var doer = that.doers[i]; doer.action.call(doer.holder); } } , Idaligo.Anima.delay ); return true; } else { return false; } } } Idaligo.Anima.Tick.prototype.stop = function() { if (Idaligo.Core.defined(this.id)) { window.clearInterval(this.id); } this.id = null; } /// /// /// Idaligo.Anima.MoveBy = function(holder, action, maxStep) { this.maxStep = maxStep; this.holder = holder; this.action = action; this.reset(); this.tick = new Idaligo.Anima.Tick(); this.tick.register(this, this._tickAction); } Idaligo.Anima.MoveBy.prototype.start = function() { this.tick.start(); } Idaligo.Anima.MoveBy.prototype.stop = function() { this.reset(); this.tick.stop(); } Idaligo.Anima.MoveBy.prototype.reset = function() { this.destPt = new Idaligo.Geo.Pt(0, 0); this.curPt = new Idaligo.Geo.Pt(0, 0); } Idaligo.Anima.MoveBy.prototype._tickAction = function() { if (Idaligo.Core.defined(this.action)) { var dx = (this.destPt.x - this.curPt.x) / 10; var dy = (this.destPt.y - this.curPt.y) / 10; dx = Math.round(this.normalizeShift(dx)); var stopDx = this.curPt.x + dx == this.destPt.x; dy = Math.round(this.normalizeShift(dy)); var stopDy = this.curPt.y + dy == this.destPt.y; var d = new Idaligo.Geo.Pt(dx, dy); if (d.isZero()) { this.stop(); } else { this.curPt.add(d); //Idaligo.Debug.traceLn(this.curPt + ' ' + this.destPt); if (! this.action.call(this.holder, d)) { this.stop(); } else if (stopDx && stopDy) { this.stop(); } } } }; Idaligo.Anima.MoveBy.prototype.normalizeShift = function(shf) { if (shf != 0) { if (shf > 1) return shf; else if (shf > 0) return 1; else if (shf > -1) return -1; else return shf; } else return 0; } /// /// Idaligo.Anima.Timer = function() { } Idaligo.Anima.Timer.runForSeconds = function(seconds, framesPerSecond, action, finish_, actor_) { Idaligo.Error.checkArgumentAsNumber(seconds, "seconds"); Idaligo.Error.checkArgumentAsNumber(framesPerSecond, "framesPerSecond"); if (! Idaligo.Core.moreThanZero(framesPerSecond)) throw new Error("Parameter \"framesPerSecond\" must be greater than 0."); Idaligo.Error.checkArgument(action, "action"); //Actor may be unspecified: Idaligo.Error.checkArgument(actor, "actor"); var startAt = new Date().getTime(); var endAt = startAt + Idaligo.Time.STEP.SEC * seconds; var total = endAt - startAt; var delay = 1000 / framesPerSecond; var id = 0; // <== must be this way! id = window.setInterval(function() { var now = new Date().getTime(); var passed = now - startAt; if (passed > total) { passed = total; } var completion = passed / total; if (Idaligo.Core.defined(actor_)) { if (! action.call(actor_, completion)) { window.clearInterval(id); } } else { if (! action(completion)) { window.clearInterval(id); } } if (Math.abs(completion - 1.0) < 0.001) { window.clearInterval(id); if (Idaligo.Core.defined(finish_)) { if (Idaligo.Core.defined(actor_)) { finish_.call(actor_); } else { finish_(); } } } }, delay); } /// MapApp = function() {} MapApp.Env = function() {} MapApp.Env.fldPics = 'pics/'; MapApp.Env.recordsPerRequest = 100; MapApp.MapIt = function(elmButton, elmMap, profress, elmLeft, elmRight, elmTimeline, where, when, collections, bookmarks, /*contacts, summary,*/ paneBookmarks, /*paneInfo,*/ paneSearch, login, navigation) { if (! Idaligo.Core.defined(elmButton)) throw new Error("elmButton is not specified."); if (! Idaligo.Core.defined(elmMap)) throw new Error("elmMap is not specified."); if (! Idaligo.Core.defined(elmLeft)) throw new Error("elmLeft is not specified."); if (! Idaligo.Core.defined(elmRight)) throw new Error("elmRight is not specified."); if (! Idaligo.Core.defined(elmTimeline)) throw new Error("elmTimeline is not specified."); this.where = Idaligo.Error.checkArgument(where, "where"); this.when = Idaligo.Error.checkArgument(when, "when"); this.collections = Idaligo.Error.checkArgument(collections, "collections"); this.bookmarks = Idaligo.Error.checkArgument(bookmarks, "bookmarks"); //this.contacts = Idaligo.Error.checkArgument(contacts, "contacts"); //this.summary = Idaligo.Error.checkArgument(summary, "summary"); this.paneBookmarks = Idaligo.Error.checkArgument(paneBookmarks, "paneBookmarks"); /*this.paneInfo = Idaligo.Error.checkArgument(paneInfo, "paneInfo");*/ this.paneSearch = Idaligo.Error.checkArgument(paneSearch, "paneSearch"); this.login = Idaligo.Error.checkArgument(login, "login"); this.navigation = Idaligo.Error.checkArgument(navigation, "navigation"); this.progress = Idaligo.Error.checkArgument(profress, "progress"); if (! GBrowserIsCompatible()) throw new Error("Sorry, your browser doesn't seem compatible with this application."); this.elmLeft = elmLeft; this.elmRight = elmRight; this.elmButton = elmButton; this.elmTimeline = elmTimeline; this.map = new GMap2(elmMap); this.geocoder = new GClientGeocoder(); this.markers = new Array(); this.polygon = null; // there is no polygon by default this.map.addControl(new GLargeMapControl()); this.map.addControl(new GMapTypeControl()); this.map.addControl(new GScaleControl()); this.map.setCenter(new GLatLng(38.896369217468255, -77.02840805053711), 13); // the center of DC var me = this; // Binding handlers this.weAreMoving = false; this.authorizedMoving = false; GEvent.addListener(this.map, 'movestart', function() { me.weAreMoving = ! me.authorizedMoving; Idaligo.Debug.traceLn("Move start"); }); GEvent.addListener(this.map, 'infowindowopen', function() { me.weAreMoving = false; // don't worry that was just an info window }); GEvent.addListener(this.map, 'zoomend', function() { if (Idaligo.Core.defined(me.last)) // if there is the previous request based on which we can refine { if (me.map.getZoom() >= MapApp.MapIt.minZoom) { if (! me.authorizedMoving) { me.processAsMapMoved(); } } } me.authorizedMoving = false; }); GEvent.addListener(this.map, 'moveend', function() { Idaligo.Debug.traceLn("Move end"); if (Idaligo.Core.defined(me.last)) // if there is the previous request based on which we can refine { if (me.map.getZoom() >= MapApp.MapIt.minZoom) { if (me.weAreMoving && ! me.authorizedMoving) // the move is cause by something else but open window { var pt = me.map.getCenter(); if (Idaligo.Core.defined(me.last.pt)) { var distance = me.last.pt.distanceFrom(pt); var bounds = me.map.getBounds(); var maxSeenDistance = bounds.getSouthWest().distanceFrom(bounds.getNorthEast()); if (distance / maxSeenDistance > 0.15) // the map has been significantly panned by more than 15% of its size { me.processAsMapMoved(); } } else { me.processAsMapMoved(); } } } } me.authorizedMoving = false; }); Idaligo.Event.handle(this, this.elmButton, Idaligo.Event.TYPE.CLICK, this.mapIt); Idaligo.Event.handle(this, window, Idaligo.Event.TYPE.RESIZE, this.resize); // waiting while GMap2 is getting fully initialized window.setTimeout(function() {me.continueInitializing.call(me);}, 100); } MapApp.MapIt.prototype.continueInitializing = function() { this.markerManager = new GMarkerManager(this.map); this.resize(); this.map.setCenter(new GLatLng(38.896369217468255, -77.02840805053711), 13); // the center of DC var me = this; this.navigation.onTimeChosen = function(dt) { me.processAsDrillingMapWithTimeline(dt); } this.navigation.onPageChanged = function() { me.processAsDrillingMapWithPager(); } this.bookmarks.onSignInRequested = function() { me.login.setState(true); } this.bookmarks.onDeleteSavedPage = function(id) { me.processDeleteBookmark(id); } this.bookmarks.onSavePage = function() { me.bookmarks.askForName(me.progress, function(name, isDefault){ me.processSaveBookmark(name, isDefault);}); } this.login.signIn.action = function(login, password, rememberMe) { me.processAsLogin(login, password, rememberMe); } this.login.signOut.action = function() { me.processAsLogout(); } if (Idaligo.Core.declared(StartApp)) { StartApp(); } else { throw new Error("StartApp function is not declared."); } // Activate this hanler at the very end, when we know that everything has been initialized Idaligo.Event.handle(this, document, Idaligo.Event.TYPE.MOUSEDOWN, this.mouseDownOnScreen); } MapApp.MapIt.minZoom = 12; MapApp.MapIt.minWidthOfLeftPane = 200; //in px MapApp.MapIt.prototype.resize = function() { var width = document.body.clientWidth - this.elmLeft.clientWidth - 2; if (width < MapApp.MapIt.minWidthOfLeftPane) width = MapApp.MapIt.minWidthOfLeftPane; this.elmRight.style.width = width + 'px'; this.map.checkResize(); } MapApp.MapIt.prototype.setMap = function(bounds) { Idaligo.Error.checkArgument(bounds, "bounds"); var zoomLevel = this.map.getBoundsZoomLevel(new GLatLngBounds(bounds.sw, bounds.ne)); this.authorizedMoving = true; this.map.setZoom(zoomLevel); var lt = (bounds.sw.lat() + bounds.ne.lat())/2; var ln = (bounds.sw.lng() + bounds.ne.lng())/2; this.authorizedMoving = true; this.map.panTo(new GLatLng(lt, ln)); } MapApp.MapIt.prototype.validate = function() { var validationHeader = "Adjust your request"; var exact = this.when.getExact(); if (! this.when.isRecentSelected()) { var validateFromBuilder = exact.validateFrom("From"); if (! Idaligo.Core.emptyString(validateFromBuilder)) { this.progress.showOk(validationHeader, validateFromBuilder, function() {exact.focusFrom();} ) return false; } var validateToBuilder = exact.validateTo("To"); if (! Idaligo.Core.emptyString(validateToBuilder)) { this.progress.showOk(validationHeader, validateToBuilder, function() {exact.focusTo();} ) return false; } } if (this.where.addressChecker()) { var me; var address = this.where.address.getRawAddress(); if (Idaligo.Core.emptyString(address)) { this.progress.showOk(validationHeader, function(builder) { builder.appendText("Please, put something to the ").appendElement("B").appendText("Address").stepBack().appendText(" field."); }, function() { me.where.address.focusText(); }); return false; } } if (! this.collections.hasAnyChecked()) { var me = this; this.progress.showOk("What do you like to see on the map?", function(builder) { me.paneSearch.expandOrCollapse(true); builder.appendText("Set checkboxes on the ").appendElement("B").appendText("What").stepBack().appendText(" panel according to your request."); }); return false; } return true; } // Handler for the "Map It" button MapApp.MapIt.prototype.mapIt = function(s, e) { try { e.stopPropagation(); if (! this.validate()) return; if (this.where.addressChecker()) { // where is in the address mode var originalAddress = this.where.address.getRawAddress(); // see this.validate call above var fixedAddress = originalAddress; if (fixedAddress.toLowerCase().search('washington') < 0) { fixedAddress += ', Washington DC'; } var me = this; this.geocoder.getLocations(fixedAddress, function(response) { if (!response) { me.where.address.showError(); } else if (response.Status.code == G_GEO_UNKNOWN_ADDRESS) { me.where.address.showError("Unknown address: " + originalAddress); me.where.address.focusText(); } else if (response.Status.code == 200) { me.where.address.hideOptions(); me.where.address.clearOptions(); var numberOfAccepted = 0; for(var index = 0; index < response.Placemark.length; index++) { var place = response.Placemark[index]; if (place.AddressDetails.Accuracy >= 7) { me.where.address.addOption(place.address, place.Point.coordinates[1] + ',' + place.Point.coordinates[0]); numberOfAccepted ++; if (index == 0) { // setting the address textfield with the first address from the list me.where.address.setRawAddress(place.address); } } } if (numberOfAccepted > 1) { // if there is at least on address accurate enough, use by default; me.processAsStartOver(); me.where.address.showOptions(); } else if (numberOfAccepted > 0) { me.processAsStartOver(); } else { me.where.address.showError("Please, refine the address: " + originalAddress); } } else { me.where.address.showError(); } }); } else { // where is in the area mode this.processAsStartOver(); } } catch (e) { this.setClientError(e); } return false; } // StartOver request MapApp.MapIt.prototype.navigateByQueryString = function(queryString, isDefaultBookmark, isJustLoggedIn) { Idaligo.Error.checkArgumentAsNotEmptyString(queryString, "queryString"); Idaligo.Error.checkArgument(isDefaultBookmark, "isDefaultBookmark"); Idaligo.Error.checkArgument(isJustLoggedIn, "isJustLoggedIn"); var query = Idaligo.Core.QueryString.parse(queryString); var me = this; if (isDefaultBookmark) { if (isJustLoggedIn) { var url = window.location.protocol + "//" + window.location.hostname + ((window.location.port != 80) ? ":" + window.location.port : "") + window.location.pathname + "?" + queryString; window.location = url; } else { window.setTimeout(function() { me.processAsStartOver(query, "Please wait while your default page is loading...") }, 300); // we use this to jump over beingProcessed flag which is going to be dropped only after the response is completed } } else { this.processAsStartOver(query); } } MapApp.MapIt.prototype.processAsStartOver = function(query_, message_) { if (beingProcessed) return; message_ = Idaligo.Core.def(message_, "Please wait while the map is reloading..."); var query; if (Idaligo.Core.defined(query_)) { query = query_; } else { query = new Idaligo.Core.QueryString(); this.dumpAsStartOver(query); } this.last = {}; this.last.queryTobe = query.clone(); this.sendRequest("StartOver", query, message_); } MapApp.MapIt.prototype.setStateAfterStartOver = function(from, to, range, pager) { Idaligo.Error.checkArgument(from, "from"); Idaligo.Error.checkArgument(to, "to"); Idaligo.Error.checkArgument(range, "range"); Idaligo.Error.checkArgument(pager, "pager"); range.min = from; range.max = to; range.at = from; this.navigation.initialize(range, pager); this.last.pt = this.map.getCenter(); // if (! this.paneInfo.expanded()) // { // this.paneInfo.expand(); // } this.navigation.show(); this.progress.hide(); this.last.query = this.last.queryTobe; this.makeSureNoBalloon(); } MapApp.MapIt.prototype.processAsDrillingMapWithTimeline = function(dt) { if (beingProcessed) return; Idaligo.Error.checkArgument(dt, "dt"); var query = this.last.query.clone(); this.dumpAsDrillingMapWithTimeline(query, dt); this.sendRequest("DrillingMapWithTimeline", query, "Please wait while the map is reloading..."); } MapApp.MapIt.prototype.setStateAfterDrillingMapWithTimeline = function(dates, pager) { Idaligo.Error.checkArgument(dates, "dates"); Idaligo.Error.checkArgument(pager, "pager"); dates.at = pager.start; this.navigation.initialize(dates, pager); this.progress.hide(); this.makeSureBalloonIsActual(); } MapApp.MapIt.prototype.processAsDrillingMapWithPager = function() { if (beingProcessed) return; var query = this.last.query.clone(); this.dumpAsDrillingMapWithPager(query); this.sendRequest("DrillingMapWithPager", query, "Please wait while the map is reloading..."); } MapApp.MapIt.prototype.setStateAfterDrillingMapWithPager = function(dates, pager) { Idaligo.Error.checkArgument(dates, "dates"); Idaligo.Error.checkArgument(pager, "pager"); this.navigation.initialize(dates, pager); this.progress.hide(); this.makeSureNoBalloon(); } MapApp.MapIt.prototype.processAsMapMoved = function() { if (beingProcessed) return; var query = this.last.query.clone(); this.dumpAsMapMoved(query); this.sendRequest("MapMoved", query, "Please wait while the map is reloading..."); } MapApp.MapIt.prototype.setStateAfterMapMoved = function(dates, pager) { Idaligo.Error.checkArgument(dates, "dates"); Idaligo.Error.checkArgument(pager, "pager"); this.last.pt = this.map.getCenter(); this.navigation.initialize(dates, pager) this.progress.hide(); this.makeSureBalloonIsActual(); } MapApp.MapIt.prototype.processAsBalloonClick = function(pt, number, message_) { // WARNING pt is not GLatLng, because GLatLng has a low percision if (beingProcessed) return; Idaligo.Error.checkArgument(pt, "pt"); Idaligo.Error.checkArgumentAsNumber(number, "number"); message_ = Idaligo.Core.def(message_, "Please wait while the information is loading..."); this.makeSureContextAvailable(); var query = this.last.query.clone(); this.dumpAsBalloonClick(query, pt, number); this.sendRequest("BalloonClick", query, message_); } MapApp.MapIt.prototype.setStateAfterBalloonClick = function(pt, claimedNumber, records) { Idaligo.Error.checkArgument(pt, "pt"); Idaligo.Error.checkArgumentAsArray(records, "records"); this.showBalloon(pt, claimedNumber, records); this.progress.hide(); } MapApp.MapIt.prototype.processAsStaticBalloonClick = function(pt) { if (beingProcessed) return; Idaligo.Error.checkArgument(pt, "pt"); this.makeSureContextAvailable(); var query = this.last.query.clone(); this.dumpAsStaticBalloonClick(query, pt); this.sendRequest("StaticBalloonClick", query, "Please wait while the information is loaging..."); } MapApp.MapIt.prototype.processAsLogin = function(login, password, rememberMe) { if (beingProcessed) return; Idaligo.Error.checkArgument(login, "login"); Idaligo.Error.checkArgument(password, "password"); Idaligo.Error.checkArgument(rememberMe, "rememberMe"); var query = new Idaligo.Core.QueryString(); query.add("lgn", login); query.add("pwd", password); query.addBoolean("rem", rememberMe); this.sendRequest("Login", query, "Please wait while the system is checking your information..."); } MapApp.MapIt.prototype.processAsLogout = function() { if (beingProcessed) return; var query = new Idaligo.Core.QueryString(); this.sendRequest("Logout", query, "Please waite while your are being singed out..."); } MapApp.MapIt.prototype.setStateAfterLogout = function() { this.progress.hide(); this.login.setSignInState(); } // Working with bookmarks MapApp.MapIt.prototype.processSaveBookmark = function(name, isDefault) { if (beingProcessed) return; Idaligo.Error.checkArgumentAsNotEmptyString(name, "name"); Idaligo.Error.checkArgument(isDefault, "isDefault"); this.makeSureContextAvailable(); var query = this.last.query.clone(); query.add("bn", name); query.addBoolean("bdf", isDefault); this.sendRequest("SaveBookmark", query, "Please wait while the page is being saved..."); } MapApp.MapIt.prototype.processDeleteBookmark = function(id) { if (beingProcessed) return; Idaligo.Error.checkArgumentAsNotEmptyString(id, "id"); var query = new Idaligo.Core.QueryString(); query.add("bid", id); this.sendRequest("DeleteBookmark", query, "Please wait while the saved page is being deleted..."); } MapApp.MapIt.prototype.initialized = function() { return Idaligo.Core.defined(this.last); } MapApp.MapIt.prototype.hasLastQuery = function() {return this.initialized() && Idaligo.Core.defined(this.last.query);} MapApp.MapIt.prototype.makeSureContextAvailable = function() {if (! this.hasLastQuery()) throw new Error("There is no context for requested operation. Do some query first.");} // Notifications MapApp.MapIt.prototype.setNotification = function(message, header_) { Idaligo.Error.checkArgument(message, "message"); this.progress.showOk ( Idaligo.Core.def(header_, "Information") , function(builder) {builder.appendText(message);} ); } // Handling errors MapApp.MapIt.prototype.setError = function(message, header_) { Idaligo.Error.checkArgument(message, "message"); this.progress.showError ( Idaligo.Core.def(header_, "Unexpected difficulties") , function(builder) { builder.appendElement("PRE").appendText(message).stepBack(); } ); } MapApp.MapIt.prototype.setClientError = function(e) { this.progress.showError ( "Client exception" , function(builder) { MapApp.BuildHelper.dumpException(builder, e); } ) } MapApp.MapIt.prototype.sendRequest = function(commandName, parameters, message_) { Idaligo.Error.checkArgument(commandName, "commandName"); Idaligo.Error.checkArgument(parameters, "parameters"); if (! Idaligo.Core.emptyString(message_)) { this.progress.show(message_); } parameters.add("a", commandName); var query = parameters.toString(); Idaligo.Debug.traceLn(query); __DoCallBack(null, query); } MapApp.MapIt.prototype.mouseDownOnScreen = function(s, e) { // requesting elements to hide, but hide only appropriate ones var elements = new MapApp.MapIt.TobeHidden(); this.when.populateTobeHidden(elements); this.login.populateTobeHidden(elements); var target = e.source; elements.forEach(function(tobeHidden, guards) { var hide = true; for (var index = 0; index < guards.length; index ++) { var guard = guards[index]; hide = hide && ! Idaligo.Dom.isAncestor(guard, target); } if (hide) { if (Idaligo.Core.defined(tobeHidden.hide)) { tobeHidden.hide.call(tobeHidden); } else { Idaligo.Css.setDisplay(tobeHidden, false); } } return true; // keep going }); }; MapApp.MapIt.TobeHidden = function() { var elements = new Array(); var guards; this.hide = function(elementToHide) { Idaligo.Error.checkArgument(elementToHide, "elementToHide"); guards = new Array(); elements.push({hide:elementToHide, guards:guards}); return this; } this.guard = function(guardian) { Idaligo.Error.checkArgument(guardian, "guardian"); if (Idaligo.Core.defined(guards)) { guards.push(guardian); } return this; } this.forEach = function(action) { for (var index = 0; index < elements.length; index ++) { var element = elements[index]; if (! action(element.hide, element.guards)) { break; } } } }/// /// MapApp.MapIt.prototype.makeSureNoMarkers = function() { while (this.markers.length > 0) { this.map.removeOverlay(this.markers.pop()); } } MapApp.MapIt.prototype.addAddressMarker = function(pt, address) { Idaligo.Error.checkArgument(pt, "pt"); Idaligo.Error.checkArgument(address, "address"); var icon = new GIcon(G_DEFAULT_ICON); icon.image = "pics/" + "location.gif"; icon.iconSize = new GSize(32,53); var options = {icon:icon}; var marker = new GMarker(pt, options); var me = this; GEvent.addListener(marker, "click", function() { me.map.openInfoWindowHtml(pt, address); me.last.balloon = me.map.getInfoWindow(); }); this.addMarker(marker); } MapApp.MapIt.prototype.showBalloon = function(pt, claimedNumber, records) { Idaligo.Error.checkArgument(pt, "pt"); Idaligo.Error.checkArgumentAsNumber(claimedNumber, "claimedNumber"); Idaligo.Error.checkArgumentAsArray(records, "records"); var builder = Idaligo.Dom.Builder.createElement("DIV"); var elmBalloon = builder.getCurrentElement(); var isFirst = true; for (var index = 0; index < records.length; index ++) { var record = records[index]; if (isFirst) { isFirst = false; } else { builder.appendElement("HR").stepBack(); } this.buildRecord(builder, record); } elmBalloon.className = "maBalloon"; if (Idaligo.Agent.TYPE.IE && Idaligo.Agent.getVersion() <= 6) { elmBalloon.style.height = "150px"; } this.map.openInfoWindow(pt, elmBalloon); this.last.balloon = this.map.getInfoWindow(); this.last.balloon.number = claimedNumber; } MapApp.MapIt.prototype.buildRecord = function(builder, record) { Idaligo.Error.checkArgument(builder, "builder"); Idaligo.Error.checkArgument(record, "record"); var type = Idaligo.Core.def(record.f1, ""); if (type == "Crime Incidents") { var subType = record.f5; var subSubType = record.f6; var date = record.f4; var location = record.f3; var description = record.f7; if (! Idaligo.Core.emptyString(subType)) { builder.appendElement("DIV").appendElement("B"); builder.appendText(MapApp.BuildHelper.normalize(subType)); if (! Idaligo.Core.emptyString(subSubType)) { builder.appendText("/" + MapApp.BuildHelper.normalize(subSubType)); } if (! Idaligo.Core.emptyString(date)) { builder.appendText(", " + date); } builder.stepBack().stepBack(); } if (! Idaligo.Core.emptyString(location)) { builder.appendElement("DIV").withAttribute("style", "color:gray").appendText(location).stepBack(); } if (! Idaligo.Core.emptyString(description)) { builder.appendElement("DIV").withAttribute("style", "margin-top:5px;margin-right:5px;padding:5px;border:solid 1px #ddd;background-color:#f5f5f5").appendText(description).stepBack(); } } else if (type == "Service Requests") { var subType = record.f3; var agency = record.f5; var status = record.f4; var date = record.f6; var location = record.f7; if (! Idaligo.Core.emptyString(subType)) { builder.appendElement("DIV").appendElement("B").appendText(subType).stepBack().stepBack(); } if (! Idaligo.Core.emptyString(location)) { builder.appendElement("DIV").withAttribute("style", "color:gray").appendText(location).stepBack(); } if (! Idaligo.Core.emptyString(agency)) { builder.appendElement("DIV").appendText("Responsible agency: " + agency).stepBack(); } if (! Idaligo.Core.emptyString(status)) { builder.appendElement("DIV").appendText("Status: " + status).stepBack(); } if (! Idaligo.Core.emptyString(date)) { builder.appendElement("DIV").appendText("Resolution due date: " + date).stepBack(); } } else if (type == "Building Permites") { var subType = record.f3; var date = record.f4; var contractor = record.f5; var location = record.f7; if (! Idaligo.Core.emptyString(subType)) { builder.appendElement("DIV").appendElement("B").appendText(subType) if (! Idaligo.Core.emptyString(date)) { builder.appendText(", " + date); } builder.stepBack().stepBack(); } if (! Idaligo.Core.emptyString(location)) { builder.appendElement("DIV").withAttribute("style", "color:gray").appendText(location).stepBack(); } if (! Idaligo.Core.emptyString(contractor)) { builder.appendElement("DIV").appendText("Contractor: " + contractor).stepBack(); } } else if (type == "Public Space Permites") { var subType = record.f3; var location = record.f4; var owner = record.f5; var date = record.f6; var expires = record.f7; if (! Idaligo.Core.emptyString(subType)) { builder.appendElement("DIV").appendElement("B").appendText(subType); if (! Idaligo.Core.emptyString(date)) { builder.appendText(", " + date); } builder.stepBack().stepBack(); } if (! Idaligo.Core.emptyString(location)) { builder.appendElement("DIV").withAttribute("style", "color:gray").appendText(location).stepBack(); } if (! Idaligo.Core.emptyString(owner)) { builder.appendElement("DIV").appendText("Owner: " + owner).stepBack(); } if (! Idaligo.Core.emptyString(expires)) { builder.appendElement("DIV").appendText("Expiration date: " + expires).stepBack(); } } else if (type == "Schools") { var subType = record.f3; var location = record.f4; var phone = record.f5; if (! Idaligo.Core.emptyString(subType)) { builder.appendElement("DIV").appendElement("B").appendText(subType); builder.stepBack().stepBack(); } if (! Idaligo.Core.emptyString(location)) { builder.appendElement("DIV").withAttribute("style", "color:gray").appendText(location).stepBack(); } if (! Idaligo.Core.emptyString(phone)) { builder.appendElement("DIV").appendText("Phone: " + phone).stepBack(); } } else { builder.appendText("f1:" + record.f1).appendElement("BR", false); builder.appendText("f2:" + record.f2).appendElement("BR", false); builder.appendText("f3:" + record.f3).appendElement("BR", false); builder.appendText("f4:" + record.f4).appendElement("BR", false); builder.appendText("f5:" + record.f5).appendElement("BR", false); builder.appendText("f6:" + record.f6).appendElement("BR", false); builder.appendText("f7:" + record.f7); } } MapApp.MapIt.prototype.makeSureBalloonIsActual = function() { if(Idaligo.Core.defined(this.last.balloon) && ! this.last.balloon.isHidden()) { for (var index = 0; index < this.markers.length; index ++) { var marker = this.markers[index]; if (marker.getPoint().distanceFrom(this.last.balloon.getPoint()) < 1.0 /* distance is less than one meter */) { if (marker.number == this.last.balloon.number) { /* marker seems to be the same as open balloon */ return; } } } } this.makeSureNoBalloon(); } MapApp.MapIt.prototype.makeSureNoBalloon = function() { this.map.closeInfoWindow(); this.last.balloon = null; } MapApp.MapIt.prototype.addMarker = function(marker) { if (! Idaligo.Core.defined(marker)) throw new Error("Marker is not specified."); this.markers.push(marker); this.map.addOverlay(marker); } MapApp.MapIt.prototype.addMarkers = function(markers) { Idaligo.Error.checkArgumentAsArray(markers, "markers"); this.makeSureNoMarkers(); for (var index = 0; index < markers.length; index ++) { var marker = markers[index]; var result = this.createMarker(marker.pt, marker.n, marker.c); this.addMarker(result); } Idaligo.Debug.traceLn("total is " + markers.length); } MapApp.MapIt.prototype.createMarker = function(pt, number, color) { var icon = new GIcon(G_DEFAULT_ICON); var dynmic = number > 0; if (dynmic) { icon.image = "pics/markers/" + color + "/marker" + number + ".png"; } else { if (color == "school") { icon.iconSize = new GSize(15, 15); icon.shadowSize = icon.iconSize = new GSize(15, 15); icon.iconAnchor = new GPoint(7, 15); icon.maxHeight = 15; } icon.image = "pics/" + color + ".png"; } var result = new GMarker(new GLatLng(pt.t, pt.n), {icon:icon}); result.number = number; var me = this; if (dynmic) { GEvent.addListener(result, "click", function() { me.processAsBalloonClick(pt, number); }); } else { GEvent.addListener(result, "click", function() { me.processAsStaticBalloonClick(pt); }); } return result; } // Working with polygons MapApp.MapIt.prototype.makeSureNoPolygon = function() { if (Idaligo.Core.defined(this.polygon)) { this.map.removeOverlay(this.polygon); this.polygon = null; } } MapApp.MapIt.prototype.registerPolygon = function(points) { this.makeSureNoPolygon(); this.polygon = new GPolygon(points, "navy", 5, 1, "navy", 0.1); this.map.addOverlay(this.polygon); } MapApp.MapIt.prototype.registerRadiusPolygon = function(pt, radiusInMiles) { Idaligo.Error.checkArgument(pt, "pt"); this.makeSureNoPolygon(); var k = Math.PI / 180; var points = new Array(); var rx = 1/68.978 * radiusInMiles; var ry = 1/53.904 * radiusInMiles; for (var index = 0; index < 360; index += 10) { var alpha = index * k; var x = rx * Math.cos(alpha); var y = ry * Math.sin(alpha); points.push(new GLatLng(pt.lat() + x, pt.lng() + y)); } points.push(points[0]); // closed curve this.polygon = new GPolygon(points, "navy", 5, 1, "navy", 0.1); this.map.addOverlay(this.polygon); }/// /// MapApp.MapIt.prototype.dumpAsStartOver = function(query) { Idaligo.Error.checkArgument(query, "query"); this.when.dump(query); this.where.dump(query); this.collections.dump(query); } MapApp.MapIt.prototype.dumpMapState = function(query) { Idaligo.Error.checkArgument(query, "query"); var bounds = this.map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); query.addGLatLong("sw", southWest); // SouthWest query.addGLatLong("ne", northEast); // NorthEast query.add("zm", this.map.getZoom()); // Zoom } MapApp.MapIt.prototype.dumpAsDrillingMapWithPager = function(query) { Idaligo.Error.checkArgument(query, "query"); query.add("pof", this.navigation.pager.getOffset()); // PagerOffset query.addDate("tml", this.navigation.pager.getStartDate()); this.dumpMapState(query); } MapApp.MapIt.prototype.dumpAsDrillingMapWithTimeline = function(query, dt) { Idaligo.Error.checkArgument(query, "query"); Idaligo.Error.checkArgument(dt, "dt"); query.add("pof", 0); query.addDate("tml", dt); this.dumpMapState(query); } MapApp.MapIt.prototype.dumpAsMapMoved = function(query) { Idaligo.Error.checkArgument(query, "query"); query.add("pof", 0); query.addDate("tml", this.navigation.pager.getStartDate()); this.dumpMapState(query); } MapApp.MapIt.prototype.dumpAsBalloonClick = function(query, pt, number) { // WARNING pt is not GLatLng, because GLatLng tuncates has a low percision Idaligo.Error.checkArgument(query, "query"); Idaligo.Error.checkArgument(pt, "pt"); this.dumpAsStaticBalloonClick(query, pt); var from = this.navigation.timeline.tryGetDataFrom(); var to = this.navigation.timeline.tryGetDataTo(); query.addDate("bf", from); // BalloonFrom query.addDate("bt", to); // BalloonTo query.add("bcn", number); // BalloonClaimedNumber } MapApp.MapIt.prototype.dumpAsStaticBalloonClick = function(query, pt) { Idaligo.Error.checkArgument(query, "query"); Idaligo.Error.checkArgument(pt, "pt"); query.add("bptlt", pt.t); // BalloonPoint query.add("bptln", pt.n); // BalloonPoint }/// MapApp.Where = function(address, area, addressChecker) { Idaligo.Error.checkArgument(address, "address"); Idaligo.Error.checkArgument(area, "area"); Idaligo.Error.checkArgument(addressChecker, "addressChecker"); this.address = address; this.area = area; this.addressChecker = addressChecker; this.makeSureAreaMode = function() { if (this.addressChecker()) throw new Error('"Where" control is in the address mode, while the area mode is expected.'); } this.makeSureAddressMode = function() { if (! this.addressChecker()) throw new Error('"Where" control is in the area mode, while the address mode is expected.');} this.dump = function(values) { Idaligo.Error.checkArgument(values, "values"); if (this.addressChecker()) { this.address.dump(values); } else { this.area.dump(values); } } } MapApp.Where.Address = function(elementAddress, elementOptions, elementRadius, elementBorder) { var _elementAddress, _elementOptions, _elementRadius, _elementBorder; this.getRawAddress = function() { return _elementAddress.value; } this.setRawAddress = function(value) { _elementAddress.value = value; } this.getRadius = function() { return _elementRadius[_elementRadius.selectedIndex].value; } this.hasBorder = function() { return _elementBorder.checked;} this.getAddress = function() { if (_elementOptions.selectedIndex < 0) return this.getRawAddress(); else return _elementOptions[_elementOptions.selectedIndex].text; } this.hideOptions = function() { Idaligo.Css.setDisplay(_elementOptions, false);} this.showOptions = function() { Idaligo.Css.setDisplay(_elementOptions, true); } this.clearOptions = function() { _elementOptions.options.length = 0; } this.addOption = function(text, value) { _elementOptions.options[_elementOptions.options.length] = new Option(text, value, false, false); } this.showError = function(text) {text = Idaligo.Core.def(text, "Unable to resolve the given address: " + this.getRawAddress()); alert(text); this.hideOptions(); } this.focusText = function() {_elementAddress.focus();} this.addressOptionChosen = function() {this.setRawAddress(_elementOptions[_elementOptions.selectedIndex].text);} this.getAddressPoint = function() { if (_elementOptions.selectedIndex < 0) { return null; } else { var pt = _elementOptions[_elementOptions.selectedIndex].value.split(','); return new GLatLng(pt[0], pt[1]); } } this.dump = function(values) { values.add("am", "address"); values.add("ad", this.getAddress()); values.add("rd", this.getRadius()); values.addBoolean("rhb", this.hasBorder()); var point = this.getAddressPoint(); if (point == null) throw new Error("Address is not prepared to be serialized."); values.addGLatLong("apt", point); } // Constructor this.initialize = function(elementAddress, elementOptions, elementRadius, elementBorder) { _elementAddress = Idaligo.Error.checkArgument(elementAddress, "elementAddress"); _elementOptions = Idaligo.Error.checkArgument(elementOptions, "elementOptions"); _elementRadius = Idaligo.Error.checkArgument(elementRadius, "elementRadius"); _elementBorder = Idaligo.Error.checkArgument(elementBorder, "elementBorder"); Idaligo.Event.handle(this, _elementOptions, Idaligo.Event.TYPE.CHANGE, this.addressOptionChosen); } this.initialize(elementAddress, elementOptions, elementRadius, elementBorder); } MapApp.Where.Area = function(elementMode, elementId, elementBorder) { var _elementMode, _elementId, _elementBorder; this.initialize = function(elementMode, elementId, elementBorder) { Idaligo.Error.checkArgument(elementMode, "elementMode"); Idaligo.Error.checkArgument(elementId, "elementId"); Idaligo.Error.checkArgument(elementBorder, "elementBorder"); _elementBorder = elementBorder; _elementMode = elementMode; _elementId = elementId; } this.initialize(elementMode, elementId, elementBorder); this.getAreaId = function() { return _elementId.options[_elementId.selectedIndex].value; } this.getAreaMode = function() { return _elementMode.options[_elementMode.selectedIndex].value; } this.hasBorder = function() { return _elementBorder.checked; } this.dump = function(values) { Idaligo.Error.checkArgument(values, "values"); values.add("am", "area"); values.add("aid", this.getAreaId()); values.add("at", this.getAreaMode()); values.addBoolean("ahb", this.hasBorder()); } }/// /// MapApp.When = function(recent, exact, recentSelected) { Idaligo.Error.checkArgument(recent, "recent"); Idaligo.Error.checkArgument(exact, "exact"); Idaligo.Error.checkArgument(recentSelected, "recentSelected"); this.getRecent = function() {return recent;} this.getExact = function() {return exact;} this.isRecentSelected = function() { return recentSelected();} this.populateTobeHidden = function(elements) { Idaligo.Error.checkArgument(elements, "elements"); this.getExact().getFrom().populateTobeHidden(elements); this.getExact().getTo().populateTobeHidden(elements); } } MapApp.When.prototype.dump = function(query) { Idaligo.Error.checkArgument(query, "query"); if (this.isRecentSelected()) this.getRecent().dump(query); else this.getExact().dump(query); } MapApp.When.Exact = function(from, to) { Idaligo.Error.checkArgument(from, "from"); Idaligo.Error.checkArgument(to, "to"); var _from, _to; var me = this; this.initialize = function(from, to) { Idaligo.Error.checkArgument(from, "from"); Idaligo.Error.checkArgument(to, "to"); _from = from; _to = to; } this.initialize(from, to); this.getFrom = function() {return _from;} this.getTo = function() {return _to;} //this.hasFrom = function() { return ! this.getFrom().unspecified();} //this.hasTo = function() { return ! this.getTo().unspecified();} this.validateFrom = function(name, builder) {return this.getFrom().validate(name);} this.validateTo = function(name, builder) {return this.getTo().validate(name);} this.focusFrom = function() {this.getFrom().focus();} this.focusTo = function() {this.getTo().focus();} } MapApp.When.Exact.prototype.dump = function(query) { Idaligo.Error.checkArgument(query, "query"); query.add("tm", "exact"); query.add("sd", this.getFrom().getDate()); // StartTime query.add("ed", this.getTo().getDate()); // EndTime } MapApp.When.Recent = function(elmLast7Days, elmLast30Days, elmYtd) { Idaligo.Error.checkArgument(elmLast7Days, "elmLast7Days"); Idaligo.Error.checkArgument(elmLast30Days, "elmLast30Days"); Idaligo.Error.checkArgument(elmYtd, "elmYtd"); this.isLast7 = function() {return elmLast7Days.checked;} this.isLast30 = function() {return elmLast30Days.checked;} this.isYtd = function() {return elmYtd.checked;} } MapApp.When.Recent.prototype.dump = function(query) { Idaligo.Error.checkArgument(query, "query"); query.add("tm", "recent"); if (this.isLast7()) query.add("rm", "l7"); else if (this.isLast30()) query.add("rm", "l30"); else if (this.isYtd()) query.add("rm", "ytd"); else throw new Error("Unexpected 'When: Recent' mode."); }/// MapApp.Calendar = function(elmText, elmCalendar) { if (! Idaligo.Core.defined(elmText)) throw new Error("elmTextbox is not specified."); if (! Idaligo.Core.defined(elmCalendar)) throw new Error("elmCalendar is not specified."); this.elmText = elmText; this.elmCalendar = elmCalendar; if (Idaligo.Core.emptyString(this.elmText.value)) { this.elmText.value = MapApp.Calendar.dateFormat; } Idaligo.Event.handle(this, this.elmText, Idaligo.Event.TYPE.FOCUS, function(s, e) { this.defaultValue(true); this.show(); }); Idaligo.Event.handle(this, this.elmText, Idaligo.Event.TYPE.BLUR, function(s, e) { this.defaultValue(false); }); // // Idaligo.Event.handle(this, this.elmText, Idaligo.Event.TYPE.CLICK, function(s, e) // { // e.stopPropagation(); // }); var tobeShown = ! Idaligo.Core.emptyString(this.elmCalendar.className); if (tobeShown) { this.show(); } } MapApp.Calendar.dateFormat = ""; // to be overriden MapApp.Calendar.prototype.show = function() { var at = Idaligo.Css.getPos(this.elmText, true); var sz = Idaligo.Css.getSize(this.elmText); at.x += 2; at.y += sz.y + 6; Idaligo.Css.setPos(this.elmCalendar, at); Idaligo.Css.setVisible(this.elmCalendar, true); Idaligo.Css.setDisplay(this.elmCalendar, true); } MapApp.Calendar.prototype.populateTobeHidden = function(elements) { Idaligo.Error.checkArgument(elements, "elements"); elements.hide(this.elmCalendar).guard(this.elmText).guard(this.elmCalendar); } MapApp.Calendar.prototype.validate = function(name) { Idaligo.Error.checkArgument(name, "name"); if (this.unspecified()) { return function(builder) { builder.appendText("Please, specify the ").appendElement("B").appendText(name).stepBack().appendText(" date.") }; } else { var date = this.getDate(); if (new String(date).match(/^\d{2}\/\d{2}\/\d{4}$/ig) == null) { return function(builder) { builder.appendText("The ").appendElement("B").appendText(name).stepBack().appendText(" date is incorrect."); builder.appendElement("BR", false).appendText("Please, use the following format: ").appendElement("BR", false).appendElement("B").appendText("mm/dd/yyyy").stepBack(); } } } return null; } MapApp.Calendar.prototype.unspecified = function() { return this.getDate() == MapApp.Calendar.dateFormat; } MapApp.Calendar.prototype.focus = function() { this.elmText.focus(); } MapApp.Calendar.prototype.defaultValue = function(focused) { if (focused) { if (this.unspecified()) { this.elmText.value = ""; this.elmText.style.color = "Black"; } } else { if (this.elmText.value == "") { this.elmText.value = MapApp.Calendar.dateFormat; this.elmText.style.color = "Gray"; } } } MapApp.Calendar.prototype.setDate = function(dateText) { Idaligo.Error.checkArgument(dateText, 'dateText'); this.elmText.value = dateText; } MapApp.Calendar.prototype.getDate = function() { return this.elmText.value; } /// // Expandable list MapApp.ExpandList = function(elmImage, elmCheckbox, elmPane, expanded) { if (! Idaligo.Core.defined(elmImage)) throw new Error("Image element is not specified."); if (! Idaligo.Core.defined(elmPane)) throw new Error("Pane element is not specified."); if (! Idaligo.Core.defined(elmCheckbox)) throw new Error("Checkbox element is not specified."); expanded = Idaligo.Core.def(expanded, false); this.elmImage = elmImage; this.elmPane = elmPane; this.elmCheckbox = elmCheckbox; this.expandCollapse(expanded); Idaligo.Event.handle(this, this.elmImage, Idaligo.Event.TYPE.CLICK, this.toggle); Idaligo.Event.handle(this, this.elmCheckbox, Idaligo.Event.TYPE.CLICK, this.setCheckmark); } MapApp.ExpandList.CSS = function() {}; MapApp.ExpandList.CSS.PANE = { Opened:"maExpLstPn_Opn", Closed:"maExpLstPn" }; MapApp.ExpandList.prototype.expanded = function() { return this.elmPane.className == MapApp.ExpandList.CSS.PANE.Opened; } MapApp.ExpandList.prototype.toggle = function() { this.expandCollapse( ! this.expanded()); } MapApp.ExpandList.prototype.setCheckmark = function() { var id = this.elmCheckbox.id; var inputs = this.elmPane.getElementsByTagName("input"); // if (this.elmCheckbox.checked) // { // this.expandCollapse(true); // } for (var index = 0; index < inputs.length; index ++) { inputs[index].checked = this.elmCheckbox.checked; } } MapApp.ExpandList.prototype.expandCollapse = function(expand) { this.elmPane.className = (expand) ? MapApp.ExpandList.CSS.PANE.Opened : MapApp.ExpandList.CSS.PANE.Closed; this.elmImage.src = MapApp.Env.fldPics + ((expand) ? "open.gif" : "clsd.gif"); } /// MapApp.ExpandPane = function(elmHead, expanded) { expanded = Idaligo.Core.def(expanded, false); this.elmHead = elmHead; this.elmImage = Idaligo.Dom.firstChildElement(elmHead, "IMG"); if (! Idaligo.Core.defined(this.elmImage)) { throw new Error("Unable to find the depended image for " + elmHead.id); } this.elmBody = Idaligo.Dom.nextSiblingElement(elmHead, "DIV"); this.expandOrCollapse(expanded); if (! Idaligo.Core.defined(this.elmBody)) { throw new Error("Unable to find the depended pane element for " + elmHead.id); } Idaligo.Event.handle(this, elmHead, Idaligo.Event.TYPE.CLICK, this.toggle); } MapApp.ExpandPane.prototype.toggle = function() { this.expandOrCollapse(! this.expanded()); } MapApp.ExpandPane.prototype.expandOrCollapse = function(trueForExpand) { this.elmHead.className = (trueForExpand) ? "pnlHdr_Opn" : "pnlHdr"; this.elmImage.src = MapApp.Env.fldPics + ((trueForExpand) ? "minus.gif" : "plus.gif"); this.elmBody.style.display = (trueForExpand) ? "block" : "none"; } MapApp.ExpandPane.prototype.expand = function() { this.expandOrCollapse(true); } MapApp.ExpandPane.prototype.collapse = function() { this.expandOrCollapse(false); } MapApp.ExpandPane.prototype.expanded = function() { return this.elmHead.className == "pnlHdr_Opn"; } /// /// /// /// // Progress bar MapApp.Dialog = function(elmDialog, elmBackground) { this.elmDialog = Idaligo.Error.checkArgument(elmDialog, "elmDialog"); this.elmBackground = Idaligo.Error.checkArgument(elmBackground, "elmBackground"); } MapApp.Dialog.prototype.fixCanvas = function() { var scrollPt = Idaligo.Css.getScrollPos(); var clientSz = Idaligo.Css.getClientSize(); var windowSz = Idaligo.Css.getSize(this.elmDialog); var docSz = Idaligo.Css.getDocSize(); var windowPt = new Idaligo.Geo.Pt(scrollPt.x + clientSz.x/2 - windowSz.x/2, scrollPt.y + clientSz.y/2 - windowSz.y/2); Idaligo.Css.setPos(this.elmDialog, windowPt); Idaligo.Css.setPos(this.elmBackground, Idaligo.Geo.Pt.zero()); Idaligo.Css.setSize(this.elmBackground, docSz); this.scrollHook = Idaligo.Event.handle(this, window, Idaligo.Event.TYPE.SCROLL, this.fixDialogAfterScroll); } MapApp.Dialog.prototype.fixDialogAfterScroll = function() { window.status = document.body.scrollTop; if (Idaligo.Core.defined(this.fixDialogHandle)) { window.clearTimeout(this.fixDialogHandle); } var me = this; this.fixDialogHandle = window.setTimeout(function() { var scrollPt = Idaligo.Css.getScrollPos(); var clientSz = Idaligo.Css.getClientSize(); var windowSz = Idaligo.Css.getSize(me.elmDialog); var windowPt = new Idaligo.Geo.Pt(scrollPt.x + clientSz.x/2 - windowSz.x/2, scrollPt.y + clientSz.y/2 - windowSz.y/2); Idaligo.Css.setPos(me.elmDialog, windowPt); }, 300); } MapApp.Dialog.prototype.releaseCanvas = function() { if (Idaligo.Core.defined(this.scrollHook)) { Idaligo.Event.unhandle(window, Idaligo.Event.TYPE.SCROLL, this.scrollHook); } } MapApp.Dialog.prototype.showCanvas = function() { Idaligo.Css.setDisplay(this.elmDialog, true); Idaligo.Css.setDisplay(this.elmBackground, true); this.elmBackground.disabled = true; this.fixCanvas(); } MapApp.Dialog.prototype.hide = function() { if (this.timeout != 0) { window.clearTimeout(this.timeout); } Idaligo.Css.setDisplay(this.elmDialog, false); Idaligo.Css.setDisplay(this.elmBackground, false); this.elmBackground.className = "status"; this.elmDialog.className = ""; this.releaseCanvas(); } MapApp.Dialog.MODE = {Dialog:0, Error:1}; MapApp.Dialog.prototype.show = function(message) { Idaligo.Error.checkArgument(message, "message"); this.showCanvas(); this.elmBackground.className = "status"; var builder = new Idaligo.Dom.Builder(this.elmDialog).removeChildNodes(); builder.appendText(message); var elmFotter = builder.appendElement("DIV").withAttribute("style", "padding-top:10px").getCurrentElement(); Idaligo.Css.setDisplay(elmFotter, false); var me = this; var elmButton = MapApp.BuildHelper.buildButton(builder, "Cancel", function() { me.hide(); var url = window.location.protocol + "//" + window.location.hostname + ((window.location.port != 80) ? ":" + window.location.port : "") + window.location.pathname + "?empty"; window.location = url; }, this); this.timeout = window.setTimeout ( function() {Idaligo.Css.setDisplay(elmFotter, true); me.timeout = 0;} , 10000 ); } MapApp.Dialog.prototype.showOk = function(header, detailsCreator, okHandler_) { Idaligo.Error.checkArgumentAsNotEmptyString(header, "header"); Idaligo.Error.checkArgumentAsNotEmptyString(detailsCreator, "detailsCreator"); var me = this; this.build(function(elmHeader, elmDetails, elmFooter, elmDialog, elmBackground) { elmBackground.className = "dialog"; var builder = new Idaligo.Dom.Builder(elmHeader).appendText(header); builder.startWith(elmDetails); elmDetails.className = "details_ok"; detailsCreator(builder); builder.startWith(elmFooter); var closeHandler = function() { me.hide(); if (Idaligo.Core.defined(okHandler_)) okHandler_(); return false; } var elmClose = MapApp.BuildHelper.buildButton(builder, "OK", closeHandler, me); MapApp.BuildHelper.handleKeyboard([elmClose], [{key:27, handler:closeHandler}]); return elmClose; }); } MapApp.Dialog.prototype.showError = function(header, detailsCreator) { Idaligo.Error.checkArgumentAsNotEmptyString(detailsCreator, "detailsCreator"); if (Idaligo.Core.emptyString(header)) { header = "Unexpected difficulties"; } var me = this; this.build(function(elmHeader, elmDetails, elmFooter, elmDialog, elmBackground) { elmBackground.className = "error"; elmDialog.className = "error"; var builder = new Idaligo.Dom.Builder(elmHeader).appendText(header); builder.startWith(elmDetails); elmDetails.className = "details_wide"; detailsCreator(builder); builder.startWith(elmFooter); var closeHandler = function() { me.hide(); return false; } var elmClose = MapApp.BuildHelper.buildButton(builder, "Close", closeHandler, me); MapApp.BuildHelper.handleKeyboard([elmDialog], [{key:27, handler:closeHandler}]); return elmClose; }); } MapApp.Dialog.prototype.build = function(creator) { Idaligo.Error.checkArgument(creator, "creator"); var builder = new Idaligo.Dom.Builder(this.elmDialog); builder.removeChildNodes(); var elmHeader = builder.appendElement("DIV").getCurrentElement(); elmHeader.className = "header"; var elmDetails = builder.stepBack().appendElement("DIV").getCurrentElement(); elmDetails.className = "details"; var elmFooter = builder.stepBack().appendElement("DIV").getCurrentElement(); elmFooter.className = "footer"; this.elmBackground.className = "dialog"; this.elmDialog.className = ""; var elmInFocus = creator(elmHeader, elmDetails, elmFooter, this.elmDialog, this.elmBackground); if (Idaligo.Core.defined(elmInFocus)) { var me = this; window.setTimeout(function() { me.showCanvas(); elmInFocus.focus(); }, 200); } else { this.showCanvas(); } } /// /// /// MapApp.SavedPages = function(elmSavedPages, elmSavePage) { this.elmSavedPages = Idaligo.Error.checkArgument(elmSavedPages, "elmSavedPages"); this.elmSavePage = Idaligo.Error.checkArgument(elmSavePage, "elmSavePage"); this.showSignInRequired(); Idaligo.Event.handle(this, this.elmSavePage, Idaligo.Event.TYPE.CLICK, this.savePageClicked); } MapApp.SavedPages.prototype.showSignInRequired = function() { var builder = new Idaligo.Dom.Builder(this.elmSavedPages); builder.removeChildNodes(); builder.appendText("Please, "); var elmSignIn = builder.appendElement("A").withAttribute("href", "#").withAttribute("title", "Sign in to save your searches").appendText("sign in").getCurrentElement(); builder.stepBack().appendText(" in order to see saved pages."); Idaligo.Event.handle(this, elmSignIn, Idaligo.Event.TYPE.CLICK, this.signInClicked); Idaligo.Css.setDisplay(this.elmSavePage, false); } MapApp.SavedPages.prototype.showBookmarks = function(bookmarks) { Idaligo.Error.checkArgumentAsArray(bookmarks, "bookmarks"); this.addBookmarks(bookmarks); Idaligo.Css.setDisplay(this.elmSavePage, true); } MapApp.SavedPages.prototype.addBookmarks = function(bookmarks) { Idaligo.Error.checkArgumentAsArray(bookmarks, "bookmarks"); var builder = new Idaligo.Dom.Builder(this.elmSavedPages); var me = this; if (bookmarks.length > 0) { builder.removeChildNodes(); builder.appendElement("UL"); for (var index = 0; index < bookmarks.length; index ++) { var bookmark = bookmarks[index]; var name = Idaligo.Core.def(bookmark.name, ""); var id = Idaligo.Core.def(bookmark.id, ""); var url = Idaligo.Core.def(bookmark.url, ""); var isDefault = Idaligo.Core.def(bookmark.def, ""); builder.appendElement("LI"); builder.appendElement("A").withAttribute("href", url).appendText(name).stepBack(); if (bookmark.def) { builder.appendText(" (default)"); } builder.appendText(" "); var elmDelete = builder.appendElement("A").withAttribute("href", "#").appendText("Delete").getCurrentElement(); elmDelete.bookmarkId = id; Idaligo.Event.handle(this, elmDelete, Idaligo.Event.TYPE.CLICK, function(s, e) { return me.deleteSavedPageClicked(s.bookmarkId); }); builder.stepBack(); builder.stepBack(); } } else { this.showNoBookmarks(); } } MapApp.SavedPages.prototype.showNoBookmarks = function() { var builder = new Idaligo.Dom.Builder(this.elmSavedPages); builder.removeChildNodes(); builder.appendElement("DIV").withAttribute("style", "text-align:center;").appendText("Nothing has been saved yet"); } MapApp.SavedPages.prototype.removeBookmark = function(id) { Idaligo.Error.checkArgumentAsNotEmptyString(id); var elmUl = Idaligo.Error.checkElement(Idaligo.Dom.firstChildElement(this.elmSavedPages, "UL"), "Saved pages list"); var lis = this.elmSavedPages.getElementsByTagName("LI"); var found = false; var total = 0; for (var index = 0; index < lis.length; index ++) { var elmLi = lis[index]; var as = elmLi.getElementsByTagName("A"); var elmDelete = Idaligo.Error.checkElement(Idaligo.Dom.tryFindByIndex(as, 1), "Link to delete a saved page"); if (elmDelete.bookmarkId == id) { found = true; elmUl.removeChild(elmLi); } total ++; } if (found && lis.length == 0) // just removed the very last bookmark { this.showNoBookmarks(); } } //MapApp.SavedPages.prototype.askToProceedByDefaultBookmark = function(dialog, proceedHanlder) //{ // Idaligo.Error.checkArgument(dialog, "dialog"); // Idaligo.Error.checkArgument(proceedHanlder, "proceedHandler"); // // dialog.build(function(elmHeader, elmDetails, elmFooter, elmDialog, elmBackground) // { // Idaligo.Css.setDisplay(elmHeader, false); // var builder = new Idaligo.Dom.Builder(elmDetails); // builder.removeChildNodes().appendText("Would you like to proceed to your default saved page?"); // var noHandler = function() // { // dialog.hide(); // return false; // }; // // var yesHandler = function() // { // dialog.hide(); // proceedHanlder(); // return false; // } // builder.startWith(elmFooter); // var elmYes = MapApp.BuildHelper.buildButton(builder, "Yes", yesHandler, this); // builder.appendText(" "); // var elmNo = MapApp.BuildHelper.buildButton(builder, "No", noHandler, this); // MapApp.BuildHelper.handleKeyboard([elmYes, elmNo], [{key:27, handler:noHandler}]); // // return elmYes; // }); //} MapApp.SavedPages.prototype.askForName = function(dialog, nameHandler) { Idaligo.Error.checkArgument(dialog, "dialog"); Idaligo.Error.checkArgument(nameHandler, "nameHandler"); dialog.build(function(elmHeader, elmDetails, elmFooter, elmDialog, elmBackground) { var builder = new Idaligo.Dom.Builder(elmHeader); builder.removeChildNodes().appendText("Give it a name"); builder.startWith(elmDetails).removeChildNodes(); var elmName = builder.appendInput("text", true, [{n:"maxlength", v:30}]).getCurrentElement(); elmName.style.width = "140px"; var elmIsDefault = builder.stepBack().appendElement("BR", false).appendInput("checkbox", true, [{n:"id", v:"elmMakeDefault"}]).getCurrentElement(); builder.stepBack().appendElement("LABEL").withAttribute("for", "elmMakeDefault").appendText("Set as default"); var cancelHandler = function() { dialog.hide();return false; }; var okHandler = function() { var name = elmName.value; if (Idaligo.Core.emptyString(name)) { alert("Please, specify the name"); elmName.focus(); } else { dialog.hide(); nameHandler(Idaligo.Core.trimString(name), elmIsDefault.checked); } return false; } builder.startWith(elmFooter); var elmOk = MapApp.BuildHelper.buildButton(builder, "Save", okHandler, this); builder.appendText(" "); var elmCancel = MapApp.BuildHelper.buildButton(builder, "Cancel", cancelHandler, this); MapApp.BuildHelper.handleKeyboard([elmName, elmIsDefault], [{key:13, handler:okHandler}, {key:27, handler:cancelHandler}]); MapApp.BuildHelper.handleKeyboard([elmCancel, elmOk], [{key:27, handler:cancelHandler}]); return elmName; }); } MapApp.SavedPages.prototype.signInClicked = function() { var handler = this.onSignInRequested; if (Idaligo.Core.defined(handler)) { handler(); } return false; } MapApp.SavedPages.prototype.deleteSavedPageClicked = function(id) { var handler = this.onDeleteSavedPage; if (Idaligo.Core.defined(handler)) { handler(id); } return false; } MapApp.SavedPages.prototype.savePageClicked = function() { var handler = this.onSavePage; if (Idaligo.Core.defined(handler)) { handler(); } return false; } MapApp.SavedPages.prototype.onSignInRequested = null; MapApp.SavedPages.prototype.onDeleteSavedPage = null; MapApp.SavedPages.prototype.onSavePage = null;/// /// MapApp.Pager = function() { this._count = 0; this._pageNumber = 0; } MapApp.Pager.numberOfPagesSeen = 2; MapApp.Pager.separator = " "; MapApp.Pager.prototype.initialize = function(info) { Idaligo.Error.checkArgument(info, "info"); this._count = info.count; this._total = info.total; this._startDate = info.start; var tail = this._total % this._count; this._numberOfPages = (tail > 0 ? 1 : 0) + (this._total - tail) / this._count; var diff = info.offset % this._count; this._pageNumber = (info.offset - diff) / this._count; } MapApp.Pager.prototype.go = function(pageNumber) { if (pageNumber >= this._numberOfPages) { this._pageNumber = this._pageNumber - 1; } else if (pageNumber < 0) { this._pageNumber = 0; } else { this._pageNumber = pageNumber; } var handler = this.onPageChanged; if (Idaligo.Core.defined(handler)) { handler(); } } MapApp.Pager.prototype.build = function(builder) { Idaligo.Error.checkArgument(builder, "builder"); if (this._total > 0) { var from = this._pageNumber - MapApp.Pager.numberOfPagesSeen; if (from < 0) from = 0; var to = this._pageNumber + MapApp.Pager.numberOfPagesSeen; if (to >= this._numberOfPages) to = this._numberOfPages - 1; // going back var needSeparator = false; if (from > 0) { var elmPage = builder.appendElement("A").appendText(((from == 1) ? "1" : "...")).withAttribute("href", "#").getCurrentElement(); Idaligo.Event.handle(this, elmPage, Idaligo.Event.TYPE.CLICK, function() {return this.go(from - 1); return false;}); builder.stepBack(); needSeparator = true; } for (var index = from; index <= to; index ++) { if (needSeparator) { builder.appendText(MapApp.Pager.separator); } var numberToDisplay = index + 1; if (index == this._pageNumber) { builder.appendText(numberToDisplay); } else { var elmPage = builder.appendElement("A").appendText(numberToDisplay).withAttribute("href", "#").getCurrentElement(); elmPage.number = index; Idaligo.Event.handle(this, elmPage, Idaligo.Event.TYPE.CLICK, function(e, s) {return this.go(e.number);return false;}); builder.stepBack(); } needSeparator = true; } if (to < this._numberOfPages - 1) { if (needSeparator) { builder.appendText(MapApp.Pager.separator); } var elmPage = builder.appendElement("A").appendText(((to == this._numberOfPages - 2) ? this._numberOfPages : "...")).withAttribute("href", "#").getCurrentElement(); Idaligo.Event.handle(this, elmPage, Idaligo.Event.TYPE.CLICK, function() {return this.go(to + 1);return false;}); builder.stepBack() needSeparator = true; } } } MapApp.Pager.prototype.getPageNumber = function() { return this._pageNumber; } MapApp.Pager.prototype.getNumberOfPages = function() { return this._numberOfPages; } MapApp.Pager.prototype.getOffset = function() { return this._pageNumber * this.getCount(); } MapApp.Pager.prototype.getCount = function() { return this._count; } MapApp.Pager.prototype.getTotal = function() { return this._total; } MapApp.Pager.prototype.getStartDate = function() { return this._startDate; } MapApp.Pager.prototype.onPageChanged = function () {} // to be overriden/// MapApp.What = function(elementCrimes, elementScr, /* elementComplaints, elementInspection, */ elementBuildingPermits, elementPublicSpacePermits, elementSchools) { Idaligo.Error.checkArgument(elementCrimes, "elementCrimes"); Idaligo.Error.checkArgument(elementScr, "elementSrc"); // Idaligo.Error.checkArgument(elementComplaints, "elementComplaints"); // Idaligo.Error.checkArgument(elementInspection, "elementInspection"); Idaligo.Error.checkArgument(elementBuildingPermits, "elementBuildingPermits"); Idaligo.Error.checkArgument(elementPublicSpacePermits, "elementPublicSpacePermits"); Idaligo.Error.checkArgument(elementSchools, "elementSchools"); var collections = new Array(); this.populate = function(elementContainer, key) { Idaligo.Error.checkArgument(elementContainer, "elementContainer"); Idaligo.Error.checkArgument(key, "key"); var checkboxes = new Array(); collections.push ({ container: elementContainer , items: checkboxes , key: key , hasAny:function() { for (var index = 0; index < this.items.length; index ++) { if (this.items[index].checked) { return true; } } return false; } }); if (elementContainer.tagName == "INPUT") { checkboxes.push(elementContainer); } else { var elementCheckboxes = elementContainer.getElementsByTagName("INPUT"); if (elementCheckboxes.length < 1) { throw new Error("Checkbox container '" + elementContainer.id + "' does not have any checkboxes."); } for (var index = 0; index < elementCheckboxes.length; index ++) { var elmCheckbox = elementCheckboxes[index]; checkboxes.push(elmCheckbox); } } } this.populate(elementCrimes, "crm"); this.populate(elementScr, "src"); // this.populate(elementComplaints, "cmp"); // this.populate(elementInspection, "ins"); this.populate(elementBuildingPermits, "bp"); this.populate(elementPublicSpacePermits, "psp"); this.populate(elementSchools, "sch"); this.dump = function(values) { for (var collectionIndex = 0; collectionIndex < collections.length; collectionIndex ++) { var collection = collections[collectionIndex]; var key = collection.key; if (collection.container.tagName == "INPUT") { values.addBoolean(key, collection.container.checked); } else { var atLeastOne = false; for (var index = 0; index < collection.items.length; index ++) { var checkbox = collection.items[index]; if (checkbox.checked) { atLeastOne = true; values.add(key, checkbox.id.substr(checkbox.id.indexOf('_') + 1)); } } if (! atLeastOne) { values.addNull(key); } } } } this.hasAnyChecked = function() { for (var collectionIndex = 0; collectionIndex < collections.length; collectionIndex ++) { var collection = collections[collectionIndex]; if (collection.hasAny()) { return true; } } return false; } } /// /// /// /// /// MapApp.Login = function(elmLogin) { Idaligo.Error.checkArgument(elmLogin, "elmLogin"); this.elmLogin = Idaligo.Error.checkArgument(elmLogin); this.elmToggler = Idaligo.Error.checkElement(Idaligo.Dom.firstChildElement(elmLogin, "DIV"), "Header of the login pane"); this.elmToggler.style.cursor = "pointer"; this.elmPane = Idaligo.Error.checkElement(Idaligo.Dom.nextSiblingElement(this.elmToggler, "DIV"), "Main part of the login pane"); var elmPaneSignIn = Idaligo.Error.checkElement(Idaligo.Dom.firstChildElement(this.elmPane, "DIV"), "Sign in part of the login pane"); var elmPaneSignOut = Idaligo.Error.checkElement(Idaligo.Dom.nextSiblingElement(elmPaneSignIn, "DIV"), "Sign out part of the login pane"); this.signIn = new MapApp.Login.SignIn(elmPaneSignIn); this.signOut = new MapApp.Login.SignOut(elmPaneSignOut); Idaligo.Event.handle(this, this.elmToggler, Idaligo.Event.TYPE.CLICK, this.toggle); } MapApp.Login.prototype.setSignInState = function() { this.active = this.signIn; this.signIn.enable(this.elmToggler); this.signOut.disable(); this.close(); } MapApp.Login.prototype.setSignOutState = function(userName) { this.active = this.signOut; this.signIn.disable(); this.signOut.enable(userName, this.elmToggler); this.close(); } MapApp.Login.prototype.setState = function(openClosed) { Idaligo.Css.setDisplay(this.elmPane, openClosed); if (openClosed) { this.active.open(); } else { this.active.close(); } Idaligo.Css.setDisplay(this.elmToggler, ! openClosed); } MapApp.Login.prototype.closed = function() { return this.elmToggler.style.display != "none"; } MapApp.Login.prototype.open = function() { this.setState(true); } MapApp.Login.prototype.hide = MapApp.Login.prototype.close = function() { this.setState(false); } // hide is needed for closing the login pane when empty space on the screen is clicked MapApp.Login.prototype.toggle = function() { if (this.closed()) this.open(); else this.close();} MapApp.Login.prototype.populateTobeHidden = function(elements) { Idaligo.Error.checkArgument(elements); elements.hide(this).guard(this.elmLogin); } MapApp.Login.SignIn = function(elmPane) { Idaligo.Error.checkArgument(elmPane, "elmPane"); this.elmPane = elmPane; var elements = this.elmPane.getElementsByTagName("INPUT"); if (Idaligo.Core.isNotEmptyArray(elements)) { for (var index = 0; index < elements.length - 1; index ++) { var element = elements[index]; Idaligo.Event.handle(this, element, Idaligo.Event.TYPE.KEYDOWN, function(s, e) { if (e.keyCode == 13) { this.loginButtonClicked() e.stopPropagation(); return false; } return true; }); } var elmSignInButton = elements[elements.length - 1]; Idaligo.Event.handle(this, elmSignInButton, Idaligo.Event.TYPE.CLICK, this.loginButtonClicked); } } MapApp.Login.SignIn.prototype.enable = function(elmToggler) { Idaligo.Error.checkArgument(elmToggler, "elmToggler"); new Idaligo.Dom.Builder(elmToggler).removeChildNodes().appendElement("B").appendText("Sign in"); elmToggler.title = "Sign in to save your searches"; Idaligo.Css.setDisplay(this.elmPane, true); } MapApp.Login.SignIn.prototype.disable = function() { Idaligo.Css.setDisplay(this.elmPane, false); } MapApp.Login.SignIn.prototype.open = function() { var inputs = this.elmPane.getElementsByTagName("INPUT"); var elmLogin = Idaligo.Error.checkElement(Idaligo.Dom.tryFindByIndex(inputs, 0), "Login textbox"); var elmPassword = Idaligo.Error.checkArgument(Idaligo.Dom.tryFindByIndex(inputs, 1), "Password textbox"); var elmRememberMe = Idaligo.Error.checkArgument(Idaligo.Dom.tryFindByIndex(inputs, 2), "Remember me checkbox"); if (! Idaligo.Core.emptyString(elmLogin.value)) { elmLogin.select(); } elmLogin.focus(); elmPassword.value = ""; } MapApp.Login.SignIn.prototype.close = function() { // do nothing } MapApp.Login.SignIn.prototype.loginButtonClicked = function() { var handler = this.action; if (Idaligo.Core.defined(handler)) { var inputs = this.elmPane.getElementsByTagName("INPUT"); var elmLogin = Idaligo.Error.checkElement(Idaligo.Dom.tryFindByIndex(inputs, 0), "Login textbox"); var elmPassword = Idaligo.Error.checkArgument(Idaligo.Dom.tryFindByIndex(inputs, 1), "Password textbox"); var elmRememberMe = Idaligo.Error.checkArgument(Idaligo.Dom.tryFindByIndex(inputs, 2), "Remember me checkbox"); var login = elmLogin.value; var password = elmPassword.value; var rememberMe = elmRememberMe.checked; handler(login, password, rememberMe); } } MapApp.Login.SignIn.prototype.action = null; MapApp.Login.SignOut = function(elmPane) { Idaligo.Error.checkArgument(elmPane, "elmPane"); this.elmPane = elmPane; } MapApp.Login.SignOut.prototype.enable = function(userName, elmToggler) { Idaligo.Error.checkArgument(elmToggler); new Idaligo.Dom.Builder(elmToggler).removeChildNodes().appendText(userName).stepBack().appendElement("BR", false).appendElement("B").appendText("Sign out"); elmToggler.title = "Sign out"; Idaligo.Css.setDisplay(this.elmPane, true); } MapApp.Login.SignOut.prototype.disable = function() { Idaligo.Css.setDisplay(this.elmPane, false); } MapApp.Login.SignOut.prototype.open = function() { var handler = this.action; if (Idaligo.Core.defined(handler)) { handler(); } } MapApp.Login.SignOut.prototype.close = function() { // do nothing } MapApp.Login.SignOut.prototype.action = null;/// /// /// MapApp.Navigation = function(elmMain, elmNoData, elmTimeline, elmPager) { this.elmMain = Idaligo.Error.checkArgument(elmMain, "elmMain"); this.elmTimeline = Idaligo.Error.checkArgument(elmTimeline, "elmTimeline"); this.elmPager = Idaligo.Error.checkArgument(elmPager, "elmPager"); this.elmNoData = Idaligo.Error.checkArgument(elmNoData, "elmNoData"); this.show = function() { Idaligo.Css.setDisplay(this.elmMain, true); } this.hide = function() { Idaligo.Css.setDisplay(this.elmMain, false); } } MapApp.Navigation.prototype.initialize = function(dates, pager) { Idaligo.Error.checkArgument(dates, "dates"); Idaligo.Error.checkArgument(pager, "pager"); // show the whole navigation panel this.show(); // initializing the timeline control var me = this; if (! Idaligo.Core.defined(this.timeline)) { this.timeline = new Idaligo.UI.TimeLine(this.elmTimeline, new Date().date(), Idaligo.UI.TimeLine.ZOOM.MONTH, function(dt) { var handler = me.onTimeChosen; if (Idaligo.Core.defined(handler)) { handler(dt); } }); } this.timeline.initialize(dates, Idaligo.UI.TimeLine.ZOOM.MONTH); // initializing pager if (! Idaligo.Core.defined(this.pager)) { this.pager = new MapApp.Pager(); this.pager.onPageChanged = function() { var handler = me.onPageChanged; if (Idaligo.Core.defined(handler)) { handler(); } } } this.pager.initialize(pager); this.build(new Idaligo.Dom.Builder(this.elmPager)); } MapApp.Navigation.prototype.initializeTimeline = function(dates) { Idaligo.Error.checkArgument(dates, "dates"); this.timeline.initialize(dates, Idaligo.UI.TimeLine.ZOOM.MONTH); this.build(new Idaligo.Dom.Builder(this.elmPager)); } MapApp.Navigation.prototype.onTimeChosen = null; MapApp.Navigation.prototype.build = function(builder) { Idaligo.Error.checkArgument(builder, "builder"); var elmRoot = builder.getCurrentElement(); var tmRg = this.timeline.tm.dataTmRg; var pageNumber = this.pager.getPageNumber(); var numberOfPages = this.pager.getNumberOfPages(); var startDate = this.pager.getStartDate(); var sty = startDate.getFullYear(); var stm = startDate.getMonth(); var std = startDate.getDate(); builder.removeChildNodes(); var hasData = tmRg.hasAll() && numberOfPages > 0; if (tmRg.hasAll() && numberOfPages > 0) { var start = new Date(tmRg.f); var end = new Date(tmRg.t); var sy = start.getFullYear(); var ey = end.getFullYear(); var sm = start.getMonth(); var em = end.getMonth(); var sd = start.getDate(); var ed = end.getDate(); builder.appendText("Displaying "); if (sy == ey && sm == em && sd == ed) { builder.appendElement("B"); MapApp.BuildHelper.buildDate(builder, sm, sd, sy); builder.stepBack(); } else { builder.appendText("from ").appendElement("B"); MapApp.BuildHelper.buildDate(builder, sm, sd, ((sy != ey) ? sy : null)); builder.stepBack().appendText(" to ").appendElement("B"); MapApp.BuildHelper.buildDate(builder, em, ed, ey); builder.stepBack(); } if (numberOfPages > 1) { builder.appendText(" pages: "); this.pager.build(builder); } } else { builder.startWith(this.elmNoData).removeChildNodes(); //builder.appendText("No data starting from "); builder.appendText("There are no results for your search starting from "); builder.appendElement("B"); MapApp.BuildHelper.buildDate(builder, stm, std, sty); builder.stepBack(); } Idaligo.Css.setDisplay(this.elmTimeline, true); Idaligo.Css.setDisplay(this.elmPager, hasData); Idaligo.Css.setDisplay(this.elmNoData, ! hasData); } /// /// /// MapApp.BuildHelper = function() {} MapApp.BuildHelper.buildButton = function(builder, name, handler, holder) { Idaligo.Error.checkArgument(builder, "builder"); Idaligo.Error.checkArgumentAsNotEmptyString(name, "name"); Idaligo.Error.checkArgument(handler, "handler"); Idaligo.Error.checkArgument(holder, "holder"); var elmButton = builder.appendInput("button", true, [{n:"value", v:name}]).getCurrentElement(); elmButton.className = "btn"; builder.stepBack(); Idaligo.Event.handle(holder, elmButton, Idaligo.Event.TYPE.CLICK, handler); return elmButton; } MapApp.BuildHelper.dumpException = function(builder, e) { Idaligo.Error.checkArgument(builder, "builder"); if (Idaligo.Core.defined(e)) { var hasSomething = false; if (! Idaligo.Core.emptyString(e.name)) { hasSomething = true; builder.appendElement("DIV").appendElement("B").appendText(e.name).stepBack(); if (! Idaligo.Core.emptyString(e.lineNumber)) { builder.appendText(" at line " + e.lineNumber); } if (! Idaligo.Core.emptyString(e.fileName)) { builder.appendText(" in " + e.fileName); } builder.stepBack(); } if (! Idaligo.Core.emptyString(e.message)) { hasSomething = true; builder.appendElement("DIV").appendText(e.message).stepBack(); } if (! Idaligo.Core.emptyString(e.stack)) { hasSomething = true; builder.appendElement("PRE").appendText(e.stack).stepBack(); } if (! hasSomething) { builder.appendText(e); } } else { builder.appendText("No information provided."); } } MapApp.BuildHelper.handleKeyboard = function(elements, handlers) { Idaligo.Error.checkArgumentAsArray(elements, "elements"); Idaligo.Error.checkArgumentAsArray(handlers, "handlers"); for (var index = 0; index < elements.length; index ++) { var element = elements[index]; Idaligo.Event.handle(this, element, Idaligo.Event.TYPE.KEYDOWN, function(s, e) { for (var handlerIndex = 0; handlerIndex < handlers.length; handlerIndex ++) { var handler = handlers[handlerIndex]; if (e.keyCode == handler.key) { handler.handler(); e.stopPropagation(); return false; } } return true; }); } } MapApp.BuildHelper.getSuffix = function(number) { Idaligo.Error.checkArgumentAsNumber(number, "number"); var result; var rest = number % 10; if (number == 11 || number == 12 || number == 13) { result = "th"; } else { if (rest == 1) { result = "st"; } else if (rest == 2) { result = "nd"; } else if (rest == 3) { result = "rd"; } else { result = "th"; } } return result; } MapApp.BuildHelper.buildSuffix = function(builder, number) { Idaligo.Error.checkArgument(builder, "builder"); Idaligo.Error.checkArgumentAsNumber(number, "number"); builder.appendElement("SUP").appendText(MapApp.BuildHelper.getSuffix(number)); builder.stepBack(); } MapApp.BuildHelper.buildDate = function(builder, month, day, year_) { Idaligo.Error.checkArgument(builder, "builder"); Idaligo.Error.checkArgumentAsNumber(month, "month"); Idaligo.Error.checkArgumentAsNumber(day, "day"); builder.appendText(Idaligo.Time.monthNames[month] + " " + day); MapApp.BuildHelper.buildSuffix(builder, day); if (! Idaligo.Core.emptyString(year_)) { builder.appendText(", " + year_); } } MapApp.BuildHelper.capitalize = function(text) { if (Idaligo.Core.emptyString(text)) { return ""; } else { text = Idaligo.Core.trimString(text); if (text.length > 1) { return text.substr(0, 1).toUpperCase() + text.substr(1).toLowerCase(); } else if (text.length > 0) { return text.substr(0, 1).toUpperCase(); } else { return ""; } } } MapApp.BuildHelper.normalize = function(text) { if (Idaligo.Core.emptyString(text)) { return ""; } else { return MapApp.BuildHelper.capitalize(text); } }