updated by GasGit automation
This commit is contained in:
parent
9317041efb
commit
fe531809fd
1 changed files with 257 additions and 147 deletions
|
@ -19,7 +19,8 @@ function Elementer() {
|
|||
classes: {
|
||||
branch: "",
|
||||
nav: {
|
||||
prevIcon: ""
|
||||
prevIcon: "",
|
||||
showTitle:false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,43 +43,51 @@ function Elementer() {
|
|||
tdLabel: "",
|
||||
icon: "mui--text-dark-secondary material-icons",
|
||||
tdIcon: "mui--align-middle",
|
||||
tdNextIcon:"mui--align-middle mui--text-right",
|
||||
option:"",
|
||||
nav: {
|
||||
nextIcon: "chevron_right",
|
||||
prevIcon: "chevron_left"
|
||||
prevIcon: "", // chevron_left to enable back at top of page.
|
||||
showTitle:true
|
||||
},
|
||||
hide: "mui--hide",
|
||||
show: "mui--show"
|
||||
};
|
||||
|
||||
var defStyles_ = {
|
||||
td: "padding:3px",
|
||||
tdLabel: "padding:3px",
|
||||
tdIcon: "padding:3px;max-width:30px;",
|
||||
tdElement: "padding:3px",
|
||||
td: "padding:3px;",
|
||||
tdLabel: "padding:3px;",
|
||||
tdIcon: "padding:3px;max-width:32px;",
|
||||
tdElement: "padding:3px;",
|
||||
backLabel:"position:relative;vertical-align: middle;",
|
||||
icon:"vertical-align: middle;",
|
||||
elementContainer:"padding:0px;margin:0;",
|
||||
navCursor:"cursor: pointer; cursor: hand;",
|
||||
backLabel:"cursor: pointer; cursor: hand;"
|
||||
backLabel:"cursor: pointer; cursor: hand;",
|
||||
tdNextIcon: "padding:3px;",
|
||||
};
|
||||
|
||||
var defDetail_ = {
|
||||
selectTemplate: {
|
||||
tag: "SELECT",
|
||||
classes:{
|
||||
elementContainer:"mui-select"
|
||||
elementContainer:""
|
||||
},
|
||||
values:{
|
||||
property:"value",
|
||||
resetable:true
|
||||
}
|
||||
},
|
||||
|
||||
textAreaTemplate: {
|
||||
tag: "TEXTAREA",
|
||||
label:"Input text area",
|
||||
classes:{
|
||||
elementContainer:"mui-textfield"
|
||||
elementContainer:"",
|
||||
tdElement:"mui-text-left",
|
||||
},
|
||||
styles:{
|
||||
element:"width:100%;"
|
||||
},
|
||||
values:{
|
||||
property:"value",
|
||||
|
@ -86,21 +95,66 @@ function Elementer() {
|
|||
value:"",
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
buttonTemplate:{
|
||||
tag:"BUTTON",
|
||||
label:"",
|
||||
classes:{
|
||||
element:"mui-btn"
|
||||
element:"",
|
||||
tdElement:"button-item",
|
||||
tr:"button-place",
|
||||
cancel:""
|
||||
},
|
||||
properties:{
|
||||
type:"button"
|
||||
},
|
||||
styles:{
|
||||
tdElement:"padding-top:10px;"
|
||||
},
|
||||
values:{
|
||||
property:"innerHTML",
|
||||
value:"Submit",
|
||||
value:"SUBMIT",
|
||||
resetable:false
|
||||
},
|
||||
custom:{
|
||||
cancelButton:true,
|
||||
cancelText:"BACK",
|
||||
outside:true,
|
||||
backListener:true
|
||||
}
|
||||
},
|
||||
|
||||
resetButtonTemplate:{
|
||||
tag:"BUTTON",
|
||||
label:"",
|
||||
classes:{
|
||||
element:"action ",
|
||||
tdElement:"button-item",
|
||||
tr:"button-place",
|
||||
cancel:""
|
||||
},
|
||||
properties:{
|
||||
type:"button",
|
||||
disabled:true
|
||||
},
|
||||
styles:{
|
||||
tdElement:"padding-top:10px;"
|
||||
},
|
||||
values:{
|
||||
property:"innerHTML",
|
||||
value:"APPLY",
|
||||
resetable:false
|
||||
},
|
||||
custom:{
|
||||
cancelButton:true,
|
||||
cancelText:"BACK",
|
||||
outside:true,
|
||||
backListener:true
|
||||
}
|
||||
},
|
||||
|
||||
textTemplate: {
|
||||
tag: "INPUT",
|
||||
label: "Input text",
|
||||
|
@ -109,10 +163,10 @@ function Elementer() {
|
|||
type: "text"
|
||||
},
|
||||
styles: {
|
||||
element: "max-width:100px;"
|
||||
element: "width:50px;"
|
||||
},
|
||||
classes:{
|
||||
elementContainer:"mui-textfield"
|
||||
elementContainer:""
|
||||
},
|
||||
values: {
|
||||
property:"value",
|
||||
|
@ -129,8 +183,11 @@ function Elementer() {
|
|||
min: 0,
|
||||
max: 100
|
||||
},
|
||||
styles: {
|
||||
element:"width:50px;"
|
||||
},
|
||||
classes:{
|
||||
elementContainer:"mui-textfield"
|
||||
elementContainer:""
|
||||
},
|
||||
values: {
|
||||
property:"value",
|
||||
|
@ -144,7 +201,7 @@ function Elementer() {
|
|||
type: "checkbox"
|
||||
},
|
||||
classes:{
|
||||
elementContainer:"mui-checkbox"
|
||||
elementContainer:""
|
||||
},
|
||||
values: {
|
||||
property:"checked",
|
||||
|
@ -159,7 +216,7 @@ function Elementer() {
|
|||
name: "radioGroup"
|
||||
},
|
||||
classes:{
|
||||
elementContainer:"mui-radio"
|
||||
elementContainer:""
|
||||
},
|
||||
values: {
|
||||
property:"checked",
|
||||
|
@ -177,6 +234,9 @@ function Elementer() {
|
|||
label: "subhead",
|
||||
classes: {
|
||||
label: "mui--text-accent"
|
||||
},
|
||||
styles: {
|
||||
tdLabel:"padding:3px;padding-top:13px;"
|
||||
}
|
||||
},
|
||||
contentTemplate: {
|
||||
|
@ -354,9 +414,9 @@ function Elementer() {
|
|||
|
||||
// do the root
|
||||
doLayout(root_, layout_.settings.root, layout_, detail_);
|
||||
|
||||
// do the others
|
||||
Object.keys(layout_.pages).forEach(function(k) {
|
||||
|
||||
if (k !== layout_.settings.root) {
|
||||
doLayout(container_, k, layout_, detail_);
|
||||
}
|
||||
|
@ -366,6 +426,7 @@ function Elementer() {
|
|||
var rt = layout_.settings.root;
|
||||
var onEnter = layout_.pages[rt].on ? layout_.pages[rt].on.enter : null;
|
||||
showThis(elements_.pages[rt], onEnter);
|
||||
|
||||
return self;
|
||||
|
||||
function doLayout(parent, branchName, layout, details) {
|
||||
|
@ -383,12 +444,8 @@ function Elementer() {
|
|||
|
||||
elements_.pages[branchName] = dv;
|
||||
|
||||
// prev icon - hide this and go back to whoever called
|
||||
if (ec.nav.prevIcon) {
|
||||
var dvp = ea(dv, "div", "", ec.backLabel, es.backLabel);
|
||||
var backIcon = ea(dvp, "span", ec.nav.prevIcon, ec.icon, es.icon);
|
||||
ea(dvp, "span", "Back to ???", ec.backLabel, es.backLabel).id = layout.settings.prefix + "-" + branchName + "-backcomment";
|
||||
dvp.addEventListener('click', function(e) {
|
||||
function backListener (elm) {
|
||||
elm.addEventListener('click', function(e) {
|
||||
|
||||
// do exit processing
|
||||
var onExit = layout_.pages[branchName].on ? layout_.pages[branchName].on.exit : null;
|
||||
|
@ -401,15 +458,24 @@ function Elementer() {
|
|||
var onEnter = layout_.pages[elb.branchName].on ? layout_.pages[elb.branchName].on.enter : null;
|
||||
showThis(elb.element, onEnter);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// prev icon - hide this and go back to whoever called
|
||||
if (ec.nav.prevIcon) {
|
||||
|
||||
var dvp = ea(dv, "div", "", ec.backLabel, es.backLabel);
|
||||
var backIcon = ea(dvp, "span", ec.nav.prevIcon, ec.icon, es.icon);
|
||||
ea(dvp, "span", "Back to ???", ec.backLabel, es.backLabel).id = layout.settings.prefix + "-" + branchName + "-backcomment";
|
||||
backListener (dvp);
|
||||
|
||||
}
|
||||
// use a table to lay out
|
||||
var tab = ea(dv, "table", "", ec.table, es.table);
|
||||
// the section title
|
||||
var tr = ea(tab, "tr", "", ec.tr, es.tr);
|
||||
|
||||
if (ec.nav.prevIcon) {
|
||||
if (ec.nav.showTitle) {
|
||||
|
||||
var td = ea(tr, "td", "", ec.td, es.td);
|
||||
td.colSpan = 3;
|
||||
ea(td, "span", DomUtils.fillLabel(lob.label), ec.title, es.title);
|
||||
|
@ -418,6 +484,7 @@ function Elementer() {
|
|||
lob.items.forEach(function(d) {
|
||||
if (layout.pages[d]) {
|
||||
// its a reference to another section
|
||||
|
||||
var ob = layout.pages[d];
|
||||
// bring in any override classes
|
||||
var fc = Utils.vanMerge([ec, ob.classes]);
|
||||
|
@ -437,8 +504,7 @@ function Elementer() {
|
|||
if (!ob.icon) {
|
||||
td.colSpan = 2;
|
||||
}
|
||||
// the next icon
|
||||
var td = ea(tr, "td", "", fc.tdIcon, fs.tdIcon);
|
||||
|
||||
|
||||
function clickPointer (elem , itemName, brName ) {
|
||||
elem.addEventListener ('click', function () {
|
||||
|
@ -450,7 +516,7 @@ function Elementer() {
|
|||
var backComment = DomUtils.elem(layout.settings.prefix + "-" + d + "-backcomment");
|
||||
if (backComment) {
|
||||
var lb = DomUtils.fillLabel(layout_.pages[brName].label);
|
||||
backComment.innerHTML = "Back to " + lb;
|
||||
backComment.innerHTML = "Back to " + lb ;
|
||||
}
|
||||
}
|
||||
var onEnter = layout_.pages[itemName].on ? layout_.pages[itemName].on.enter : null;
|
||||
|
@ -460,12 +526,17 @@ function Elementer() {
|
|||
|
||||
// add navigation to next level
|
||||
if (fc.nav.nextIcon) {
|
||||
var td = ea(tr, "td", "", fc.tdNextIcon, fs.tdNextIcon);
|
||||
td.colSpan = 2;
|
||||
ea(td, "i", fc.nav.nextIcon, fc.icon, fs.icon);
|
||||
clickPointer (tr,d, branchName);
|
||||
}
|
||||
|
||||
else {
|
||||
var td = ea(tr, "td", "", fc.tdIcon, fs.tdIcon);
|
||||
}
|
||||
} else {
|
||||
// it should be some real stuff
|
||||
|
||||
if (!details[d]) {
|
||||
throw d + ' layout reference not found in details';
|
||||
}
|
||||
|
@ -476,70 +547,109 @@ function Elementer() {
|
|||
|
||||
var fc = Utils.vanMerge([ec, ob.classes]);
|
||||
var fs = Utils.vanMerge([es, ob.styles]);
|
||||
var tr = ea(tab, "tr", "", fc.tr, fs.tr);
|
||||
|
||||
|
||||
// the label
|
||||
if (ob.custom && ob.custom.spanCols) {
|
||||
|
||||
// this element spans all columns
|
||||
var td = ea(tr, "td", "", fc.tdElement, fs.tdElement);
|
||||
td.colSpan = 3;
|
||||
// could be after the table
|
||||
if (ob.custom && ob.custom.outside) {
|
||||
var tr = ea(dv , "div", "", fc.tr, fs.tr);
|
||||
// the element container
|
||||
var td = ea(tr, "div", "", fc.tdElement, fs.tdElement);
|
||||
}
|
||||
else {
|
||||
|
||||
// the icon
|
||||
else {
|
||||
var tr = ea(tab, "tr", "", fc.tr, fs.tr);
|
||||
var used = 0;
|
||||
|
||||
// the icon is the first column
|
||||
if (ob.icon) {
|
||||
var td = ea(tr, "td", "", fc.tdIcon, fs.tdIcon);
|
||||
ea(td, "i", ob.icon, fc.icon);
|
||||
used++;
|
||||
}
|
||||
|
||||
// now the label
|
||||
var label = null;
|
||||
if (ob.label) {
|
||||
var td = ea(tr, "td", "", fc.tdLabel, fs.tdLabel);
|
||||
var label = ob.label ? ea(td, "label", DomUtils.fillLabel(ob.label), fc.label, fs.label) : null;
|
||||
if (!ob.icon) {
|
||||
td.colSpan = 2;
|
||||
}
|
||||
|
||||
// the element
|
||||
var td = ea(tr, "td", "", fc.tdElement, fs.tdElement);
|
||||
|
||||
var label = ea(td, "label", DomUtils.fillLabel(ob.label), fc.label, fs.label) ;
|
||||
used++;
|
||||
}
|
||||
|
||||
// the element.. if there's a tag we'll need a space for it
|
||||
if (ob.tag) {
|
||||
used++;
|
||||
var td = ea(tr, "td", "", fc.tdElement, fs.tdElement);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// now create an element
|
||||
var elemCancel = null,elem = null;
|
||||
if (ob.tag) {
|
||||
if (!(ob.custom && ob.custom.cancelOnly)) {
|
||||
var ediv = ea(td, "span", "", fc.elementContainer, fs.elementContainer);
|
||||
var elem = ea(ediv, ob.tag, "", fc.element, fs.element);
|
||||
elem.id = dv.id + "-" + d + "-elem";
|
||||
if (label) label['for'] = elem.id;
|
||||
|
||||
}
|
||||
// there may be a cancel button needed
|
||||
if (ob.custom && ob.custom.cancelButton) {
|
||||
var ediv = ea (tr, "span", "", fc.elementContainer , fs.elementContainer);
|
||||
var elemCancel = ea (ediv , ob.tag , "", fc.cancel , fs.cancel );
|
||||
elemCancel.id = dv.id + "-" + d + "-elem" + "-cancel";
|
||||
if (ob.custom && ob.custom.backListener) {
|
||||
backListener (elemCancel);
|
||||
}
|
||||
}
|
||||
// this should only apply to selects
|
||||
// but i'll leave it unchecked and just do it anyway
|
||||
if (ob.options){
|
||||
if (ob.options && elem){
|
||||
ob.options.forEach(function(g){
|
||||
ea (elem,"option",g,fc.option,fs.option).value = g;
|
||||
});
|
||||
}
|
||||
if (ob.properties) {
|
||||
|
||||
|
||||
if (ob.properties && elem) {
|
||||
Object.keys(ob.properties).forEach(function(e) {
|
||||
// now its possible that the propertty doesnt exist for every browser
|
||||
// for example input type="color" will throw exceptin
|
||||
// when running on excel 2016 sidebar so just pass on error with a console.log
|
||||
try {
|
||||
elem[e] = ob.properties[e];
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err + ':continuing and ignoring');
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (ob.values && ob.values.property) {
|
||||
if (elemCancel){
|
||||
elemCancel.innerHTML = ob.custom && ob.custom.cancelText ? ob.custom.cancelText : "Cancel";
|
||||
}
|
||||
|
||||
if (elem && ob.values && ob.values.property) {
|
||||
elem[ob.values.property] = ob.values.value;
|
||||
elements_.values[d] = ob.values;
|
||||
if(ob.values.resetable) {
|
||||
initial_[d] = ob.values.value;
|
||||
}
|
||||
}
|
||||
|
||||
// now apply any onchange/ click etc.
|
||||
if (ob.on) {
|
||||
if (ob.on && elem) {
|
||||
Object.keys (ob.on).forEach(function (o) {
|
||||
elem.addEventListener (o , function (e) {
|
||||
ob.on[o] (self , branchName , ob , e);
|
||||
});
|
||||
});
|
||||
}
|
||||
elements_.controls[d] = elem;
|
||||
|
||||
if (!(ob.custom && ob.custom.outside)) {
|
||||
// swallow up the rest
|
||||
if (td)td.colSpan = 5 - used ;
|
||||
}
|
||||
elements_.controls[d] = elem || elemCancel;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue