[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[6094] trunk/UI/lib
- Subject: SF.net SVN: ledger-smb:[6094] trunk/UI/lib
- From: ..hidden..
- Date: Sun, 29 Sep 2013 02:41:09 +0000
Revision: 6094
http://sourceforge.net/p/ledger-smb/code/6094
Author: einhverfr
Date: 2013-09-29 02:41:09 +0000 (Sun, 29 Sep 2013)
Log Message:
-----------
First shot at new modularized dojo loader
Modified Paths:
--------------
trunk/UI/lib/TabularForm.js
trunk/UI/lib/setup.js
Added Paths:
-----------
trunk/UI/lib/Loader.js
Added: trunk/UI/lib/Loader.js
===================================================================
--- trunk/UI/lib/Loader.js (rev 0)
+++ trunk/UI/lib/Loader.js 2013-09-29 02:41:09 UTC (rev 6094)
@@ -0,0 +1,238 @@
+/* lsmb/lib/Loader
+ * A module for loading and setting up Dojo on LSMB screens.
+ *
+ * This exposes two methods:
+ *
+ * setup()
+ *
+ * sets up all widgets on a page
+ *
+ * createWidget(dnode)
+ *
+ * creates a wedget from a DOM node. Returns undef if the widget already
+ * exists. The choice to return undef allows one to check the return value
+ * of the function, and avoid calling if the widget already exists.
+ */
+
+define([
+ // base
+ 'dojo/_base/declare',
+ 'dijit/registry',
+ 'dojo/parser',
+ 'dojo/query',
+ 'dojo/ready',
+ // widgets
+ // row1
+ 'lsmb/lib/TabularForm',
+ 'dijit/form/Textarea',
+ 'lsmb/lib/DateTextBox',
+ 'dijit/form/CheckBox',
+ 'dijit/form/RadioButton',
+ 'dijit/form/TextBox',
+ 'lsmb/accounts/AccountSelector',
+ //row2
+ 'dijit/form/Select',
+ 'dijit/form/Button'
+ ],
+function(
+ // base
+ declare, registry, parser, query, ready,
+ // widgets
+ tabular, textarea, datebox, checkbox, radio, textbox, accountselector,
+ select, button) {
+ return declare(null, {
+ nodeMap: { // hierarchy nodeName->class, input type treated as class
+ // for INPUT elements, type beats class.
+ DIV: {
+ '__default': function(){ return undefined; },
+ 'tabularform': function(node){
+ return new tabular(node);
+ }
+
+ },
+ TEXTAREA: { '__default': function(input){
+ return new textarea(
+ { "name": input.name,
+ "value": input.innerHTML,
+ "label": input.title,
+ "cols": input.cols,
+ "rows": input.rows}, input);
+ }
+ },
+ INPUT: { 'hidden': function(){ return undefined},
+ 'date': function(input){
+ var style = {};
+ if (input.size !== undefined
+ && input.size !== '')
+ {
+ style['width'] =
+ (input.size * 0.6)
+ + 'em';
+ }
+ var val = input.value;
+ if (val == ''){
+ val = undefined;
+ }
+ return new datebox({
+ "label": input.title,
+ "value": val,
+ "name": input.name,
+ "id": input.id,
+ "style": style,
+ }, input);
+
+ },
+ 'checkbox': function(input){
+ return new checkbox({
+ "name": input.name,
+ "value": input.value,
+ "checked": input.checked
+ }, input);
+ },
+ 'radio': function(input){
+ return new radio({
+ "name": input.name,
+ "value": input.value,
+ "checked": input.checked
+ }, input);
+ },
+ 'password': function(input){
+ if (undefined !== registry.byNode(input)){
+ return undefined;
+ }
+ var style = {};
+ if (input.size !== undefined
+ && input.size !== '')
+ {
+ style['width'] = (input.size * 0.6)
+ + 'em';
+ }
+ return new textbox({
+ "label": input.title,
+ "value": input.value,
+ "name": input.name,
+ "style": style,
+ "id": input.id,
+ "type": 'password'
+
+ }, input);
+ },
+ 'AccountBox': function(input){
+ return new accountselector({
+ "name": input.name
+ }, input);
+ },
+ '__default': function(input){
+ if (undefined !== registry.byNode(input)){
+ return undefined;
+ }
+ var style = {};
+ if (input.size !== undefined
+ && input.size !== '')
+ {
+ style['width'] = (input.size * 0.6)
+ + 'em';
+ }
+ return new textbox({
+ "label": input.title,
+ "value": input.value,
+ "name": input.name,
+ "style": style,
+ "id": input.id
+ }, input);
+ }
+ },
+ SELECT: { '__default': function(input){
+ var optlist = [];
+ query('option', input).forEach(
+ function(opt){
+ var entry = {
+ "label": opt.innerHTML,
+ "id": input.id,
+ "value": opt.value
+ };
+ if (opt.selected){
+ entry["selected"] = true;
+ }
+ optlist.push(entry);
+ });
+
+ return new select(
+ { "name": input.name,
+ "options": optlist,
+ "label": input.title,
+ "id": input.id
+ } , input);
+ }
+ },
+ BUTTON: {
+ '__default': function(){
+ return new button(
+ { "name": input.name,
+ "type": input.type,
+ "id": input.id,
+ "label": input.innerHTML,
+ "value": input.value
+ }, input
+ );
+ }
+ }
+ },
+ constructor: function(){},
+ // createWidget(domNode)
+ //
+ // Creates a widget from a domNode. This is used in a number of cases,
+ // including the main dynamic parser and the lsmb/lib/TabularForm
+ // widget.
+ //
+ // Note that this *must* be called inside a ready() block, either by
+ // the parser.parse() or by setup().
+ getInputSize: function(dnode) {
+ return dnode.size * 0.6 + 'em';
+ },
+ createWidget: function(dnode) {
+ if (undefined !== registry.byNode(dnode)){
+ return undefined;
+ }
+ if (undefined == this.nodeMap[dnode.nodeName]){
+ return undefined;
+ }
+ if ('INPUT' == dnode.nodeName){
+ var classKey;
+ classKey = dnode.type;
+ if (undefined !== this.nodeMap.INPUT[classKey]){
+ return this.nodeMap.INPUT[classKey](dnode);
+ }
+ }
+ var classes = dnode.className.split(' ');
+ for (var i = 0; i <= classes.length; i++){
+ classKey=classes[i];
+ if (undefined !== this.nodeMap[dnode.nodeName][classKey]){
+ return this.nodeMap[dnode.nodeName][classKey](dnode);
+ }
+ }
+ if (undefined !== this.nodeMap[dnode.nodeName].__default){
+ return this.nodeMap[dnode.nodeName].__default(dnode);
+ }
+ return undefined;
+ },
+ setup: function(){
+ var declarative = false;
+ var myself = this;
+ query('body.dojo-declarative').forEach(function(){
+ declarative = true;
+ });
+ if (declarative){
+ return parser.parse();
+ }
+ query('*').forEach(function(dnode){
+ ready(function(){
+ widget = myself.createWidget(dnode);
+ if (undefined !== widget){
+ widget.startup();
+ }
+ });
+ });
+ }
+ });
+});
Modified: trunk/UI/lib/TabularForm.js
===================================================================
--- trunk/UI/lib/TabularForm.js 2013-09-28 07:03:11 UTC (rev 6093)
+++ trunk/UI/lib/TabularForm.js 2013-09-29 02:41:09 UTC (rev 6094)
@@ -67,7 +67,7 @@
'dijit/layout/ContentPane',
'dojo/query',
'dojo/window',
- 'lsmb/lib/loader',
+ 'lsmb/lib/Loader',
'dojo/_base/declare'
],
function(TableContainer, dom, cls, registry, cp, query, win, loader,
Modified: trunk/UI/lib/setup.js
===================================================================
--- trunk/UI/lib/setup.js 2013-09-28 07:03:11 UTC (rev 6093)
+++ trunk/UI/lib/setup.js 2013-09-29 02:41:09 UTC (rev 6094)
@@ -6,107 +6,18 @@
* and textbox class detection. input is the node. The others are appropriate
* dijit/dojo classes for the widgets.
*/
-
+/*
function construct_form_node(query, cls, registry,
textbox, checkbox, radio, select, button, textarea,
input)
{
if (input.nodeName == 'INPUT'){
- if (input.type == 'hidden') {
- return undefined;
- } else if (input.type == 'text'){
- if (cls.contains(input, 'date')){
- // logic to pick dates
- //
- // I have now changed it to a DateTextBox, but apparently we
- // also have a wrapped version which we should use. Will move
- // that over shortly. --CT
- return require(['lsmb/lib/DateTextBox', 'dojo/domReady!'],
- function(datebox){
- var val = input.value;
- if (val == ''){
- val = undefined;
- }
- new datebox({
- "label": input.title,
- "value": val,
- "name": input.name,
- "id": input.id,
- "style": style,
- }, input);
- }
- );
- } else if (cls.contains(input, 'AccountBox')){
- return require(['lsmb/accounts/AccountSelector'],
- function(accountselector){
- return new accountselector({
- "name": input.name
- }, input);
- }
- );
- } else {
- var style = {};
- if (input.size !== undefined && input.size !== ''){
- style['width'] = (input.size * 0.6) + 'em';
- }
- return new textbox({
- "label": input.title,
- "value": input.value,
- "name": input.name,
- "style": style,
- "id": input.id
- }, input);
- }
-
- } else if (input.type == 'checkbox'){
- return new checkbox({
- "name": input.name,
- "value": input.value,
- "checked": input.checked
- }, input);
} else if (input.type == 'radio'){
- return new radio({
- "name": input.name,
- "value": input.value,
- "checked": input.checked
- }, input);
} else if (input.type == 'password'){
- var style = {};
- if (input.size !== undefined && input.size !== ''){
- style['width'] = (input.size * 0.6) + 'em';
- }
- return new textbox({
- "label": input.title,
- "value": input.value,
- "name": input.name,
- "style": style,
- "id": input.id,
- "type": 'password'
- }, input);
}
} else if (input.nodeName == 'SELECT'){
- var optlist = [];
- query('option', input).forEach(
- function(opt){
- var entry = {
- "label": opt.innerHTML,
- "id": input.id,
- "value": opt.value
- };
- if (opt.selected){
- entry["selected"] = true;
- }
- optlist.push(entry);
- });
-
- return new select(
- { "name": input.name,
- "options": optlist,
- "label": input.title,
- "id": input.id
- } , input);
} else if (input.nodeName == 'BUTTON'){
return new button(
{ "name": input.name,
@@ -152,7 +63,7 @@
*
* As of first commit only setting up table containers.
*/
-
+/*
require( ['dojo/query',
'dijit/registry',
'dojo/dom-class',
@@ -161,7 +72,6 @@
'dijit/form/TextBox',
'dijit/form/CheckBox',
'dijit/form/RadioButton',
- 'dijit/form/Select',
'dijit/form/Button',
'dijit/layout/ContentPane',
'dijit/form/Textarea',
@@ -269,4 +179,10 @@
}
});
}
-);
+);*/
+
+require(['lsmb/lib/Loader', 'dojo/domReady!'],
+function(l){
+ loader = new l;
+ loader.setup();
+});
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits