[% default_keys = ['id', 'class', 'title']; # Defaults for all attributes # Defaults for input attributes default_input_keys = default_keys.merge( ['type', 'name', 'disabled', 'size', 'value', 'data-dojo-type','data-dojo-props', 'data-dojo-attach-point', 'required', 'tabindex']); input_keys.hidden = default_keys.merge(['type', 'name', 'value']); input_keys.file = default_input_keys.merge(['accept']); input_keys.image = default_input_keys.merge(['alt', 'src']); input_keys.checkbox = default_input_keys.merge(['checked']); input_keys.toggle = default_input_keys.merge(['checked']); input_keys.radio = default_input_keys.merge(['checked']); input_keys.password = default_input_keys; input_keys.date = default_input_keys; input_keys.text = default_input_keys.merge(['maxlength', 'readonly']); textarea_keys = default_input_keys.merge(['cols', 'rows', 'readonly', 'style', 'wrap' ]); select_keys = default_input_keys.merge(['multiple', 'readonly']); option_keys = default_keys.merge(['tabindex', 'disabled', 'value', 'selected']); button_keys = default_input_keys.merge(['data-lsmb-doing', 'data-lsmb-done']); toggle_keys = default_input_keys.merge(['showLabel', 'label']); for_keys = default_keys.merge(['for']); # ELEMENT DEFAULTS element_defaults.checkbox = { value = '1', 'data-dojo-type' = 'dijit/form/CheckBox' }; #radio element_defaults.radio = { 'data-dojo-type' = 'dijit/form/RadioButton' }; #file element_defaults.file = { size = '60' }; #password element_defaults.password = { size = '60', "data-dojo-type" = "dijit/form/ValidationTextBox" }; # text element_defaults.text = { size = '60', maxlength = '255', "data-dojo-type" = "dijit/form/ValidationTextBox" }; # date USER.dojo_dateformat = USER.dateformat.lower().replace('mm','MM'); element_defaults.date = { "data-dojo-type" = 'lsmb/DateTextBox', 'data-dojo-props' = "constraints: {datePattern: '$USER.dojo_dateformat'},placeholder: '$USER.dateformat'" size = '8', }; # textarea element_defaults.textarea = { rows = '1', cols = '60', "data-dojo-type" = "lsmb/ResizingTextarea" }; #button element_defaults.button = { type = 'submit', "data-dojo-type" = "dijit/form/Button" }; #select element_defaults.select = { "data-dojo-type" = "dijit/form/Select" }; #multiselect element_defaults.multiselect = { "data-dojo-type" = "dijit/form/MultiSelect" "multiple" = "true" }; #toggle element_defaults.toggle = { type = 'submit', "data-dojo-type" = "dijit/form/ToggleButton" "data-dojo-props" = "iconClass:'dijitCheckBoxIcon'" }; # INPUT ELEMENT BLOCK input ; IF label_pos != 1 and label_pos != -1; label_pos = -1; END; IF element_data; # Only process element if one exists. DEFAULT element_data.title = element_data.label element_data.type = "text"; input_type_keys = input_keys.${element_data.type} or default_input_keys; input_defaults = element_defaults.${element_data.type} or {}; IF 'text' == element_data.type and 'date' == element_data.class; input_type_keys = input_keys.date; input_defaults = element_defaults.date; END; IF 'date' == element_data.type; # we can't add 'type="date"' because HTML5 defines it, # which conflicts with our use for Dojo element_data.type = 'text'; END; PROCESS auto_id element_type = 'input';; PROCESS attributes attribute_data = element_data, attribute_defaults = input_defaults, element_keys = input_type_keys, custom_attribute_data = element_data.attributes; IF label_pos == -1; PROCESS auto_label; END; # wrap the input in a span so grids don't stretch it ""; IF label_pos == 1; PROCESS auto_label; END; END; END; # TEXTAREA ELEMENT BLOCK textarea ; IF element_data; DEFAULT element_data.title = element_data.label; PROCESS auto_id element_type = 'textarea'; PROCESS attributes attribute_data = element_data, attribute_defaults = element_defaults.textarea, element_keys = textarea_keys, custom_attribute_data = element_data.attributes; PROCESS auto_label; "" _ element_data.text _ ""; END ; END ; # SELECT ELEMENT BLOCK select ; IF element_data; DEFAULT element_data.title = element_data.label; text_attr = element_data.text_attr or 'text'; value_attr = element_data.value_attr or 'value'; PROCESS auto_id element_type = 'select'; PROCESS attributes attribute_data = element_data, attribute_defaults = ((element_data.type == "multiselect") ? element_defaults.multiselect : element_defaults.select), element_keys = select_keys, custom_attribute_data = element_data.attributes; PROCESS auto_label; # wrap all SELECTs in SPANs so grids don't stretch the selects ""; IF element_data.default_blank; # loop.count starts at 1, so using index 0 here is safe: it won't overlap below PROCESS option parent_id = element_data.id, optindex = 0, option_data = { $text_attr = "", $value_attr = element_data.required ? "" : "_!lsmb!empty!_" }, text_attr = text_attr, value_attr = value_attr; END; FOREACH option IN element_data.options; PROCESS option parent_id = element_data.id, optindex = loop.count, option_data = option, text_attr = text_attr, value_attr = value_attr; END; ""; END ; END ; # OPTION ELEMENT BLOCK option ; # Selected is a special case # -- no attribute key, so it is handled here by looking for the option value in the default_values list. option_selected = ""; FOREACH test_val IN element_data.default_values; IF test_val.defined and option_data.$value_attr == test_val; option_selected = 'selected'; END; END; PROCESS attributes attribute_data = { value => option_data.$value_attr, id => "${parent_id}-${optindex}", selected => option_selected, }, element_keys = option_keys, custom_attribute_data = option_data.attributes; "" _ ((option_data.$text_attr == '_!lsmb!empty!_') ? "" : option_data.$text_attr) _ ""; END ; # BUTTON ELEMENT BLOCK button ; IF element_data; PROCESS auto_id element_type = 'button'; PROCESS attributes attribute_data = element_data attribute_defaults = element_defaults.button element_keys = button_keys, custom_attribute_data = element_data.attributes; PROCESS auto_label; "" _ element_data.text _ ""; IF element_data.tooltip.msg; INCLUDE tooltip element_data = { id => element_data.tooltip.id, ref_id => element_data.id, position => element_data.tooltip.position, msg => element_data.tooltip.msg }; END; END; END ; # TOGGLE ELEMENT BLOCK toggle ; IF element_data; PROCESS auto_id element_type = 'toggle'; PROCESS attributes attribute_data = element_data, attribute_defaults = element_defaults.toggle, element_keys = toggle_keys, custom_attribute_data = element_data.attributes; PROCESS auto_label # Process element label. "" _ element_data.text _ ""; END; END; # LABEL ELEMENT BLOCK label ; IF element_data.text; PROCESS auto_id element_type = 'label'; PROCESS attributes attribute_data = element_data, attribute_defaults = {}, element_keys = for_keys, custom_attribute_data = element_data.attributes; "" _ element_data.text _ ""; END; END; # REGULAR ATTRIBUTE PROCESSING -- all explicitly allowed attributes are processed here. BLOCK attributes ; all_attributes = ""; FOREACH element_attribute IN element_keys; # Loop through each allowed attribute. IF attribute_data.item(element_attribute).defined() and (attribute_data.item(element_attribute) != ""); all_attributes = "$all_attributes $element_attribute=\"" _ attribute_data.item(element_attribute) _ "\""; ELSIF attribute_defaults.item(element_attribute).defined() and (attribute_defaults.item(element_attribute) != ""); all_attributes = "$all_attributes $element_attribute=\"" _ attribute_defaults.item(element_attribute) _ "\""; END; END; FOREACH element_attribute IN custom_attribute_data; all_attributes = all_attributes _ " " _ element_attribute.key _ '="' _ element_attribute.value _ '"'; END; END; BLOCK auto_id ; # Automatically builds the id tag for the element if possible. UNLESS element_data.id.defined(); # id attribute should always be set, so auto-set it if it is not defined. element_id = ""; # Label ids default to [for]-label. IF element_type == 'label' AND (element_data.for.defined() OR element_type == 'toggle'); element_id = element_data.for _ "-label"; ELSIF ((element_type == 'input' AND element_data.type == 'radio') OR element_type == 'button') AND element_data.name.defined() AND element_data.value.defined(); # radios and buttons get name-value for uniqueness. element_id = element_data.name _ "-" _ element_data.value; ELSIF (element_type == 'input' OR element_type == 'textarea' OR element_type == 'select') AND element_data.name.defined(); element_id = element_data.name; END; # Add the id if it has been generated. Replace all non alphanumeric characters with dashes -- nicer CSS. IF element_id; element_data.id = element_id.replace('[^\p{IsAlnum}]', '-'); END; END; END; BLOCK auto_label ; # Sets a label for a form element if the special 'label' key is passed. IF element_data.label.defined() and element_data.label != '_none_'; # Add a 'for' attribute for the label if possible. IF element_data.id.defined(); label_id = ' id="' _ element_data.id _ '-label"'; label_for = ' for="' _ element_data.id _ '"'; ELSE; label_id = ""; label_for = ""; END; # Label inherits class of the related element if possible. IF element_data.class.defined(); label_class = ' class="' _ element_data.class _ '"'; ELSE; label_class = ""; END; "" _ text(element_data.label) _ ""; END; END; BLOCK decorated_text; IF element_data && element_data.msg.defined(); element_data.msg.replace('<((/?[ibup]|br))>','<$1>'); END; END; BLOCK tooltip; IF element_data && element_data.msg.defined(); ref_if = element_data.ref_id; position = (element_data.position.defined() ? (", position:['" _ element_data.position.join("','") _ "']") : ""); "
"; INCLUDE decorated_text element_data = { msg => element_data.msg }; "
"; END; END; BLOCK select_language; IF ! element_data.default_values || element_data.default_values.size == 0 ; element_data.default_values = [ SETTINGS.default_language ] ; END ; PROCESS select element_data=element_data ; END ; BLOCK select_country; IF ! element_data.default_values || element_data.default_values.size == 0 ; element_data.default_values = [ SETTINGS.default_country ] ; END ; PROCESS select element_data=element_data ; END ; -%]