module TheAdmin
module FormHelpers
# View helper to generate check box
# @param id [String] the checkbox id attribute
# @param name [String] the checkbox name attribute
# @param value [String] the checkbox value
# @param label [String] the checkbox label
# @param checked [Boolean] if the checkbox is checked
# @param switch [Boolean] if the checkbox is a switch
# @param align [String] if the alignment should be left or right
# @param inline [Boolean] if the element is inline
# @param form_group [Boolean] if a form group
# @param required [Boolean] if required or not
# @return [String] Compiled html checkbox
def x_checkbox(id: "", name: "", value: "", label: "", checked: false, switch: false, align: false, inline: false, form_group: true, required: false)
checked_output = ""
switchery_div = ""
switchery_input = ""
align_class = ""
inline_class = ""
form_group_start = ""
form_group_end = ""
required_output = ""
if checked == true then checked_output='checked="checked"' end
if switch == true then switchery_div='checkbox-switchery' end
if switch == true then switchery_input='switch' end
if align == "left" then align_class='pull-left' end
if align == "right" then align_class='pull-right' end
if inline == true then inline_class ='inline' end
if form_group == true then form_group_start = '
' end
if form_group == true then form_group_end = '
' end
if required == true then required_output = "data-parsley-mincheck='1'" end
cb = <
#{form_group_end}
EOS
return cb
end
# Check box helper
# @param id [String] the checkbox id
# @param name [String] the name attribute of the checkbox
# @param value [String] the checkbox value
# @param label [String] the label text of the checkbox
# @param checked [Boolean] if the checkbox is checked
# @param switch [Boolean] if the checkbox is a switchery input
# @param align [String] if the check box aligned 'left' or 'right'
# @param inline [Boolean] if the checkbox is inline or not
# @param form_group [Boolean] if the checkbox is of form group
# @param required [Boolean] if checkbox is required
# @return [String] the compiled checkbox
def x_checkbox_string(id: "", name: "", value: "", label: "", checked: false, switch: false, align: false, inline: false, form_group: true, required: false)
checked_output = ""
switchery_div = ""
switchery_input = ""
align_class = ""
inline_class = ""
form_group_start = ""
form_group_end = ""
required_output = ""
if checked == true then checked_output='checked="checked"' end
if switch == true then switchery_div='checkbox-switchery' end
if switch == true then switchery_input='switch' end
if align == "left" then align_class='pull-left' end
if align == "right" then align_class='pull-right' end
if inline == true then inline_class ='inline' end
if form_group == true then form_group_start = '
' end
if form_group == true then form_group_end = '
' end
if required == true then required_output = "data-parsley-mincheck='1'" end
cb = <
#{form_group_end}
EOS
return cb
end
# Radio button view helper
# @param id [String] the radio id
# @param name [String] the name attribute of the radio
# @param value [String] the radio value
# @param label [String] the label text of the radio
# @param checked [Boolean] if the radio is checked
# @param align [String] if the check box aligned 'left' or 'right'
# @param inline [Boolean] if the radio is inline or not
# @param form_group [Boolean] if the radio is of form group
# @return [String] the compiled radio
def x_radio(id: "", name: "", value: "1", label: "", checked: false, checked_if: "", align: false, inline: false, include_false_as_hidden: false ,form_group: true)
checked_output = ""
align_class = ""
inline_class = ""
form_group_start = ""
form_group_end = ""
include_false_as_hidden_element = ""
if checked == checked_if then checked_output='checked="checked"' end
if checked_if != "" then checked = false end
if checked == true then checked_output='checked="checked"' end
if align == "left" then align_class='pull-left' end
if align == "right" then align_class='pull-right' end
if inline == true then inline_class ='inline' end
if form_group == true then form_group_start = '
' end
if form_group == true then form_group_end = '
' end
if include_false_as_hidden == true then include_false_as_hidden_element = '' end
radio_btn = <
#{form_group_end}
EOS
return radio_btn
end
# Hidden input helper
# @param id [String] hidden input id
# @param name [String] hidden input name
# @param value [String] hidden input value
# @return [String] compiled hidden input html
def x_hidden(id: "", name: "", value: "")
hi = <
EOS
return hi
end
# Text input helper
# @param id [String] input element id
# @param name [String] input element name
# @param value [String] input element value
# @param label [String] input element label
# @param required [Boolean] if input element is required
# @param placeholder [String] input element placeholder
# @param mask [String] input element mask
# @param maxlength [String] input element max length
# @return [String] compiled input element
def x_input(id: "", name: "", value: "", label: "", required: false, placeholder: "", mask: "", maxlength: "", css:"")
id = name unless id != ""
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# Money input helper
# @param id [String] the money input id
# @param name [String] the money input name
# @param label [String] the money input label
# @param required [Boolean] if money input is required or not
# @param placeholder [String] the moeny input placeholder
# @param mask [String] the money input mask
# @param maxlength [String] max length of the input
# @return [String] compiled money input html
def x_money(id: "", name: "", value: "", label: "", required: false, placeholder: "", mask: "", maxlength: "")
id = name unless id != ""
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
if value == 0 || value.nil? || value == ""
value = "0.00"
else
value = "%.2f" % value rescue nil
end
tb = <
#{label}#{required_output}
$
EOS
return tb
end
# Percentage input helper
# @param id [String] percentage input id
# @param name [String] percentage input name
# @param value [String] percentage input value
# @param label [String] percentage input label
# @param required [Boolean] if percentage input is required
# @param placeholder [String] percentage input placeholder
# @param mask [String] percentage input mask
# @param maxlength [String] percentage input maxlength
def x_percentage(id: "", name: "", value: "", label: "", required: false, placeholder: "", mask: "", maxlength: "")
id = name unless id != ""
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
tb = <
#{label}#{required_output}
%
EOS
return tb
end
# Sq Ft input helper
# @param id [String] percentage input id
# @param name [String] percentage input name
# @param value [String] percentage input value
# @param label [String] percentage input label
# @param required [Boolean] if percentage input is required
# @param placeholder [String] percentage input placeholder
# @param mask [String] percentage input mask
# @param maxlength [String] percentage input maxlength
def x_sqft(id: "", name: "", value: "", label: "", required: false, placeholder: "", mask: "", maxlength: "")
id = name unless id != ""
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
tb = <
#{label}#{required_output}
sqft
EOS
return tb
end
# Number input helper
# @param id [String] number input id
# @param name [String] number input name
# @param value [String] number input value
# @param label [String] number input label
# @param required [Boolean] if required or not
# @param placeholder [String] number input placeholder text
# @param mask [String] number input mask
# @param maxlength [String] nuber input max length
# @return [String] compiled html of number input
def x_number(id: "", name: "", value: "", label: "", required: false, placeholder: "", mask: "", maxlength: "")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
tb = <
#{label}
EOS
return tb
end
# Phone input helper
# @param id [String] phone input id
# @param name [String] phone input name
# @param value [String] phone input value
# @param label [String] phone input label
# @param required [Boolean] if required or not
# @param placeholder [String] phone input placeholder text
# @param mask [String] phone input mask
# @param maxlength [String] nuber input max length
# @return [String] compiled html of phone input
def x_phone(id: "", name: "", value: "", label: "", required: false, placeholder: "", mask: "(999) 999-9999 x99999", maxlength: "22")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
tb = <
#{label}
EOS
return tb
end
# SSN input helper
# @param id [String] ssn input id
# @param name [String] ssn input name
# @param value [String] ssn input value
# @param label [String] ssn input label
# @param required [Boolean] if required or not
# @param placeholder [String] ssn input placeholder text
# @param mask [String] ssn input mask
# @param maxlength [String] nuber input max length
# @return [String] compiled html of ssn input
def x_ssn(id: "", name: "", value: "", label: "", required: false, placeholder: "", mask: "999-99-9999")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
tb = <
#{label}
EOS
return tb
end
# EIN input helper
# @param id [String] ein input id
# @param name [String] ein input name
# @param value [String] ein input value
# @param label [String] ein input label
# @param required [Boolean] if required or not
# @param placeholder [String] ein input placeholder text
# @param mask [String] ein input mask
# @param maxlength [String] nuber input max length
# @return [String] compiled html of ein input
def x_ein(id: "", name: "", value: "", label: "", required: false, placeholder: "", mask: "99-9999999", maxlength: "10")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
tb = <
#{label}
EOS
return tb
end
# Zip input helper
# @param id [String] zip input id
# @param name [String] zip input name
# @param value [String] zip input value
# @param label [String] zip input label
# @param required [Boolean] if required or not
# @param placeholder [String] zip input placeholder text
# @param mask [String] zip input mask
# @param maxlength [String] nuber input max length
# @return [String] compiled html of zip input
def x_zip(id: "", name: "", value: "", label: "", required: false, placeholder: "", mask: "99999", maxlength: "5")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
tb = <
#{label}
EOS
return tb
end
# State input helper
# @param id [String] state input id
# @param name [String] state input name
# @param value [String] state input value
# @param label [String] state input label
# @param required [Boolean] if required or not
# @param placeholder [String] state input placeholder text
# @param mask [String] state input mask
# @param maxlength [String] nuber input max length
# @return [String] compiled html of state input
def x_state(id: "", name: "", value: "", label: "", required: false, placeholder: "", mask: "aa", maxlength: "2")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
tb = <
#{label}
EOS
return tb
end
# Credit card input helper
# @param id [String] credit card input id
# @param name [String] credit card input name
# @param value [String] credit card input value
# @param label [String] credit card label
# @param required [Boolean] if required or not
# @param placeholder [String] credit card input placeholder text
# @param mask [String] credit card input mask
# @param maxlength [String] nuber input max length
# @return [String] compiled html of credit card input
def x_credit_card(id: "", name: "", value: "", label: "", required: false, placeholder: "", maxlength: "16", mask:"")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
tb = <
#{label}
EOS
return tb
end
# CVC input helper
# @param id [String] cvc input id
# @param name [String] cvc input name
# @param value [String] cvc input value
# @param lable [String] cvc label
# @param required [Boolean] if required or not
# @param placeholder [String] cvc input placeholder text
# @param mask [String] cvc input mask
# @param maxlength [String] nuber input max length
# @return [String] compiled html of cvc input
def x_cvc(id: "", name: "", value: "", label: "", required: false, placeholder: "", maxlength: "4", mask:"999999999999999999")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if mask != ""
mask = "data-masked-input='#{mask}'"
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# Email input helper
# @param id [String] email input id
# @param name [String] email input name
# @param value [String] email input value
# @param label [String] email input label
# @param required [Boolean] if required or not
# @param placeholder [String] email input placeholder text
# @return [String] compiled html of email input
def x_email(id: "", name: "", value: "", label: "", required: false, placeholder: "")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# URL input helper
# @param id [String] url input id
# @param name [String] url input name
# @param value [String] url input value
# @param label [String] url input label
# @param required [Boolean] if required or not
# @param placeholder [String] url input placeholder text
# @return [String] compiled html of url input
def x_url(id:"", name:"", value:"", label:"", required: false, placeholder: "")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# File input helper
# @param id [String] file input id
# @param name [String] file input name
# @param value [String] file input value
# @param label [String] file input label
# @param required [Boolean] if required or not
# @param placeholder [String] file input placeholder text
# @param css [String] file input css
# @return [String] compiled html of file input
def x_file(id:"", name:"", value:"", label:"", required: false, placeholder: "", css: "")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# Image Upload
# @param id [String] file input id
# @param name [String] file input name
# @param value [String] file input value
# @param label [String] file input label
# @param required [Boolean] if required or not
# @param placeholder [String] file input placeholder text
# @param css [String] file input css
# @return [String] compiled html of file input
def x_image_upload(id: "input1",name: "input1",value: "",label: "Input1",required: false, size: "1M",height: "",default: "")
if required && label != ""
required_output = '*'
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if height == ""
height = ""
else
height="data-height='#{height}'"
end
tb = <
EOS
return tb
end
# Date input helper
# @param id [String] date input id
# @param name [String] date input name
# @param value [String] date input value
# @param label [String] date input label
# @param required [Boolean] if required or not
# @param placeholder [String] date input placeholder text
# @return [String] compiled html of date input
def x_date(id: "", name: "", value: "", label: "", required: false, placeholder: "")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# Date-time input helper
# @param id [String] date-time input id
# @param name [String] date-time input name
# @param value [String] date-time input value
# @param label [String] date-time input label
# @param required [Boolean] if required or not
# @param placeholder [String] date-time input placeholder text
# @return [String] compiled html of date-time input
def x_datetime(id: "", name: "", value: "", label: "", required: false, placeholder: "")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# Time input helper
# @param id [String] time input id
# @param name [String] time input name
# @param value [String] time input value
# @param label [String] time input label
# @param required [Boolean] if required or not
# @param placeholder [String] time input placeholder text
# @return [String] compiled html of time input
def x_time(id: "", name: "", value: "", label: "", required: false, placeholder: "")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# Password input helper
# @param id [String] password input id
# @param name [String] password input name
# @param value [String] password input value
# @param label [String] password input label
# @param required [Boolean] if required or not
# @param placeholder [String] password input placeholder text
# @return [String] compiled html of password input
def x_password(id: "",name: "", value: "", label: "", required: false, placeholder: "")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# Submit Helper
# @param label [String] submit button label
# @param css [String] submit button css
# @param icon [String] submit button icon
# @param size [String] submit button size
# @param wrapper_css [String] submit button wrapper css
# @return [String] compiled html of submit button
def x_submit(label: "Submit", css: "btn-primary", icon: "", size: "", wrapper_css: "pull-right")
if icon != ""
icon = " "
end
submit = <
EOS
return submit
end
# Text Area Helper
# @param id [String] textarea id
# @param name [String] textarea name
# @param value [String] textarea value
# @param placeholder [String] textarea placeholder text
# @param label [String] textarea label
# @param required [Boolean] if required or not
# @param maxlength [String] textarea max length
# @return [String] compiled html of textarea
def x_textarea(id: "", name: "", value: "",label: "",placeholder: "",required: false, maxlength:"")
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
if label != ""
label = ""
end
if maxlength != ""
maxlength = "maxlength='#{maxlength}'"
end
ta = <
#{label}#{required_output}
EOS
return ta
end
# Summernote
# @param id [String] summernote id
# @param name [String] summernote name
# @param value [String] summernote value
# @param label [String] summernote label
# @param required [Boolean] if required or not
# @return [String] compiled html of summernote
def x_html(id: "", name: "", value: "", label: "", help: "", required: false)
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
ta = <
#{label}
EOS
return ta
end
# Year Drop down
def x_year
current_year = Time.now.year
year_dd = <
EOS
end
# Year Drop down (expiry)
def x_exp_year
current_year = Time.now.year
begining_year = Time.now.year + 6
year_dd = <
EOS
end
# Month Drop down
def x_exp_month
current_year = Time.now.year
begining_year = Time.now.year - 6
year_dd = <
EOS
end
# Switch
# @param id [String] summernote id
# @param name [String] summernote name
# @param value [String] summernote value
# @param label [String] summernote label
# @param checked [Boolen] if checked or not
# @return [String] compiled html of summernote
def x_switch(id: "", name: "", value: "", label: "", checked: false)
checked_output = ""
if checked == true then checked_output='checked="checked"' end
cb = <
EOS
return cb
end
# Tags
# @param id [String] tags id
# @param name [String] tags name
# @param value [String] tags value
# @param label [String] tags label
# @param required [Boolean] if required or not
# @param placeholder [String] tags placeholder text
# @return [String] compiled html of tags
def x_tags(id: "", name: "", value: "", label: "", required: false, placeholder: "")
id = name unless id != ""
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# Typeahead
# @param id [String] typeahead id
# @param name [String] typeahead name
# @param value [String] typeahead value
# @param label [String] typeahead label
# @param required [Boolean] if required or not
# @param placeholder [String] typeahead placeholder text
# @param css [String] typeahead css
# @return [String] compiled html of typeahead
def x_typeahead(id: "", name: "", value: "", label: "", required: false, placeholder: "", css: "")
id = name unless id != ""
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
if label != ""
label = ""
end
tb = <
#{label}#{required_output}
EOS
return tb
end
# Rating Radios
# @param id [String] id of the survey radio
# @param name [String] name of the survey radio
# @return [String] compiled html of the survey radio
def x_survey_radio(id: "", name: "")
tb = <
EOS
return tb
end
# Select Dropdown
# @param id [String] id of the select
# @param name [String] name of the select
# @param value [String] value of the select
# @param name_col [String] name col of the select
# @param value_col [String] vale col of the select
# @param label [String] label of the select
# @param css [String] css of the select
# @param menu_style [String] menu syle of the select
# @param style [String] style classes of the select
# @param option_data [String] option data
# @param option_name [String] option name
# @param option_value [String] option value
# @param selected_value [String] selected value of the select
# @param title [String] title of the select
# @param multple [Boolean] if multiple selection is enabled
# @return [String] compiled select drop down
def x_select(id: "", name: "", value: "",name_col: "name", value_col: "id", label: "", css: "selectpicker", menu_style: "dropdown-blue", style: "btn-default btn-block", option_data: "", option_name: "name", option_value: "id", selected_value: "", title: "", multiple: false, add_none: false, required: false, menu_size: 0, live_search: false)
options_html = ""
show_multiple = ""
add_none_option = ""
live_search_html = ""
if multiple == true
show_multiple = "Multiple"
end
if required
if label != ""
required_output = '*'
else
required_output = ''
end
required_tag = 'required="required"'
else
required_output = ""
required_tag = ""
end
multiple_name = ""
if multiple == true
multiple_name = "[]"
end
option_data.each do |i|
selected = ""
if selected_value == i[:id]
selected = "selected='selected'"
end
if selected_value.kind_of?(Array) && (selected_value.include? i[:id])
selected = "selected='selected'"
end
unless name_col.kind_of?(Array)
options_html << ""
else
options_html << ""
end
end
if option_data.count == 0 || option_data.nil?
options_html << ""
end
if add_none == true
add_none_option = ""
end
if menu_size == 0
menu_size_html = ""
else
menu_size_html = "data-size='#{menu_size}'"
end
if live_search == true
live_search_html = "data-live-search='true'"
end
select = <
EOS
return select
end
end
end