/*
This file is part of LONCAPA-Daxe.
LONCAPA-Daxe is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LONCAPA-Daxe is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Daxe. If not, see <http://www.gnu.org/licenses/>.
*/
part of loncapa_daxe;
/**
* Display for the textfield element, for simple UI (some attributes are displayed like attributes of the parent).
* Jaxe display type: 'textfield'.
*/
class Textfield extends LCDBlock {
static List<String> simpleUIAttributes = ['spellcheck', 'rows', 'cols'];
Textfield.fromRef(x.Element elementRef) : super.fromRef(elementRef);
Textfield.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent) {
if (simpleParent())
simpleUI = true;
}
@override
bool simpleUIPossible() {
if (attributes.length != 0) {
// accept any spellcheck, rows, columns, but no addchars
for (DaxeAttr att in attributes) {
if (!simpleUIAttributes.contains(att.name)) {
throw new SimpleUIException('textfield: ' + LCDStrings.get('attribute_problem') + att.name);
}
}
}
if (firstChild != null)
return false;
return true;
}
bool simpleParent() {
return (parent is LCDBlock && (parent as LCDBlock).simpleUI) &&
(parent is EssayResponse);
}
@override
h.Element html() {
simpleUI = simpleParent();
if (!simpleUI)
return super.html();
// the whole textfield node is reduced to its attributes
h.TableElement table = new h.TableElement();
table.classes.add('expand');
table.id = id;
for (x.Element refAttr in attRefs) {
String name = doc.cfg.attributeName(refAttr);
if (simpleUIAttributes.contains(name)) {
h.TableRowElement tr = attributeHTML(refAttr);
table.append(tr);
}
}
return(table);
}
@override
void updateAttributes() {
if (!simpleUI) {
super.updateAttributes();
return;
}
parent.updateHTML();
}
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>