this.config = config;
this.parsechain = [ config ];
+ this.readonly = false;
this.data = uci;
},
+ /**
+ * Toggle readonly state of the form.
+ *
+ * If set to `true`, the Map instance is marked readonly and any form
+ * option elements added to it will inherit the readonly state.
+ *
+ * @name LuCI.form.Map.prototype#readonly
+ * @type boolean
+ */
+
/**
* Find all DOM nodes within this Map which match the given search
* parameters. This function is essentially a convenience wrapper around
* @default null
*/
+ /**
+ * Make option element readonly.
+ *
+ * This property defaults to the readonly state of the parent form element.
+ * When set to `true`, the underlying widget is rendered in disabled state,
+ * means its contents cannot be changed and the widget cannot be interacted
+ * with.
+ *
+ * @name LuCI.form.AbstractValue.prototype#readonly
+ * @type boolean
+ * @default false
+ */
+
/**
* Override the cell width of a table or grid section child option.
*
createEl.appendChild(E('button', {
'class': 'cbi-button cbi-button-add',
'title': btn_title || _('Add'),
- 'click': ui.createHandlerFn(this, 'handleAdd')
+ 'click': ui.createHandlerFn(this, 'handleAdd'),
+ 'disabled': this.map.readonly || null
}, [ btn_title || _('Add') ]));
}
else {
var nameEl = E('input', {
'type': 'text',
- 'class': 'cbi-section-create-name'
+ 'class': 'cbi-section-create-name',
+ 'disabled': this.map.readonly || null
});
dom.append(createEl, [
return;
return this.handleAdd(ev, nameEl.value);
- })
+ }),
+ 'disabled': this.map.readonly || null
})
]);
'class': 'cbi-button',
'name': 'cbi.rts.%s.%s'.format(config_name, cfgsections[i]),
'data-section-id': cfgsections[i],
- 'click': ui.createHandlerFn(this, 'handleRemove', cfgsections[i])
+ 'click': ui.createHandlerFn(this, 'handleRemove', cfgsections[i]),
+ 'disabled': this.map.readonly || null
}, [ _('Delete') ])));
}
E('div', {
'title': _('Drag to reorder'),
'class': 'btn cbi-button drag-handle center',
- 'style': 'cursor:move'
+ 'style': 'cursor:move',
+ 'disabled': this.map.readonly || null
}, '☰')
]);
}
E('button', {
'title': btn_title || _('Delete'),
'class': 'cbi-button cbi-button-remove',
- 'click': ui.createHandlerFn(this, 'handleRemove', section_id)
+ 'click': ui.createHandlerFn(this, 'handleRemove', section_id),
+ 'disabled': this.map.readonly || null
}, [ btn_title || _('Delete') ])
);
}
s = m.section(CBINamedSection, section_id, this.sectiontype);
m.parent = parent;
+ m.readonly = parent.readonly;
s.tabs = this.tabs;
s.tab_names = this.tab_names;
}, [ _('Dismiss') ]), ' ',
E('button', {
'class': 'cbi-button cbi-button-positive important',
- 'click': ui.createHandlerFn(this, 'handleModalSave', m)
+ 'click': ui.createHandlerFn(this, 'handleModalSave', m),
+ 'disabled': m.readonly || null
}, [ _('Save') ])
])
], 'cbi-modal');
E('div', { 'class': 'cbi-section-remove right' },
E('button', {
'class': 'cbi-button',
- 'click': ui.createHandlerFn(this, 'handleRemove')
+ 'click': ui.createHandlerFn(this, 'handleRemove'),
+ 'disabled': this.map.readonly || null
}, [ _('Delete') ])));
}
sectionEl.appendChild(
E('button', {
'class': 'cbi-button cbi-button-add',
- 'click': ui.createHandlerFn(this, 'handleAdd')
+ 'click': ui.createHandlerFn(this, 'handleAdd'),
+ 'disabled': this.map.readonly || null
}, [ _('Add') ]));
}
optional: this.optional || this.rmempty,
datatype: this.datatype,
select_placeholder: this.placeholder || placeholder,
- validate: L.bind(this.validate, this, section_id)
+ validate: L.bind(this.validate, this, section_id),
+ disabled: (this.readonly != null) ? this.readonly : this.map.readonly
});
}
else {
optional: this.optional || this.rmempty,
datatype: this.datatype,
placeholder: this.placeholder,
- validate: L.bind(this.validate, this, section_id)
+ validate: L.bind(this.validate, this, section_id),
+ disabled: (this.readonly != null) ? this.readonly : this.map.readonly
});
}
optional: this.optional || this.rmempty,
datatype: this.datatype,
placeholder: this.placeholder,
- validate: L.bind(this.validate, this, section_id)
+ validate: L.bind(this.validate, this, section_id),
+ disabled: (this.readonly != null) ? this.readonly : this.map.readonly
});
return widget.render();
sort: this.keylist,
optional: this.optional,
placeholder: this.placeholder,
- validate: L.bind(this.validate, this, section_id)
+ validate: L.bind(this.validate, this, section_id),
+ disabled: (this.readonly != null) ? this.readonly : this.map.readonly
});
return widget.render();
id: this.cbid(section_id),
value_enabled: this.enabled,
value_disabled: this.disabled,
- validate: L.bind(this.validate, this, section_id)
+ validate: L.bind(this.validate, this, section_id),
+ disabled: (this.readonly != null) ? this.readonly : this.map.readonly
});
return widget.render();
select_placeholder: this.placeholder,
display_items: this.display_size || this.size || 3,
dropdown_items: this.dropdown_size || this.size || -1,
- validate: L.bind(this.validate, this, section_id)
+ validate: L.bind(this.validate, this, section_id),
+ disabled: (this.readonly != null) ? this.readonly : this.map.readonly
});
return widget.render();
cols: this.cols,
rows: this.rows,
wrap: this.wrap,
- validate: L.bind(this.validate, this, section_id)
+ validate: L.bind(this.validate, this, section_id),
+ disabled: (this.readonly != null) ? this.readonly : this.map.readonly
});
return widget.render();
hiddenEl = new ui.Hiddenfield(value, { id: this.cbid(section_id) }),
outputEl = E('div');
- if (this.href)
+ if (this.href && !((this.readonly != null) ? this.readonly : this.map.readonly))
outputEl.appendChild(E('a', { 'href': this.href }));
dom.append(outputEl.lastChild || outputEl,
ev.currentTarget.parentNode.nextElementSibling.value = value;
return this.map.save();
- }, section_id)
+ }, section_id),
+ 'disabled': ((this.readonly != null) ? this.readonly : this.map.readonly) || null
}, [ btn_title ])
]);
else
show_hidden: this.show_hidden,
enable_upload: this.enable_upload,
enable_remove: this.enable_remove,
- root_directory: this.root_directory
+ root_directory: this.root_directory,
+ disabled: (this.readonly != null) ? this.readonly : this.map.readonly
});
return browserEl.render();