UNPKG

foam-framework

Version:
78 lines (64 loc) 2 kB
/** * @license * Copyright 2014 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ CLASS({ package: 'foam.ui', name: 'SummaryView', extends: 'foam.ui.View', documentation: function() {/* A display-only summary view. */}, properties: [ { name: 'model', type: 'Model' }, { name: 'data' } ], methods: { toHTML: function() { return (this.model.getPrototype().toSummaryHTML || this.defaultToHTML).call(this); }, defaultToHTML: function() { this.children = []; var model = this.model; var obj = this.data; var out = []; out.push('<div id="' + this.id + '" class="summaryView">'); out.push('<table>'); // TODO: Either make behave like DetailView or else // make a mode of DetailView. for ( var i = 0 ; i < model.properties.length ; i++ ) { var prop = model.properties[i]; if ( prop.hidden ) continue; var value = obj[prop.name]; if ( ! value ) continue; out.push('<tr>'); out.push('<td class="label">' + prop.label + '</td>'); out.push('<td class="value">'); if ( prop.summaryFormatter ) { out.push(prop.summaryFormatter(this.strToHTML(value))); } else { out.push(this.strToHTML(value)); } out.push('</td></tr>'); } out.push('</table>'); out.push('</div>'); return out.join(''); } } });