// Concrete Model Editor // // Copyright (c) 2010 Martin Thiede // // Concrete is freely distributable under the terms of an MIT-style license. Concrete.TemplateProvider = Class.create({ // +templateRoot+ is the DOM element containing the templates // // Options: // identifierAttribute: name of the feature that holds the identifier, default: none // featureSortFunc: function providing values for features used to sort them, default: none // alwaysHideFeatures: names of the features which should always be hidden, default: none // initialize: function(templateRoot, options) { this.templateRoot = templateRoot; this._templateByClass = {}; this.options = options || {}; this.options.alwaysHideFeatures = this.options.alwaysHideFeatures || []; }, emptyValue: function(feature) { var value = new Element("span"); value.className = "ct_value ct_empty"; value.innerHTML = "<"+feature.mmFeature.name+">"; return value; }, emptyElement: function(parentNode, feature) { if (feature) { var placeholderText = "<"+feature.mmFeature.name+">" } else { var placeholderText = "<root>" } if (parentNode.tagName.toUpperCase() == "TBODY") { cols = parentNode.up("table").select("tr").max(function(r) { return r.childElements().select(function(c) {return c.tagName.toUpperCase() == "TD";}).size(); }); var element = new Element("tr"); element.className = "ct_element ct_empty"; element.features = []; // adding child td node via innerHTML doesn't work in Firefox as long as the parent tr node is not child of a table var td = new Element("td"); td.writeAttribute("colspan", cols); td.innerHTML = placeholderText; element.appendChild(td); } else { var element = new Element("span"); element.className = "ct_element ct_empty"; element.innerHTML = placeholderText; element.features = []; } return element; }, templateByClass: function(clazz) { if (this._templateByClass[clazz.name]) return this._templateByClass[clazz.name]; var tmpl = this.templateRoot.down(".ctc_"+clazz.name); if (tmpl) { this._completeDomBasedTemplate(tmpl, clazz); } else { tmpl = this._createGenericTemplate(clazz); } return this._templateByClass[clazz.name] = tmpl; }, _createGenericTemplate: function(clazz) { this.templateRoot.insert({bottom: "