;(function(){
_App.TemplateElement = function()
{
this.initialize();
};
_App.TemplateElement.prototype =
{
initialize : function()
{
// Nothing to do.
},
/**
* Create a new Text element for a template.
* Example: var name = new App.TemplateElement.Text('name');
* @param id
*/
Text : function ( id )
{
this.id = id;
this.hydrate = function( template, value )
{
value = (null == value)
? ' '
: value;
return template.replace('[' + this.id + ']', value);
};
this.hydrateLive = function( tid, value )
{
$('#' + tid + '_' + this.id).html(value);
};
this.publish = function( tid )
{
// element bindings and such
};
this.harvest = function( tid )
{
return $('#' + tid + '_' + this.id).html();
};
},
LabeledText : function ( id )
{
this.id = id;
this.hydrate = function( template, meta )
{
var value = (null == meta || null == meta.value)
? ' '
: meta.value;
var title = (null == meta || null == meta.title)
? ' '
: meta.title;
var labelStyle = (null == meta || null == meta.labelStyle)
? 'valuation-line'
: meta.labelStyle;
var style = (null == meta || null == meta.style)
? 'information-lines'
: meta.style;
var html = '';
html += '
';
html += '
' + value + '
';
html += '
';
return template.replace('[' + this.id + ']', html);
};
this.hydrateLive = function( tid, meta )
{
var value = (undefined == meta || null == meta.value)
? ' '
: meta.value;
var title = (undefined == meta || null == meta.title)
? ' '
: meta.title;
var labelStyle = (null == meta || null == meta.labelStyle)
? 'valuation-line'
: meta.labelStyle;
var style = (null == meta || null == meta.style)
? 'information-lines'
: meta.style;
var html = '';
html += '
';
html += '
' + value + '
';
html += '
';
$('#' + tid + '_' + this.id).html(html);
};
this.publish = function( tid )
{
// element bindings and such
};
this.harvest = function( tid )
{
return $('#' + this.id).html();
};
},
ComponentCollection : function ( id )
{
this.id = id;
this.meta = {};
this.hydrate = function( template, value )
{
this.meta = (null == value)
? '[...]'
: value;
var html = '';
for (var item in this.meta)
{
html += this.meta[item]['html'];
}
return template.replace('[' + this.id + ']', html);
};
this.hydrateLive = function( tid, value )
{
this.meta = (null == value)
? '[...]'
: value;
var html = '';
for (var item in this.meta)
{
if (this.meta[item]['html'])
{
html += this.meta[item]['html'];
}
}
$('#' + tid + '_' + this.id).html(html);
for (var item in this.meta)
{
if (this.meta[item]['js'])
{
this.meta[item]['js']();
}
}
};
this.publish = function( tid )
{
for (var item in this.meta)
{
if (this.meta[item]['js'])
{
this.meta[item]['js']();
}
}
};
this.harvest = function( tid )
{
return null;
};
},
ConstructorComponentCollection : function ( id )
{
this.id = id;
this.meta = {items:{}};
this.itemMeta = null;
this.hydrate = function( template, value )
{
if (null == value)
{
return template;
}
this.meta = value;
var html = '';
for (var item in this.meta.items)
{
html += App.ElementLibrary[this.meta.constructor].html(this.meta.items[item]);
}
return template.replace('[' + this.id + ']', html);
};
this.hydrateLive = function( tid, value )
{
if (null == value)
{
return;
}
this.meta = value;
var html = '';
if (this.meta.items)
{
for (var i in this.meta.items)
{
html += App.ElementLibrary[this.meta.constructor].html(this.meta.items[i]);
}
}
$('#' + tid + '_' + this.id).html(html);
if (undefined == App.ElementLibrary[this.meta.constructor])
{
return;
}
if (App.ElementLibrary[this.meta.constructor].bind)
{
for (var item in this.meta.items)
{
App.ElementLibrary[this.meta.constructor].bind(this.meta.items[item]);
}
}
};
this.publish = function( tid )
{
if (!this.meta.constructor)
{
return;
}
if (undefined == App.ElementLibrary[this.meta.constructor])
{
//console.log('NO SUCH CONSTRUCTOR: ' + this.meta.constructor);
return;
}
if (App.ElementLibrary[this.meta.constructor].bind)
{
for (var item in this.meta.items)
{
App.ElementLibrary[this.meta.constructor].bind(this.meta.items[item]);
}
}
};
this.harvest = function( tid )
{
return null;
};
},
FieldComponent : function ( id )
{
this.id = id;
this.meta = {};
this.hydrate = function( template, value )
{
this.meta = value;
value = '';
if (this.meta && this.meta.value)
{
value = this.meta.value;
}
var html = App.ElementLibrary.Field.html(this.meta, value);
return template.replace('[' + this.id + ']', html);
};
this.hydrateLive = function( tid, value )
{
this.meta = value;
value = '';
if (this.meta && this.meta.value)
{
value = this.meta.value;
}
var html = App.ElementLibrary.Field.html(this.meta, value);
$('#' + tid + '_' + this.id).html(html);
if (this.meta)
{
App.ElementLibrary.Field.setValue( tid, this.meta, value);
App.ElementLibrary.Field.bind( tid, this.meta );
}
};
this.publish = function( tid )
{
if (this.meta)
{
value = '';
if (this.meta && this.meta.value)
{
value = this.meta.value;
}
App.ElementLibrary.Field.setValue( tid, this.meta, value);
App.ElementLibrary.Field.bind( tid, this.meta );
}
};
this.harvest = function( tid )
{
return App.ElementLibrary.Field.harvest( tid, this.meta );
};
},
GroupComponent : function ( id )
{
this.id = id;
this.meta = {};
this.hydrate = function( template, value )
{
this.meta = value;
value = '';
if (this.meta && this.meta.value)
{
value = this.meta.value;
}
var html = App.ElementLibrary.Field.html(this.meta, value);
return template.replace('[' + this.id + ']', html);
};
this.hydrateLive = function( tid, value )
{
this.meta = value;
value = '';
if (this.meta && this.meta.value)
{
value = this.meta.value;
}
var html = App.ElementLibrary.Field.html(this.meta, value);
$('#' + tid + '_' + this.id).html(html);
if (this.meta)
{
App.ElementLibrary.Field.setValue( tid, this.meta, value);
App.ElementLibrary.Field.bind( tid, this.meta );
}
};
this.publish = function( tid )
{
if (this.meta)
{
value = '';
if (this.meta && this.meta.value)
{
value = this.meta.value;
}
App.ElementLibrary.Field.setValue( tid, this.meta, value);
App.ElementLibrary.Field.bind( tid, this.meta );
}
};
this.harvest = function( tid )
{
return App.ElementLibrary.Field.harvest( tid, this.meta );
};
}
};
})();