'.format(this.style, component);
};
InputTextField.prototype.render = function() {
this.html = this.question + this.html;
if (this.newline)
this.html = "
" + this.html;
$("#{0}".format(this.parent_id)).append(this.html);
}
function InputDate(parent_id, item = {}) {
item.type = "date";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_DATE++);
InputTextField.call(this, parent_id, item);
this.html = this._generate();
this.render();
}
InputDate.prototype = inherit(InputTextField.prototype);
function InputDatetime(parent_id, item = {}) {
item.type = "datetime";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_DATETIME++);
InputTextField.call(this, parent_id, item);
this.html = this._generate();
this.render();
}
InputDatetime.prototype = inherit(InputTextField.prototype);
function InputDatetimeLocal(parent_id, item = {}) {
item.type = "datetime-local";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_DATETIME_LOCAL++);
InputTextField.call(this, parent_id, item);
this.html = this._generate();
this.render();
}
InputDatetimeLocal.prototype = inherit(InputTextField.prototype);
function InputEmail(parent_id, item = {}) {
item.type = "email";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_EMAIL++);
InputTextField.call(this, parent_id, item);
this.label = item.label || "Please enter you email...";
this.html = this._generate();
this.render();
}
InputEmail.prototype = inherit(InputTextField.prototype);
function InputMonth(parent_id, item = {}) {
item.type = "month";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_MONTH++);
InputTextField.call(this, parent_id, item);
this.html = this._generate();
this.render();
}
InputMonth.prototype = inherit(InputTextField.prototype);
function InputNumber(parent_id, item = {}) {
item.type = "number";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_NUMBER++);
InputTextField.call(this, parent_id, item);
this.label = item.label || "Please enter a number...";
this.html = this._generate();
this.render();
}
InputNumber.prototype = inherit(InputTextField.prototype);
function InputPassword(parent_id, item = {}) {
item.type = "password";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_PASSWORD++);
item.needQuestion = item.needQuestion || false;
item.floating = (item.floating == false) ? false : true;
InputTextField.call(this, parent_id, item);
this.label = item.label || "Please enter your password...";
this.html = this._generate();
this.render();
}
InputPassword.prototype = inherit(InputTextField.prototype);
function InputSearch(parent_id, item = {}) {
item.type = "search";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_SEARCH++);
item.expandable = (item.expandable == false) ? false : true;
item.floating = (item.expandable) ? false : true;
item.icon = item.icon || "search";
item.needQuestion = false;
InputTextField.call(this, parent_id, item);
this.html = this._generate();
this.render();
}
InputSearch.prototype = inherit(InputTextField.prototype);
function InputTel(parent_id, item = {}) {
item.type = "tel";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_TEL++);
InputTextField.call(this, parent_id, item);
this.label = item.label || "Please enter your telephone number...";
this.html = this._generate();
this.render();
}
InputTel.prototype = inherit(InputTextField.prototype);
function InputText(parent_id, item = {}) {
item.type = "text";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_TEXT++);
InputTextField.call(this, parent_id, item);
this.label = item.label || "Please enter some texts...";
this.html = this._generate();
this.render();
}
InputText.prototype = inherit(InputTextField.prototype);
function InputTime(parent_id, item = {}) {
item.type = "time";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_TIME++);
InputTextField.call(this, parent_id, item);
this.name = item.name || this.id;
this.html = this._generate();
this.render();
}
InputTime.prototype = inherit(InputTextField.prototype);
function InputUrl(parent_id, item = {}) {
item.type = "url";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_URL++);
InputTextField.call(this, parent_id, item);
this.label = item.label || "Please enter the url...";
this.html = this._generate();
this.render();
}
InputUrl.prototype = inherit(InputTextField.prototype);
function InputWeek(parent_id, item = {}) {
item.type = "week";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_WEEK++);
InputTextField.call(this, parent_id, item);
this.html = this._generate();
this.render();
}
InputWeek.prototype = inherit(InputTextField.prototype);
function Textarea(parent_id, item = {}) {
item.type = "textarea";
item.id = item.id || "{0}_{1}".format(item.type, __TEXTAREA++);
InputTextField.call(this, parent_id, item);
this.name = item.name || this.id;
this.placeholder = item.placeholder || "Text lines";
this.cols = item.cols || "30";
this.rows = item.rows || "10";
this.wrap = (item.wrap) ? 'wrap="' + item.wrap + '" ' : "";
this.html = this._generate();
this.render();
}
Textarea.prototype = inherit(Tag.prototype);
Textarea.prototype._generate = function() {
var component = '
'.format(
this.id, this.rows, this.cols, this.parent_id, this.maxlength, this.readonly, this.required, this.disabled, this.autofocus, this.wrap, this.name) +
'
'.format(this.id, this.placeholder);
return this.question + '
{1}
'.format(this.style, component);
}
function Toggle(parent_id, item = {}) {
item.newline = item.newline || false;
Tag.call(this, parent_id, item);
// settings for mdl
// this.type --> type as a
tag
// this.type_class --> template of different type class in mdl i.e. checkbox switch...
// this.content_class --> template of different content class in mdl
this.ripple = (item.ripple == false) ? false : true;
this.toggle_type = item.toggle_type;
this.value = item.value || this.label;
this.checked = (item.checked) ? 'checked="checked"' : "";
}
Toggle.prototype = inherit(Tag.prototype);
Toggle.prototype._generate = function() {
var addon = "";
addon += ((this.ripple) ? " mdl-js-ripple-effect" : "");
var html = '
'
return html;
};
function Checkbox(parent_id, item = {}) {
item.type = "checkbox";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_CHECKBOX++);
item.toggle_type = "checkbox";
item.label = item.label || "Checkbox #{0}".format(__INPUT_CHECKBOX - 1);
Toggle.call(this, parent_id, item);
this.type_class = 'mdl-checkbox__input';
var isImage = this.label.startsWith("
")
if (!isImage)
this.content_class = '
{0}'.format(this.label);
else
this.content_class = '
{0}'.format(this.value);
this.html = this._generate();
if (isImage)
this.html += this.label;
}
Checkbox.prototype = inherit(Toggle.prototype);
function Switch(parent_id, item = {}) {
item.type = "checkbox";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_CHECKBOX++);
item.toggle_type = "switch";
item.label = item.label || "Switch #{0}".format(__INPUT_CHECKBOX - 1);
Toggle.call(this, parent_id, item);
this.type_class = 'mdl-switch__input';
var isImage = this.label.startsWith("
")
if (!isImage)
this.content_class = '
{0}'.format(this.label);
else
this.content_class = '
{0}'.format(this.value);
this.html = this._generate();
if (isImage)
this.html += this.label;
}
Switch.prototype = inherit(Toggle.prototype);
function Radio(parent_id, item = {}) {
item.type = "radio";
item.id = item.id || "{0}_{1}".format(item.type, __INPUT_RADIO++);
item.toggle_type = "radio";
item.label = item.label || "Radio #{0}".format(__INPUT_RADIO - 1);
Toggle.call(this, parent_id, item);
this.type_class = 'mdl-radio__button';
var isImage = this.label.startsWith("
")
if (!isImage)
this.content_class = '
{0}'.format(this.label);
else
this.content_class = '
{0}{1}'.format(this.value, this.label);
this.html = this._generate();
}
Radio.prototype = inherit(Toggle.prototype);
function ToggleGroup(parent_id, item) {
item.id = item.id || "Toggle group_{0}".format(__TOGGLE_GROUP++);
item.type = item.type || "checkbox";
item.name = item.name || item.id;
item.needQuestion = (item.needQuestion == false) ? false : true;
item.images = item.images || [];
item.labels = item.labels || [];
item.values = item.values || [];
Tag.call(this, parent_id, item);
for (var i in item.labels) {
if (item.values.length < item.labels.length)
item.values.push(item.labels[i]);
}
if (item.images.length > 0) {
for (var i in item.images) {
item.labels.push('
'.format(item.images[i]));
if (item.values.length < item.labels.length)
item.values.push(item.images[i]);
}
}
this.values = item.values;
this.labels = item.labels;
this.html = "";
var factory = this._selector();
for (var i in this.labels) {
item.label = this.labels[i];
item.value = this.values[i];
item.id = ""; // initialize item.id
this.html += factory(this.parent_id, item).html + "\n";
}
this.html = this.question + "
" + this.html + "
"
this.render();
}
ToggleGroup.prototype = inherit(Tag.prototype);
ToggleGroup.prototype._selector = function() {
switch (this.type) {
case "checkbox":
return function(parent_id, item) {
return new Checkbox(parent_id, item);
}
case "switch":
return function(parent_id, item) {
return new Switch(parent_id, item);
}
case "radio":
return function(parent_id, item) {
return new Radio(parent_id, item);
}
}
}