Expose special property logic in builder.

Called by the Angular renderer.
This commit is contained in:
Hristo Deshev
2015-09-07 19:11:02 +03:00
parent 0e61d1a120
commit 28898dcd32
2 changed files with 38 additions and 15 deletions

View File

@ -5,6 +5,9 @@ declare module "ui/builder/component-builder" {
export function getComponentModule(elementName: string, namespace: string, attributes: Object, exports: Object): ComponentModule;
export function setPropertyValue(instance: view.View, instanceModuleExports: Object, pageExports: Object, propertyName: string, propertyValue: string) : void;
export var specialProperties: Array<string>;
export function setSpecialPropertyValue(instance: view.View, propertyName: string, propertyValue: string): boolean;
export interface ComponentModule {
component: view.View;
exports: any;

View File

@ -29,6 +29,16 @@ var DOCK = "dock";
var LEFT = "left";
var TOP = "top";
export var specialProperties: Array<string> = [
ROW,
COL,
COL_SPAN,
ROW_SPAN,
DOCK,
LEFT,
TOP,
]
var eventHandlers = {};
export function getComponentModule(elementName: string, namespace: string, attributes: Object, exports: Object): definition.ComponentModule {
@ -112,6 +122,28 @@ export function getComponentModule(elementName: string, namespace: string, attri
return componentModule;
}
export function setSpecialPropertyValue(instance: view.View, propertyName: string, propertyValue: string) {
if (propertyName === ROW) {
gridLayoutModule.GridLayout.setRow(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === COL) {
gridLayoutModule.GridLayout.setColumn(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === COL_SPAN) {
gridLayoutModule.GridLayout.setColumnSpan(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === ROW_SPAN) {
gridLayoutModule.GridLayout.setRowSpan(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === LEFT) {
absoluteLayoutDef.AbsoluteLayout.setLeft(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === TOP) {
absoluteLayoutDef.AbsoluteLayout.setTop(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === DOCK) {
console.log('set dock: ' + propertyName + ' -> ' + propertyValue);
dockLayoutDef.DockLayout.setDock(instance, propertyValue);
} else {
return false;
}
return true;
}
export function setPropertyValue(instance: view.View, instanceModule: Object, exports: Object, propertyName: string, propertyValue: string) {
// Note: instanceModule can be null if we are loading custom compnenet with no code-behind.
var isEventOrGesture: boolean = isKnownEventOrGesture(propertyName, instance);
@ -136,20 +168,8 @@ export function setPropertyValue(instance: view.View, instanceModule: Object, ex
if (types.isFunction(handler)) {
instance.on(propertyName, handler);
}
} else if (propertyName === ROW) {
gridLayoutModule.GridLayout.setRow(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === COL) {
gridLayoutModule.GridLayout.setColumn(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === COL_SPAN) {
gridLayoutModule.GridLayout.setColumnSpan(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === ROW_SPAN) {
gridLayoutModule.GridLayout.setRowSpan(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === LEFT) {
absoluteLayoutDef.AbsoluteLayout.setLeft(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === TOP) {
absoluteLayoutDef.AbsoluteLayout.setTop(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === DOCK) {
dockLayoutDef.DockLayout.setDock(instance, propertyValue);
} else if (setSpecialPropertyValue(instance, propertyName, propertyValue)) {
// Already set by setSpecialPropertyValue
} else {
var attrHandled = false;