2015-02-05 16:08:05 -05:00
|
|
|
import {DOM, document, location} from 'angular2/src/facade/dom';
|
|
|
|
import {NumberWrapper, BaseException, isBlank} from 'angular2/src/facade/lang';
|
2015-01-09 21:00:04 -05:00
|
|
|
|
|
|
|
export function getIntParameter(name:string) {
|
2015-01-15 13:51:47 -05:00
|
|
|
return NumberWrapper.parseInt(getStringParameter(name), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getStringParameter(name:string) {
|
|
|
|
var els = DOM.querySelectorAll(document, `input[name="${name}"]`)
|
|
|
|
var value;
|
|
|
|
var el;
|
|
|
|
|
|
|
|
for (var i=0; i<els.length; i++) {
|
|
|
|
el = els[i];
|
|
|
|
if ((el.type !== 'radio' && el.type !== 'checkbox') || el.checked) {
|
|
|
|
value = el.value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isBlank(value)) {
|
2015-01-09 21:00:04 -05:00
|
|
|
throw new BaseException(`Could not find and input field with name ${name}`);
|
|
|
|
}
|
2015-01-15 13:51:47 -05:00
|
|
|
|
|
|
|
return value;
|
2015-01-09 21:00:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function bindAction(selector:string, callback:Function) {
|
|
|
|
var el = DOM.querySelector(document, selector);
|
|
|
|
DOM.on(el, 'click', function(_) {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|