Permalink
Browse files

fix(config): perform config regardless when the form config is instan…

…tiatied
  • Loading branch information...
bas080
bas080 committed Jun 14, 2016
1 parent 5a8e348 commit f850a4cc9569706eee4de82281d08e536b8d31d9
Showing with 67 additions and 71 deletions.
  1. +63 −6 src/aurelia-form.js
  2. +4 −65 src/config.js
@@ -1,19 +1,76 @@
import {Config} from './config';
import {Config as ViewManagerConfig} from 'aurelia-view-manager';
export {entitySchema} from './entity-schema';
export {Form} from './form';
export {FormField} from './form-field';

export function configure(aurelia, configCallback) {
let viewManagerConfig = aurelia.container.get(ViewManagerConfig);
let formConfig = aurelia.container.get(Config);

viewManagerConfig.configureNamespace('spoonx/form', {
framepath: '{{base}}/framework/{{framework}}', // framework path
base : './../component',
location : '{{framepath}}/{{view}}.html',
map : {
/* aurelia-form specific view are also overridable */
'form-field' : './form-field.html',
'form-fields' : './form-fields.html',
'schema-form' : './schema-form.html',

/* custom elements with a view model do not end with .html */
actions : '{{framepath}}/actions',
collection : '{{framepath}}/collection',

/* all input components */
text : '{{framepath}}/input.html',
button : '{{framepath}}/input.html',
color : '{{framepath}}/input.html',
date : '{{framepath}}/input.html',
datetime : '{{framepath}}/input.html',
'datetime-local': '{{framepath}}/input.html',
email : '{{framepath}}/input.html',
month : '{{framepath}}/input.html',
number : '{{framepath}}/input.html',
password : '{{framepath}}/input.html',
range : '{{framepath}}/input.html',
search : '{{framepath}}/input.html',
tel : '{{framepath}}/input.html',
time : '{{framepath}}/input.html',
url : '{{framepath}}/input.html',
week : '{{framepath}}/input.html'
}
});

formConfig.configure({
/*
* Instead of defining a framework or custom component for every variant
* on the name of a type, it is easier to alias that variant so the
* variant is changed to the main type.
*/
aliases : {
options : 'select',
buttons : 'actions',
nested : 'fieldset',
undefined: 'text',
null : 'text',
int : 'number',
integer : 'number',
float : 'number',
string : 'text',
bool : 'checkbox',
boolean : 'checkbox'
}
});

if (typeof configCallback === 'function') {
/* only perform configurations when providing a configCallback */
let config = aurelia.container.get(Config);
configCallback(config);
configCallback(formConfig);
}

aurelia.globalResources(
'./elements/schema-form',
'./elements/form-fields',
'./elements/form-field'
'./component/schema-form',
'./component/form-fields',
'./component/form-field'
);
}

@@ -1,76 +1,15 @@
import extend from 'extend';
import {inject} from 'aurelia-dependency-injection';
import {Config as ViewManagerConfig} from 'aurelia-view-manager';
import {Config as ViewManagerConfig, ViewManager} from 'aurelia-view-manager';

const DEFAULT_FRAMEWORK = 'bootstrap';

@inject(ViewManagerConfig)
@inject(ViewManager, ViewManagerConfig)
export class Config {
constructor(viewManagerConfig) {
/***
* It might be best to store these configurations in a configuration file
* that is bootstrap specific.
*/
viewManagerConfig.configureNamespace('aurelia-form', {
base : './../frameworks/{{framework}}',
location : '{{base}}/{{view}}.html',
framework: DEFAULT_FRAMEWORK,
map : {

/* custom elements with a view model do not end with .html */
actions : '{{base}}/actions',
collection : '{{base}}/collection',

/* all input components */
text : '{{base}}/input.html',
button : '{{base}}/input.html',
color : '{{base}}/input.html',
date : '{{base}}/input.html',
datetime : '{{base}}/input.html',
'datetime-local': '{{base}}/input.html',
email : '{{base}}/input.html',
month : '{{base}}/input.html',
number : '{{base}}/input.html',
password : '{{base}}/input.html',
range : '{{base}}/input.html',
search : '{{base}}/input.html',
tel : '{{base}}/input.html',
time : '{{base}}/input.html',
url : '{{base}}/input.html',
week : '{{base}}/input.html'
}
});

/***
* defaults that are part of aurelia-form out of the box. They do need to be
* documented and maybe moved into a seperate file named defaults.js
*/
this.configure({

translate: false,
configurations = {}

/***
* Instead of defining a framework or custom component for every variant
* on the name of a type, it is easier to alias that variant so the
* variant is changed to the main type.
*/
aliases : {
buttons : 'actions',
nested : 'fieldset',
undefined: 'text',
null : 'text',
int : 'number',
integer : 'number',
float : 'number',
string : 'text',
bool : 'checkbox',
boolean : 'checkbox'
}
});
constructor(viewManager, viewManagerConfig) {
}

configurations = {}

/**
* convenient for getting a (nested) property in the configurations
* object.

0 comments on commit f850a4c

Please sign in to comment.