2 _App.TemplateElement = function()
6 _App.TemplateElement.prototype =
9 initialize : function()
15 * Create a new Text element for a template.
16 * Example: var name = new App.TemplateElement.Text('name');
19 Text : function ( id )
23 this.hydrate = function( template, value )
25 value = (null == value)
28 return template.replace('[' + this.id + ']', value);
31 this.hydrateLive = function( tid, value )
33 $('#' + tid + '_' + this.id).html(value);
36 this.publish = function( tid )
38 // element bindings and such
41 this.harvest = function( tid )
43 return $('#' + tid + '_' + this.id).html();
47 LabeledText : function ( id )
51 this.hydrate = function( template, meta )
53 var value = (null == meta || null == meta.value)
56 var title = (null == meta || null == meta.title)
59 var labelStyle = (null == meta || null == meta.labelStyle)
62 var style = (null == meta || null == meta.style)
65 var html = '<label class="control-label ' + labelStyle + '">' + title + ':</label>';
66 html += '<div class="controls">';
67 html += '<p class="' + style + '" id="' + this.id + '">' + value + '</p>';
69 return template.replace('[' + this.id + ']', html);
72 this.hydrateLive = function( tid, meta )
74 var value = (undefined == meta || null == meta.value)
77 var title = (undefined == meta || null == meta.title)
80 var labelStyle = (null == meta || null == meta.labelStyle)
83 var style = (null == meta || null == meta.style)
86 var html = '<label class="control-label ' + labelStyle + '">' + title + ':</label>';
87 html += '<div class="controls">';
88 html += '<p class="' + style + '" id="' + this.id + '">' + value + '</p>';
90 $('#' + tid + '_' + this.id).html(html);
93 this.publish = function( tid )
95 // element bindings and such
98 this.harvest = function( tid )
100 return $('#' + this.id).html();
104 ComponentCollection : function ( id )
109 this.hydrate = function( template, value )
111 this.meta = (null == value)
115 for (var item in this.meta)
117 html += this.meta[item]['html'];
119 return template.replace('[' + this.id + ']', html);
122 this.hydrateLive = function( tid, value )
124 this.meta = (null == value)
128 for (var item in this.meta)
130 if (this.meta[item]['html'])
132 html += this.meta[item]['html'];
135 $('#' + tid + '_' + this.id).html(html);
136 for (var item in this.meta)
138 if (this.meta[item]['js'])
140 this.meta[item]['js']();
145 this.publish = function( tid )
147 for (var item in this.meta)
149 if (this.meta[item]['js'])
151 this.meta[item]['js']();
156 this.harvest = function( tid )
162 ConstructorComponentCollection : function ( id )
165 this.meta = {items:{}};
166 this.itemMeta = null;
168 this.hydrate = function( template, value )
176 for (var item in this.meta.items)
178 html += App.ElementLibrary[this.meta.constructor].html(this.meta.items[item]);
180 return template.replace('[' + this.id + ']', html);
183 this.hydrateLive = function( tid, value )
193 for (var i in this.meta.items)
195 html += App.ElementLibrary[this.meta.constructor].html(this.meta.items[i]);
198 $('#' + tid + '_' + this.id).html(html);
199 if (undefined == App.ElementLibrary[this.meta.constructor])
203 if (App.ElementLibrary[this.meta.constructor].bind)
205 for (var item in this.meta.items)
207 App.ElementLibrary[this.meta.constructor].bind(this.meta.items[item]);
212 this.publish = function( tid )
214 if (!this.meta.constructor)
218 if (undefined == App.ElementLibrary[this.meta.constructor])
220 //console.log('NO SUCH CONSTRUCTOR: ' + this.meta.constructor);
223 if (App.ElementLibrary[this.meta.constructor].bind)
225 for (var item in this.meta.items)
227 App.ElementLibrary[this.meta.constructor].bind(this.meta.items[item]);
232 this.harvest = function( tid )
238 FieldComponent : function ( id )
243 this.hydrate = function( template, value )
247 if (this.meta && this.meta.value)
249 value = this.meta.value;
251 var html = App.ElementLibrary.Field.html(this.meta, value);
252 return template.replace('[' + this.id + ']', html);
255 this.hydrateLive = function( tid, value )
259 if (this.meta && this.meta.value)
261 value = this.meta.value;
263 var html = App.ElementLibrary.Field.html(this.meta, value);
264 $('#' + tid + '_' + this.id).html(html);
267 App.ElementLibrary.Field.setValue( tid, this.meta, value);
268 App.ElementLibrary.Field.bind( tid, this.meta );
272 this.publish = function( tid )
277 if (this.meta && this.meta.value)
279 value = this.meta.value;
281 App.ElementLibrary.Field.setValue( tid, this.meta, value);
282 App.ElementLibrary.Field.bind( tid, this.meta );
286 this.harvest = function( tid )
288 return App.ElementLibrary.Field.harvest( tid, this.meta );
292 GroupComponent : function ( id )
297 this.hydrate = function( template, value )
301 if (this.meta && this.meta.value)
303 value = this.meta.value;
305 var html = App.ElementLibrary.Field.html(this.meta, value);
306 return template.replace('[' + this.id + ']', html);
309 this.hydrateLive = function( tid, value )
313 if (this.meta && this.meta.value)
315 value = this.meta.value;
317 var html = App.ElementLibrary.Field.html(this.meta, value);
318 $('#' + tid + '_' + this.id).html(html);
321 App.ElementLibrary.Field.setValue( tid, this.meta, value);
322 App.ElementLibrary.Field.bind( tid, this.meta );
326 this.publish = function( tid )
331 if (this.meta && this.meta.value)
333 value = this.meta.value;
335 App.ElementLibrary.Field.setValue( tid, this.meta, value);
336 App.ElementLibrary.Field.bind( tid, this.meta );
340 this.harvest = function( tid )
342 return App.ElementLibrary.Field.harvest( tid, this.meta );