2011-07-29 18:48:43 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-05-16 10:49:48 +00:00
|
|
|
|
2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
Ox.PlacePicker <f:Ox.Element> PlacePicker Object
|
|
|
|
() -> <f> PlacePicker Object
|
|
|
|
(options) -> <f> PlacePicker Object
|
|
|
|
(options, self) -> <f> PlacePicker Object
|
|
|
|
options <o> Options object
|
|
|
|
id <s> element id
|
|
|
|
value <s|United States> default value of place input
|
|
|
|
self <o> shared private variable
|
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.PlacePicker = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
var that;
|
2011-09-17 18:36:09 +00:00
|
|
|
self = Ox.extend(self || {}, {
|
|
|
|
options: Ox.extend({
|
2011-04-22 22:03:10 +00:00
|
|
|
id: '',
|
|
|
|
value: 'United States'
|
|
|
|
}, options)
|
2011-06-19 17:48:32 +00:00
|
|
|
});
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self.$element = Ox.Element()
|
2011-04-22 22:03:10 +00:00
|
|
|
.css({
|
|
|
|
width: '256px',
|
|
|
|
height: '192px'
|
|
|
|
})
|
|
|
|
.append(
|
2011-06-19 17:48:32 +00:00
|
|
|
self.$topBar = Ox.Bar({
|
2011-04-22 22:03:10 +00:00
|
|
|
size: 16
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
MozBorderRadius: '0 8px 0 0',
|
|
|
|
WebkitBorderRadius: '0 8px 0 0'
|
|
|
|
})
|
|
|
|
.append(
|
2011-06-19 17:48:32 +00:00
|
|
|
self.$input = Ox.Input({
|
2011-04-22 22:03:10 +00:00
|
|
|
clear: true,
|
|
|
|
id: self.options.id + 'Input',
|
|
|
|
placeholder: 'Find',
|
|
|
|
width: 256
|
|
|
|
})
|
|
|
|
.bindEvent('submit', findPlace)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.append(
|
2011-06-19 17:48:32 +00:00
|
|
|
self.$container = Ox.Element()
|
2011-04-22 22:03:10 +00:00
|
|
|
.css({
|
|
|
|
width: '256px',
|
|
|
|
height: '160px'
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.append(
|
2011-06-19 17:48:32 +00:00
|
|
|
self.$bottomBar = Ox.Bar({
|
2011-04-22 22:03:10 +00:00
|
|
|
size: 16
|
|
|
|
})
|
|
|
|
.append(
|
2011-06-19 17:48:32 +00:00
|
|
|
self.$range = Ox.Range({
|
2011-04-22 22:03:10 +00:00
|
|
|
arrows: true,
|
|
|
|
id: self.options.id + 'Range',
|
|
|
|
max: 22,
|
|
|
|
size: 256,
|
|
|
|
thumbSize: 32,
|
|
|
|
thumbValue: true
|
|
|
|
})
|
|
|
|
.bindEvent('change', changeZoom)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
self.$input.$element.children('input[type=text]').css({
|
|
|
|
width: '230px',
|
|
|
|
paddingLeft: '2px',
|
|
|
|
MozBorderRadius: '0 8px 8px 0',
|
|
|
|
WebkitBorderRadius: '0 8px 8px 0'
|
|
|
|
});
|
|
|
|
self.$input.$element.children('input[type=image]').css({
|
|
|
|
MozBorderRadius: '0 8px 0 0',
|
|
|
|
WebkitBorderRadius: '0 8px 0 0'
|
|
|
|
});
|
|
|
|
self.$range.$element.children('input').css({
|
|
|
|
MozBorderRadius: 0,
|
|
|
|
WebkitBorderRadius: 0
|
|
|
|
});
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
that = Ox.Picker({
|
2011-04-22 22:03:10 +00:00
|
|
|
element: self.$element,
|
|
|
|
elementHeight: 192,
|
|
|
|
elementWidth: 256,
|
|
|
|
id: self.options.id,
|
|
|
|
overlap: self.options.overlap,
|
|
|
|
value: self.options.value
|
|
|
|
}, self)
|
|
|
|
.bindEvent('show', showPicker);
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
that.$label.bind('click', clickLabel);
|
2011-04-22 22:03:10 +00:00
|
|
|
|
|
|
|
self.map = false;
|
|
|
|
|
2011-09-17 17:39:38 +00:00
|
|
|
function changeZoom(data) {
|
2011-11-04 15:54:28 +00:00
|
|
|
//Ox.Log('Form', 'changeZoom')
|
2011-04-22 22:03:10 +00:00
|
|
|
self.$map.zoom(data.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
function clickLabel() {
|
|
|
|
var name = that.$label.html();
|
|
|
|
if (name) {
|
|
|
|
self.$input.options({
|
|
|
|
value: name
|
|
|
|
})
|
|
|
|
.triggerEvent('submit', {
|
|
|
|
value: name
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:39:38 +00:00
|
|
|
function findPlace(data) {
|
2011-11-04 15:54:28 +00:00
|
|
|
//Ox.Log('Form', 'findPlace', data);
|
2011-04-22 22:03:10 +00:00
|
|
|
self.$map.find(data.value, function(place) {
|
|
|
|
place && that.$label.html(place.geoname);
|
2011-06-19 17:48:32 +00:00
|
|
|
});
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
2011-09-17 17:39:38 +00:00
|
|
|
function onSelect(data) {
|
2011-04-22 22:03:10 +00:00
|
|
|
that.$label.html(data.geoname);
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:39:38 +00:00
|
|
|
function onZoom(data) {
|
2011-04-22 22:03:10 +00:00
|
|
|
self.$range.options({
|
|
|
|
value: data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPicker() {
|
|
|
|
if (!self.map) {
|
2011-06-19 17:48:32 +00:00
|
|
|
self.$map = Ox.Map({
|
2011-05-12 04:15:01 +00:00
|
|
|
clickable: true,
|
2011-04-22 22:03:10 +00:00
|
|
|
id: self.options.id + 'Map',
|
2011-11-30 14:56:01 +00:00
|
|
|
// fixme: this is retarded, allow for map without places
|
|
|
|
places: [{south: -85, west: -179, north: -85, east: 179}]
|
2011-05-12 04:15:01 +00:00
|
|
|
//places: [self.options.value]
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
.css({
|
2011-05-12 04:15:01 +00:00
|
|
|
top: '16px',
|
2011-04-22 22:03:10 +00:00
|
|
|
width: '256px',
|
|
|
|
height: '160px'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
select: onSelect,
|
|
|
|
zoom: onZoom
|
|
|
|
})
|
|
|
|
.appendTo(self.$container);
|
|
|
|
self.map = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|