sugoi internally added
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
import form.Form;
|
||||
import form.FormElement;
|
||||
|
||||
|
||||
class Button extends FormElement
|
||||
{
|
||||
public var type:ButtonType;
|
||||
|
||||
//public function new(name:String, label:String, ?value:String = "Submit", ?type:ButtonType = null)
|
||||
public function new(name:String, label:String, ?value:String = null, ?type:ButtonType = null)
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
this.type = (type == null) ? ButtonType.SUBMIT : type;
|
||||
}
|
||||
|
||||
override public function isValid():Bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
override public function render() :String
|
||||
{
|
||||
return "<button type=\"" + type + "\" class=\"" + getClasses() +"\" value=\"" + value + "\" " + attributes + " name=\"" +parentForm.name + "_" +name + "\" id=\"" +parentForm.name + "_" +name + "\" >" +label + "</button>";
|
||||
|
||||
}
|
||||
|
||||
public function toString() :String
|
||||
{
|
||||
return render();
|
||||
}
|
||||
|
||||
override public function getLabel():String
|
||||
{
|
||||
var n = parentForm.name + "_" + name;
|
||||
|
||||
return "<label for=\"" + n + "\" ></label>";
|
||||
}
|
||||
|
||||
override public function getPreview():String
|
||||
{
|
||||
return "<tr><td></td><td>" + this.render() + "<td></tr>";
|
||||
}
|
||||
|
||||
override public function populate():Void
|
||||
{
|
||||
super.populate();
|
||||
var n = parentForm.name + "_" + name;
|
||||
if ( App.current.params.exists(n) )
|
||||
parentForm.submittedButtonName = name;
|
||||
}
|
||||
}
|
||||
|
||||
enum ButtonType
|
||||
{
|
||||
SUBMIT;
|
||||
BUTTON;
|
||||
RESET;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package sugoi.form.elements;
|
||||
import sugoi.form.FormElement;
|
||||
import sugoi.form.elements.Input;
|
||||
#if neko
|
||||
import neko.Web;
|
||||
#else
|
||||
import php.Web;
|
||||
#end
|
||||
|
||||
/**
|
||||
* creates a hidden token in forms to avoid CSRF
|
||||
*/
|
||||
class CSRFProtection extends StringInput
|
||||
{
|
||||
|
||||
public function new()
|
||||
{
|
||||
|
||||
value = haxe.crypto.Md5.encode(App.current.session.sid + App.config.KEY.substr(0, 5));
|
||||
super("token","", value, true);
|
||||
inputType = ITHidden;
|
||||
}
|
||||
|
||||
override public function isValid() {
|
||||
if (value == null) throw "empty token";
|
||||
var valid = Web.getParams().get(parentForm.name + "_" + name) == value;
|
||||
|
||||
if (!valid) {
|
||||
errors.add("Bad token");
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
||||
override public function getFullRow() {
|
||||
return render();
|
||||
}
|
||||
|
||||
override public function render() {
|
||||
|
||||
return "<input type=\"hidden\" value=\"" + value + "\" " + attributes + " name=\"" +parentForm.name + "_" +name + "\" id=\"" +parentForm.name + "_" +name + "\" />";
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
import sugoi.form.Form;
|
||||
import sugoi.form.FormElement;
|
||||
|
||||
class Checkbox extends FormElement<Bool>
|
||||
{
|
||||
|
||||
public function new(name:String, label:String, ?checked:Bool=false, ?required:Bool=false, ?attibutes:String="")
|
||||
{
|
||||
super();
|
||||
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.value = checked;
|
||||
this.required = required;
|
||||
this.attributes = attibutes;
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var n = parentForm.name + "_" +name;
|
||||
|
||||
var checkedStr = value ? "checked" : "";
|
||||
|
||||
return "<input type=\"checkbox\" id=\"" + n + "\" name=\"" + n + "\" class=\"" + getClasses() + "\" value=\"true\" " + checkedStr + " />";
|
||||
}
|
||||
|
||||
|
||||
override public function getTypedValue(str:String):Bool
|
||||
{
|
||||
return str == "1" || str == "true";
|
||||
}
|
||||
|
||||
override public function isValid():Bool
|
||||
{
|
||||
errors.clear();
|
||||
if ( required && value == null )
|
||||
{
|
||||
errors.add("Please check '" + ((label != null && label != "") ? label : name) + "'");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package sugoi.form.elements;
|
||||
import sugoi.form.Form;
|
||||
import sugoi.form.FormElement;
|
||||
import sugoi.form.Formatter;
|
||||
import sugoi.form.ListData;
|
||||
|
||||
/**
|
||||
* Manage an array of string with a checkbox group
|
||||
*/
|
||||
class CheckboxGroup extends FormElement<Array<String>>
|
||||
{
|
||||
public var data:Array<Dynamic>;
|
||||
public var selectMessage:String;
|
||||
public var labelLeft:Bool;
|
||||
public var verticle:Bool;
|
||||
public var labelRight:Bool;
|
||||
public var formatter:Formatter;
|
||||
public var columns:Int;
|
||||
|
||||
public function new(name:String, label:String,data:FormData<String>, ?selected:Array<String>, ?verticle:Bool=true, ?labelRight:Bool=true)
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.data = data;
|
||||
this.value = selected != null ? selected : new Array();
|
||||
this.verticle = verticle;
|
||||
this.labelRight = labelRight;
|
||||
|
||||
columns = 1;
|
||||
}
|
||||
|
||||
override public function populate()
|
||||
{
|
||||
|
||||
var v = Web.getParamValues(parentForm.name + "_" + name);
|
||||
|
||||
if (parentForm.isSubmitted())
|
||||
{
|
||||
value = (v != null) ? v : [];
|
||||
} else {
|
||||
if (v != null) value = v;
|
||||
}
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var s = "";
|
||||
var n = parentForm.name + "_" +name;
|
||||
|
||||
var tagCss = getClasses();
|
||||
var labelCss = getLabelClasses();
|
||||
|
||||
var c = 0;
|
||||
var datas = Lambda.array(data);
|
||||
if (datas != null)
|
||||
{
|
||||
var rowsPerColumn = Math.ceil(datas.length / columns);
|
||||
s = "<table><tr>";
|
||||
for (i in 0...columns)
|
||||
{
|
||||
s += "<td valign=\"top\">\n";
|
||||
s += "<table>\n";
|
||||
|
||||
for (j in 0...rowsPerColumn)
|
||||
{
|
||||
if (c >= datas.length) break;
|
||||
|
||||
s += "<tr>";
|
||||
|
||||
var row:Dynamic = datas[c];
|
||||
|
||||
var checkbox = "<input type=\"checkbox\" class=\"" + tagCss + "\" name=\""+n+"[]\" id=\""+n+c+"\" value=\"" + row.value + "\" " + (value != null ? Lambda.has(value, row.value) ? "checked":"":"") +" ></input>\n";
|
||||
var label;
|
||||
|
||||
if (formatter != null){
|
||||
label = "<label for=\"" + n + c + "\" class=\""+''/*labelCss*/+"\" >" + formatter.format(row.label) +"</label>\n";
|
||||
//}else if(Form.translator!=null){
|
||||
//label = "<label for=\"" + n + c + "\" class=\"" + ''/*labelCss*/+"\" >" + Form.translator._(row.label) +"</label>\n";
|
||||
}else {
|
||||
label = "<label for=\"" + n + c + "\" class=\"" + ''/*labelCss*/+"\" >" + row.label +"</label>\n";
|
||||
}
|
||||
|
||||
if (labelRight)
|
||||
{
|
||||
s += "<td>" + checkbox + "</td>\n";
|
||||
s += "<td> " + label + "</td>\n";
|
||||
} else {
|
||||
s += "<td>" + label + " </td>\n";
|
||||
s += "<td>" + checkbox + "</td>\n";
|
||||
}
|
||||
s += "</tr>";
|
||||
c++;
|
||||
}
|
||||
s += "</table>";
|
||||
s += "</td>";
|
||||
}
|
||||
s += "</tr></table>\n";
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
import sugoi.Web;
|
||||
import sugoi.form.FormElement;
|
||||
import sugoi.form.validators.Validator;
|
||||
import sugoi.form.ListData;
|
||||
|
||||
/**
|
||||
* A list of selectBox for day + month + year
|
||||
*/
|
||||
class DateDropdowns extends FormElement<Date>
|
||||
{
|
||||
public var maxOffset:Int;
|
||||
public var minOffset:Int;
|
||||
|
||||
//public var date : Date; //valeur typée à la place de value:Dynamic
|
||||
|
||||
public var yearMin:Int;
|
||||
public var yearMax:Int;
|
||||
|
||||
private var daySelector:Selectbox<Int>;
|
||||
private var monthSelector:Selectbox<Int>;
|
||||
private var yearSelector:Selectbox<Int>;
|
||||
|
||||
public function new(name:String, label:String, ?_value:Date, ?required:Bool=false, yearMin:Int=1950, yearMax:Int=null, ?validators:Array<Validator<Date>>, ?attibutes:String="")
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
|
||||
if (_value == null) {
|
||||
value = Date.now();
|
||||
}else {
|
||||
value = _value;
|
||||
}
|
||||
|
||||
this.required = required;
|
||||
this.attributes = attibutes;
|
||||
this.yearMin = yearMin;
|
||||
this.yearMax = yearMax;
|
||||
|
||||
maxOffset = null;
|
||||
minOffset = null;
|
||||
|
||||
var day :Int = null;
|
||||
var month :Int = null;
|
||||
var year :Int = null;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
day = value.getDate();
|
||||
month = (value.getMonth()+1);
|
||||
year = value.getFullYear();
|
||||
}
|
||||
|
||||
var t = sugoi.form.Form.translator;
|
||||
daySelector = new IntSelect(name+"_day", t._("day"),ListData.getDays(),day,true);
|
||||
monthSelector = new IntSelect(name+"_month", t._("month"),ListData.getMonths(),month,true);
|
||||
yearSelector = new IntSelect(name+"_year", t._("year"), ListData.getYears(Date.now().getFullYear()-3, Date.now().getFullYear()+3, true), year, true);
|
||||
|
||||
daySelector.internal = monthSelector.internal = yearSelector.internal = true;
|
||||
|
||||
//if (Form.USE_TWITTER_BOOTSTRAP) {
|
||||
//daySelector.cssClass = "input-mini";
|
||||
//}
|
||||
//trace("date : " + date);
|
||||
}
|
||||
public function shortLabels()
|
||||
{
|
||||
daySelector.nullMessage = "-D-";
|
||||
monthSelector.nullMessage = "-M-";
|
||||
yearSelector.nullMessage = "-Y-";
|
||||
monthSelector.data = ListData.getMonths(true);
|
||||
}
|
||||
|
||||
override public function init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
parentForm.addElement(daySelector);
|
||||
parentForm.addElement(monthSelector);
|
||||
parentForm.addElement(yearSelector);
|
||||
}
|
||||
|
||||
override public function populate()
|
||||
{
|
||||
|
||||
var day = Std.parseInt(App.current.params.get(parentForm.name + "_" + daySelector.name));
|
||||
var month = Std.parseInt(App.current.params.get(parentForm.name + "_" + monthSelector.name));
|
||||
var year = Std.parseInt(App.current.params.get(parentForm.name + "_" + yearSelector.name));
|
||||
|
||||
value = (day != null && month != null && year != null ) ? new Date(year, month - 1, day, 0, 0, 0) : null;
|
||||
}
|
||||
|
||||
override public function isValid():Bool
|
||||
{
|
||||
/*var valid = super.isValid();
|
||||
|
||||
if ( required && valid )
|
||||
{
|
||||
var n = form.name + "_" + name;
|
||||
var day = Std.parseInt(App.current.params.get(n));
|
||||
var month = Std.parseInt(App.current.params.get(n));
|
||||
var year = Std.parseInt(App.current.params.get(n));
|
||||
|
||||
if (day == null || month == null || year == null )
|
||||
{
|
||||
errors.add("<span class=\"formErrorsField\">" + ((label != null && label != "") ? label : name) + "</span> is an invalid date.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return valid;*/
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
super.render();
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
try{
|
||||
var v:Date = cast value;
|
||||
daySelector.value = v.getDate();
|
||||
monthSelector.value = v.getMonth()+1;
|
||||
yearSelector.value = v.getFullYear();
|
||||
}catch(e:Dynamic){}
|
||||
}
|
||||
|
||||
return '<div class="row">
|
||||
<div class="col-xs-2">'+daySelector.render()+'</div>
|
||||
<div class="col-xs-6">'+monthSelector.render()+'</div>
|
||||
<div class="col-xs-4">'+yearSelector.render()+'</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package sugoi.form.elements;
|
||||
import sugoi.form.FormElement;
|
||||
import sugoi.form.validators.Validator;
|
||||
import sugoi.form.ListData;
|
||||
|
||||
/**
|
||||
* date selectBox : day month year hour minutes
|
||||
*/
|
||||
class DateInput extends DateDropdowns
|
||||
{
|
||||
private var hourSelector:Selectbox<Int>;
|
||||
private var minuteSelector:Selectbox<Int>;
|
||||
|
||||
public function new(name:String, label:String, ?value:Date, ?required:Bool=false, yearMin:Int=1950, yearMax:Int=null, ?validators:Array<Validator<Date>>, ?attibutes:String="")
|
||||
{
|
||||
super(name, label, value, required, yearMin, yearMax, validators, attibutes);
|
||||
var t = sugoi.form.Form.translator;
|
||||
hourSelector = new Selectbox<Int>(name+"_hour" , t._("hour") , ListData.getDateElement(0,23), value.getHours(),true,"-",'title="Hour"');
|
||||
minuteSelector = new Selectbox<Int>(name+"_minute", t._("minute"), ListData.getDateElement(0, 59), value.getMinutes(), true, "-", 'title="Minute"');
|
||||
|
||||
if (Form.USE_TWITTER_BOOTSTRAP) {
|
||||
hourSelector.cssClass = "form-control";
|
||||
minuteSelector.cssClass = "form-control";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override public function isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
hourSelector.parentForm = this.parentForm;
|
||||
minuteSelector.parentForm = this.parentForm;
|
||||
|
||||
var s = super.render() + " : ";
|
||||
|
||||
if (value != null){
|
||||
var v:Date = cast value;
|
||||
hourSelector.value = v.getHours();
|
||||
minuteSelector.value = v.getMinutes();
|
||||
}
|
||||
s += hourSelector.render() + " h ";
|
||||
s += minuteSelector.render() + " m ";
|
||||
return s;
|
||||
}
|
||||
|
||||
override public function populate()
|
||||
{
|
||||
//super.populate();
|
||||
var n = parentForm.name + "_" + hourSelector.name;
|
||||
var v = App.current.params.get(n);
|
||||
var params = App.current.params;
|
||||
|
||||
if (v != null)
|
||||
{
|
||||
var minute = Std.parseInt(params.get(parentForm.name + "_" + minuteSelector.name));
|
||||
var hour = Std.parseInt(params.get(parentForm.name + "_" + hourSelector.name));
|
||||
var day = Std.parseInt(params.get(parentForm.name + "_" + daySelector.name));
|
||||
var month = Std.parseInt(params.get(parentForm.name + "_" + monthSelector.name));
|
||||
var year = Std.parseInt(params.get(parentForm.name + "_" + yearSelector.name));
|
||||
|
||||
value = new Date(year, month - 1, day, hour, minute, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
import sugoi.Web;
|
||||
import sugoi.form.FormElement;
|
||||
import sugoi.form.validators.Validator;
|
||||
import sugoi.form.ListData;
|
||||
|
||||
/**
|
||||
* DatePicker for Bootstrap 3
|
||||
*
|
||||
* You'll need to install some additionnal js librairies (moment.js, jquery)
|
||||
* more info at : http://eonasdan.github.io/bootstrap-datetimepicker/
|
||||
*/
|
||||
class DatePicker extends FormElement<Date>
|
||||
{
|
||||
public var maxOffset:Int;
|
||||
public var minOffset:Int;
|
||||
|
||||
public var yearMin:Int;
|
||||
public var yearMax:Int;
|
||||
|
||||
private var daySelector:Selectbox<Int>;
|
||||
private var monthSelector:Selectbox<Int>;
|
||||
private var yearSelector:Selectbox<Int>;
|
||||
|
||||
public var format : String; //moment.js format
|
||||
|
||||
public function new(name:String, label:String, ?v:Date, ?required:Bool=false, yearMin:Int=1950, yearMax:Int=null, ?validators:Array<Validator<Date>>, ?attibutes:String="")
|
||||
{
|
||||
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
format = 'LLLL';
|
||||
|
||||
if (v == null) {
|
||||
this.value = Date.now();
|
||||
}else {
|
||||
this.value = v;
|
||||
}
|
||||
|
||||
//trace(value);
|
||||
|
||||
this.required = required;
|
||||
this.attributes = attibutes;
|
||||
this.yearMin = yearMin;
|
||||
this.yearMax = yearMax;
|
||||
|
||||
maxOffset = null;
|
||||
minOffset = null;
|
||||
|
||||
var day = "";
|
||||
var month = "";
|
||||
var year = "";
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
day = ""+value.getDate();
|
||||
month = ""+(value.getMonth()+1);
|
||||
year = ""+value.getFullYear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override public function populate()
|
||||
{
|
||||
//data is stored as float in the html form element
|
||||
var d = App.current.params.get(parentForm.name + "_" + name);
|
||||
//trace(parentForm.name + "_" + name+"="+d);
|
||||
//value = Date.fromTime(Std.parseFloat(d));
|
||||
value = Date.fromString(d);
|
||||
}
|
||||
|
||||
override public function isValid():Bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
|
||||
//component init date
|
||||
//var d = value.getFullYear() +"-" + (value.getMonth() + 1) + "-" + value.getDate() + " " + value.getHours() + ":" + value.getMinutes()+":00";
|
||||
var d = value.toString();
|
||||
var defaultDate = 'moment("' + d + '", "YYYY-MM-DD HH:mm:ss")';
|
||||
|
||||
return "
|
||||
<div class='input-group date' id='datetimepicker-"+name+"'>
|
||||
<span class='input-group-addon'>
|
||||
<span class='glyphicon glyphicon-calendar'></span>
|
||||
</span>
|
||||
<input type='text' class='form-control' />
|
||||
</div>
|
||||
|
||||
<input type='hidden' name='"+parentForm.name+"_"+name+"' id='datetimepickerdata-"+name+"' value='"+d+"'/>
|
||||
<script type='text/javascript'>
|
||||
$(function () {
|
||||
$('#datetimepicker-"+name+"').datetimepicker(
|
||||
{
|
||||
locale:'fr',
|
||||
format:'"+this.format+"',
|
||||
defaultDate:"+defaultDate+"
|
||||
}
|
||||
);
|
||||
//stores the date in mysql format in a hidden input element
|
||||
$('#datetimepicker-"+name+"').on('dp.change',function(e){
|
||||
var d = $('#datetimepicker-"+name+"').data('DateTimePicker').date();//moment.js obj
|
||||
//fix 2038 date overflow bug https://en.wikipedia.org/wiki/Year_2038_problem
|
||||
if(d.year()>2037) d.year(2037);
|
||||
console.log(d.toString());
|
||||
$('#datetimepickerdata-"+name+"').val( d.format('YYYY-MM-DD HH:mm:ss'));
|
||||
});
|
||||
});
|
||||
</script>";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 2008, TouchMyPixel & contributors
|
||||
* Original author : Matt Benton <matt@touchmypixel.com>
|
||||
* Contributers: Tarwin Stroh-Spijer
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE TOUCH MY PIXEL & CONTRIBUTERS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE TOUCH MY PIXEL & CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
package form.elements;
|
||||
|
||||
import form.Form;
|
||||
import form.FormElement;
|
||||
import poko.Poko;
|
||||
|
||||
enum EmbeddedVideoService
|
||||
{
|
||||
youtube;
|
||||
vimeo;
|
||||
}
|
||||
|
||||
typedef EmbeddedVideoConfig =
|
||||
{
|
||||
var videoID:String;
|
||||
var width:Int;
|
||||
var height:Int;
|
||||
}
|
||||
|
||||
typedef VimeoConfig =
|
||||
{ > EmbeddedVideoConfig,
|
||||
var color:String;
|
||||
var showPortrait:Bool;
|
||||
var showTitle:Bool;
|
||||
var showByline:Bool;
|
||||
}
|
||||
|
||||
class EmbeddedVideoOptions extends FormElement
|
||||
{
|
||||
// Type of video service
|
||||
public var service:EmbeddedVideoService;
|
||||
/**
|
||||
* Common options
|
||||
*/
|
||||
//public var videoID:String;
|
||||
//public var width:Int;
|
||||
//public var height:Int;
|
||||
/**
|
||||
* Vimeo options
|
||||
*/
|
||||
// Can be Blue, Orange, Lime, Fuschia, White or #RRGGBB
|
||||
//public var color:String;
|
||||
//public var showPortrait:Bool;
|
||||
//public var showTitle:Bool;
|
||||
//public var showByline:Bool;
|
||||
|
||||
public var vimeo (default, null) : VimeoConfig;
|
||||
|
||||
public function new(name:String, label:String, service:EmbeddedVideoService)
|
||||
{
|
||||
super();
|
||||
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var n = form.name + "_" + name;
|
||||
if ( service == EmbeddedVideoService.vimeo )
|
||||
{
|
||||
var color = new Input(n + "Color", "Color", "Blue");
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function toString() :String
|
||||
{
|
||||
return render();
|
||||
}
|
||||
|
||||
override public function populate():Void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*var date:Date = cast value;
|
||||
var year = date.getFullYear();
|
||||
var month = date.getMonth();
|
||||
var day = date.getDate();
|
||||
|
||||
var l = new List();
|
||||
var s = "";
|
||||
|
||||
var elYear = new Selectbox(form, "1", ListData.getYears(1990, 2000, true), Std.string(year), false, "");
|
||||
var elMonth = new Selectbox(form, "2", ListData.getMonths(), Std.string(year), false);
|
||||
var elDay = new Selectbox(form, "3", ListData.getDays() , Std.string(year), false);
|
||||
|
||||
form.addElement(name + "[]", elYear);
|
||||
form.addElement(name + "[]", elMonth);
|
||||
form.addElement(name + "[]", elDay);
|
||||
|
||||
s += elYear.toString();
|
||||
s += elMonth.toString();
|
||||
s += elDay.toString();
|
||||
|
||||
form.initElements();
|
||||
*/
|
||||
@@ -0,0 +1,128 @@
|
||||
package sugoi.form.elements;
|
||||
import sugoi.form.Form;
|
||||
import sugoi.form.FormElement;
|
||||
import sugoi.form.Formatter;
|
||||
import sugoi.form.elements.Flags;
|
||||
|
||||
class Enum extends FormElement<Int>
|
||||
{
|
||||
public var enumName:String;
|
||||
public var selectMessage:String;
|
||||
public var labelLeft:Bool;
|
||||
public var verticle:Bool;
|
||||
public var labelRight:Bool;
|
||||
var checked : Array<Bool>;
|
||||
|
||||
|
||||
public var columns:Int;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param label
|
||||
* @param data list of enums
|
||||
* @param value int (enum index)
|
||||
* @param ?verticle
|
||||
* @param ?labelRight
|
||||
*/
|
||||
public function new(name:String, label:String, enumName:String, value:Int, ?required=false, ?verticle:Bool=false, ?labelRight:Bool=true)
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.enumName = enumName;
|
||||
|
||||
this.verticle = verticle;
|
||||
this.labelRight = labelRight;
|
||||
|
||||
//trace("value = " + value);
|
||||
|
||||
if (required && value == null){
|
||||
this.value = /*Type.resolveEnum(enumName).createByIndex(0)*/0;
|
||||
}else{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
columns = 1;
|
||||
}
|
||||
|
||||
override function getTypedValue(str:String):Int {
|
||||
if (str == null) return null;
|
||||
|
||||
str = StringTools.trim(str);
|
||||
if (str == "") {
|
||||
return null;
|
||||
}else{
|
||||
return Std.parseInt(str);
|
||||
}
|
||||
}
|
||||
|
||||
override function getValue(){
|
||||
if (value == null) return null;
|
||||
return Type.resolveEnum(enumName).createByIndex(value);
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var s = "";
|
||||
var n = parentForm.name + "_" +name;
|
||||
|
||||
var tagCss = getClasses();
|
||||
//no label css otherwise the style col-sm-4 will be added, and we dont want that
|
||||
// as its for the left column labels
|
||||
//var labelCss = getLabelClasses();
|
||||
|
||||
var c = 0;
|
||||
|
||||
var array = Type.allEnums(Type.resolveEnum(enumName));
|
||||
|
||||
var rowsPerColumn = Math.ceil(array.length / columns);
|
||||
s = "<table style='margin-bottom:8px;'><tr>";
|
||||
for (i in 0...columns)
|
||||
{
|
||||
s += "<td valign=\"top\">\n";
|
||||
s += "<table>\n";
|
||||
|
||||
for (j in 0...rowsPerColumn)
|
||||
{
|
||||
if (c >= array.length) break;
|
||||
|
||||
s += "<tr>";
|
||||
|
||||
var row:Dynamic = array[c];
|
||||
var checked = value == Type.enumIndex(row);
|
||||
var checkbox = "<input type=\"radio\" class=\"" + tagCss + "\" name=\""+n+"\" id=\""+n+row+"\" value=\""+Type.enumIndex(row)+"\" " + (checked? "checked":"") +" ></input>\n";
|
||||
var label;
|
||||
|
||||
var t = Form.translator;
|
||||
if (t == null){
|
||||
label = "<label for=\"" + n + c + "\" >" + Std.string(row) +"</label>\n";
|
||||
}else{
|
||||
label = "<label for=\"" + n + c + "\" >" + t._(Std.string(row)) +"</label>\n";
|
||||
}
|
||||
|
||||
|
||||
if (labelRight)
|
||||
{
|
||||
s += "<td style='vertical-align:middle;padding-right: 8px;'>" + checkbox + "</td> \n";
|
||||
s += "<td style='vertical-align:middle;'>" + label + "</td>\n";
|
||||
} else {
|
||||
s += "<td style='vertical-align:middle;padding-right: 8px;'>" + label + "</td> \n";
|
||||
s += "<td style='vertical-align:middle;'>" + checkbox + "</td>\n";
|
||||
}
|
||||
|
||||
s += "</tr>";
|
||||
c++;
|
||||
}
|
||||
s += "</table>";
|
||||
s += "</td>";
|
||||
}
|
||||
s += "</tr></table>\n";
|
||||
|
||||
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package sugoi.form.elements;
|
||||
import haxe.crypto.Md5;
|
||||
import haxe.Timer;
|
||||
import sugoi.form.Form;
|
||||
import sys.io.File;
|
||||
|
||||
/**
|
||||
* Manage an <input type="file" /> element.
|
||||
*/
|
||||
class FileUpload extends FormElement<haxe.io.Bytes>
|
||||
{
|
||||
public var fileName: String;
|
||||
public var maxSize : Int; //Max file size in Mb
|
||||
|
||||
public function new(name:String, label:String, ?value:haxe.io.Bytes, ?required:Bool=false, toFolder:String=null, ?keepFullFileName:Bool=true )
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
this.required = required;
|
||||
fileName = null;
|
||||
maxSize = 6;
|
||||
}
|
||||
|
||||
override public function getTypedValue(s:String):haxe.io.Bytes
|
||||
{
|
||||
var request = sugoi.tools.Utils.getMultipart(1024 * 1024 * maxSize);
|
||||
|
||||
//trace(request.toString());
|
||||
|
||||
var strData = request.get(parentForm.name + "_" + name);
|
||||
fileName = request.get(parentForm.name + "_" + name+"_filename");
|
||||
|
||||
return new haxe.io.StringInput(strData).readAll();
|
||||
|
||||
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var n = parentForm.name + "_" +name;
|
||||
//var path = toFolder.substr((Sys.getCwd() + "tmp/").length);
|
||||
//var path = toFolder;
|
||||
|
||||
var str:String = "";
|
||||
|
||||
//str += '<span class="fileName">'+getOriginalFileName()+'</span><br/>';
|
||||
str += '<input type="file" name="' + n + '" id="' + n + '" ' + attributes + ' />';
|
||||
//if (!required && value != '' && value != null) str += '[ <a href="#" onclick="document.getElementById(\'' + n + '__delete\').value = \'1\'; return false;">remove</a> ]';
|
||||
//str += '<input type="hidden" name="' + n + '__previous" id="' + n + '__previous" value="'+value+'"/>';
|
||||
//str += '<input type="hidden" name="' + n + '__delete" id="' + n + '__delete" value="0"/>';
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains MD5 and original filename.
|
||||
*/
|
||||
//public function getFileName()
|
||||
//{
|
||||
//if (keepFullFileName)
|
||||
//{
|
||||
//var s = Std.string(value);
|
||||
//return s.substr(s.lastIndexOf("/") + 1);
|
||||
//} else {
|
||||
//return value;
|
||||
//}
|
||||
//}
|
||||
|
||||
/**
|
||||
* Orginal filename.
|
||||
*/
|
||||
//public function getOriginalFileName()
|
||||
//{
|
||||
//if (keepFullFileName)
|
||||
//{
|
||||
//var s = Std.string(value);
|
||||
//return s.substr(s.lastIndexOf("/") + 33);
|
||||
//} else {
|
||||
//return Std.string(value).substr(33);
|
||||
//}
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package sugoi.form.elements;
|
||||
import sugoi.form.Form;
|
||||
import sugoi.form.FormElement;
|
||||
import sugoi.form.Formatter;
|
||||
#if php
|
||||
import php.Web;
|
||||
#else
|
||||
import neko.Web;
|
||||
#end
|
||||
|
||||
|
||||
enum FakeFlag {
|
||||
Flag1;
|
||||
Flag2;
|
||||
Flag3;
|
||||
Flag4;
|
||||
Flag5;
|
||||
Flag6;
|
||||
Flag7;
|
||||
Flag8;
|
||||
Flag9;
|
||||
Flag10;
|
||||
Flag11;
|
||||
Flag12;
|
||||
Flag13;
|
||||
Flag14;
|
||||
Flag15;
|
||||
Flag16;
|
||||
Flag17;
|
||||
Flag18;
|
||||
Flag19;
|
||||
Flag20;
|
||||
Flag21;
|
||||
Flag22;
|
||||
Flag23;
|
||||
Flag24;
|
||||
Flag25;
|
||||
Flag26;
|
||||
Flag27;
|
||||
Flag28;
|
||||
Flag29;
|
||||
Flag30;
|
||||
Flag31;
|
||||
Flag32;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage flags stored in an Int , various flags are defined by an Enum
|
||||
*/
|
||||
class Flags<T> extends FormElement<Int>
|
||||
{
|
||||
public var data:Array<String>;
|
||||
public var selectMessage:String;
|
||||
public var labelLeft:Bool;
|
||||
public var verticle:Bool;
|
||||
public var labelRight:Bool;
|
||||
var checked : Array<Bool>;
|
||||
|
||||
public var columns:Int;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param label
|
||||
* @param data list of enums
|
||||
* @param value int
|
||||
* @param ?verticle
|
||||
* @param ?labelRight
|
||||
*/
|
||||
public function new(name:String, label:String, data:Array<String>, value:Int, ?verticle:Bool=true, ?labelRight:Bool=true)
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.data = data;
|
||||
this.value = value;
|
||||
this.verticle = verticle;
|
||||
this.labelRight = labelRight;
|
||||
if (value == null) value = 0;
|
||||
|
||||
checked = [];
|
||||
var i = 0;
|
||||
for( f in data) {
|
||||
checked.push( value & (1 << i) != 0 );
|
||||
i++;
|
||||
}
|
||||
|
||||
columns = 1;
|
||||
}
|
||||
|
||||
override public function populate()
|
||||
{
|
||||
|
||||
var v = Web.getParamValues(parentForm.name + "_" + name);
|
||||
value = 0;
|
||||
|
||||
if (v != null) {
|
||||
//App.log("flags populate : " + v );
|
||||
var val = new haxe.EnumFlags<FakeFlag>();
|
||||
//var i = 0;
|
||||
for (vv in v) {
|
||||
val.set( FakeFlag.createByIndex(Std.parseInt(vv)) );
|
||||
//i++;
|
||||
}
|
||||
|
||||
value = val.toInt();
|
||||
}
|
||||
|
||||
|
||||
//if (form.isSubmitted()){
|
||||
//value = (v != null) ? v : new Array();
|
||||
//} else {
|
||||
//if (v != null) value = v;
|
||||
//}
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var s = "";
|
||||
var n = parentForm.name + "_" +name;
|
||||
|
||||
var tagCss = getClasses();
|
||||
var labelCss = getLabelClasses();
|
||||
|
||||
var c = 0;
|
||||
var array = Lambda.array(data);
|
||||
if (array != null)
|
||||
{
|
||||
//trace("L" + array.length);
|
||||
var rowsPerColumn = Math.ceil(array.length / columns);
|
||||
s = "<table><tr>";
|
||||
for (i in 0...columns)
|
||||
{
|
||||
s += "<td valign=\"top\">\n";
|
||||
s += "<table>\n";
|
||||
|
||||
for (j in 0...rowsPerColumn)
|
||||
{
|
||||
if (c >= array.length) break;
|
||||
|
||||
s += "<tr>";
|
||||
|
||||
var row:Dynamic = array[c];
|
||||
|
||||
var checkbox = "<input type=\"checkbox\" class=\"" + tagCss + "\" name=\""+n+"[]\" id=\""+n+c+"\" value=\""+c+"\" " + (checked[c]? "checked":"") +" ></input>\n";
|
||||
var label;
|
||||
|
||||
var t = Form.translator;
|
||||
|
||||
label = "<label for=\"" + n + c + "\" class=\""+''/*labelCss*/+"\" > " + t._(row) +"</label>\n";
|
||||
|
||||
|
||||
if (labelRight)
|
||||
{
|
||||
s += "<td style='vertical-align:middle;'>" + checkbox + "</td>\n";
|
||||
s += "<td style='vertical-align:middle;'>" + label + "</td>\n";
|
||||
} else {
|
||||
s += "<td style='vertical-align:middle;'>" + label + "</td>\n";
|
||||
s += "<td style='vertical-align:middle;'>" + checkbox + "</td>\n";
|
||||
}
|
||||
s += "</tr>";
|
||||
|
||||
c++;
|
||||
}
|
||||
s += "</table>";
|
||||
s += "</td>";
|
||||
}
|
||||
s += "</tr></table>\n";
|
||||
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package sugoi.form.elements;
|
||||
import sugoi.form.filters.FloatFilter;
|
||||
|
||||
class FloatInput extends Input<Float>
|
||||
{
|
||||
|
||||
public function new(name, label, value, ?required=false){
|
||||
super(name, label, value, required);
|
||||
}
|
||||
|
||||
override public function getTypedValue(str:String):Float{
|
||||
|
||||
var f = new FloatFilter();
|
||||
var n = f.filterString(str);
|
||||
|
||||
if (n==null && this.required){
|
||||
return 0.0;
|
||||
}else{
|
||||
return n;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
/**
|
||||
* ...
|
||||
* @author fbarbut
|
||||
*/
|
||||
class FloatSelect extends Selectbox<Float>
|
||||
{
|
||||
|
||||
override function getTypedValue(str:String):Float{
|
||||
str = StringTools.trim(str);
|
||||
if (str == "" || str==null) {
|
||||
return null;
|
||||
}else{
|
||||
return Std.parseFloat(str);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
import sugoi.Web;
|
||||
import sugoi.form.FormElement;
|
||||
import sugoi.form.validators.Validator;
|
||||
import sugoi.form.ListData;
|
||||
|
||||
class HourDropDowns extends FormElement<Date>
|
||||
{
|
||||
var hourSelector:Selectbox<Int>;
|
||||
var minuteSelector:Selectbox<Int>;
|
||||
|
||||
public function new(name:String, label:String, ?_value:Date, ?required:Bool=false,?attributes="")
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
|
||||
if (_value == null) {
|
||||
value = Date.now();
|
||||
}else {
|
||||
value = _value;
|
||||
}
|
||||
|
||||
this.required = required;
|
||||
this.attributes = attributes;
|
||||
|
||||
var hours = 0;
|
||||
var minutes = 0;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
hours = value.getHours();
|
||||
minutes = value.getMinutes();
|
||||
}
|
||||
|
||||
var t = sugoi.form.Form.translator;
|
||||
|
||||
hourSelector = new IntSelect(name+"_hour", t._("hour"), ListData.getDateElement(0, 23), value.getHours(), true, "-", 'title="Hour"');
|
||||
minuteSelector = new IntSelect(name+"_minute", t._("minute"), ListData.getMinutes(), value.getMinutes(), true, "-", 'title="Minute"');
|
||||
|
||||
hourSelector.internal = minuteSelector.internal = true;
|
||||
|
||||
if (Form.USE_TWITTER_BOOTSTRAP) {
|
||||
minuteSelector.cssClass = "form-control";
|
||||
hourSelector.cssClass = "form-control";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
override public function init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
parentForm.addElement(hourSelector);
|
||||
parentForm.addElement(minuteSelector);
|
||||
}
|
||||
|
||||
override public function populate()
|
||||
{
|
||||
var hour = Std.parseInt(App.current.params.get(parentForm.name + "_" + hourSelector.name));
|
||||
var minute = Std.parseInt(App.current.params.get(parentForm.name + "_" + minuteSelector.name));
|
||||
var now = Date.now();
|
||||
value = (hour!= null && minute != null) ? new Date(now.getFullYear(),now.getMonth(), now.getDay(), hour, minute, 0) : null;
|
||||
}
|
||||
|
||||
override public function isValid():Bool
|
||||
{
|
||||
return super.isValid();
|
||||
}
|
||||
|
||||
override public function render():String{
|
||||
super.render();
|
||||
var s = "<span class='form-inline'>";
|
||||
if (value != null){
|
||||
try{
|
||||
var v:Date = cast value;
|
||||
hourSelector.value = v.getHours();
|
||||
minuteSelector.value = v.getMinutes();
|
||||
}catch(e:Dynamic){}
|
||||
}
|
||||
|
||||
s += hourSelector.render();
|
||||
s += " : ";
|
||||
s += minuteSelector.render();
|
||||
|
||||
return s+"</span>";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
/**
|
||||
* Use this to fill some custom HTML between form elements
|
||||
*
|
||||
* @author fbarbut<francois.barbut@gmail.com>
|
||||
*/
|
||||
class Html extends sugoi.form.FormElement<String>
|
||||
{
|
||||
var html : String;
|
||||
|
||||
public function new(name:String,html:String,?label="")
|
||||
{
|
||||
this.name = name;
|
||||
this.html = html;
|
||||
this.label = label;
|
||||
super();
|
||||
}
|
||||
|
||||
override public function render()
|
||||
{
|
||||
return html;
|
||||
}
|
||||
|
||||
override public function getTypedValue(str:String):String
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package sugoi.form.elements;
|
||||
import sugoi.form.Form;
|
||||
import sys.io.File;
|
||||
|
||||
/**
|
||||
* Manage an <input type="file" /> element for uploading images.
|
||||
*/
|
||||
class ImageUpload extends FormElement<haxe.io.Bytes>
|
||||
{
|
||||
public var fileName: String;
|
||||
public var maxSize : Int; // Max file size in Mb
|
||||
public var previewMaxSize : Int; // Image preview max size in pixels
|
||||
public var url : String;
|
||||
public var text : String;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param label
|
||||
* @param url file URL for previewing the image
|
||||
* @param required
|
||||
*/
|
||||
public function new(name:String, label:String, ?url:String, ?required:Bool=false )
|
||||
{
|
||||
super();
|
||||
|
||||
this.name = "upload_"+name;
|
||||
this.label = label;
|
||||
|
||||
this.url = url;
|
||||
this.required = required;
|
||||
fileName = null;
|
||||
maxSize = 6;
|
||||
previewMaxSize = 200;
|
||||
}
|
||||
|
||||
override public function getTypedValue(s:String):haxe.io.Bytes
|
||||
{
|
||||
var request = sugoi.tools.Utils.getMultipart(1024 * 1024 * maxSize);
|
||||
|
||||
var strData = request.get(parentForm.name + "_" + name + "_data");
|
||||
if (strData != null && strData != ""){
|
||||
fileName = request.get(parentForm.name + "_" + name + "_data_filename");
|
||||
return new haxe.io.StringInput(strData).readAll();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function hasDeleteAction():Bool{
|
||||
var n = parentForm.name + "_" +name;
|
||||
return (App.current.params.get(n + "_delete") == "1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an input + image preview + delete btn
|
||||
*/
|
||||
override public function render():String
|
||||
{
|
||||
var n = parentForm.name + "_" +name;
|
||||
var str = new StringBuf();
|
||||
str.add('<div class="imageUpload" style="position: relative;">');
|
||||
if (url!= null)str.add('<img id="' + n + '_preview" src="$url" class="img-thumbnail" style="max-width:'+previewMaxSize+'px;max-height:'+previewMaxSize+'px;float:right;">');
|
||||
str.add('<input class="btn btn-default" type="file" name="' + n + '_data" id="' + n + '" ' + attributes + ' />');
|
||||
if (text != null) str.add('<p>$text</p>');
|
||||
if (!required && url!= null){
|
||||
str.add('<a style="position:absolute;right:3px;top:3px;" href="#" class="btn btn-default btn-xs" onclick="document.getElementById(\'' + n + '_delete\').value = \'1\';document.getElementById(\'' + n + '_preview\').style.display=\'none\';this.style.display=\'none\';return false;">');
|
||||
str.add('<span class="glyphicon glyphicon-remove" alt="Remove"></span>');
|
||||
str.add('</a>');
|
||||
}
|
||||
str.add('<input type="hidden" name="' + n + '_delete" id="' + n + '_delete" value="0"/>');
|
||||
str.add('</div>');
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
import sugoi.form.Form;
|
||||
import sugoi.form.FormElement;
|
||||
import sugoi.form.validators.*;
|
||||
import sugoi.form.Formatter;
|
||||
|
||||
using StringTools;
|
||||
|
||||
enum InputType{
|
||||
ITText;
|
||||
ITPassword;
|
||||
ITHidden;
|
||||
ITColor; //http://caniuse.com/#feat=input-color
|
||||
}
|
||||
|
||||
class Input<T> extends FormElement<T>
|
||||
{
|
||||
public var password(get,set):Bool;
|
||||
public var disabled:Bool;
|
||||
public var showLabelAsDefaultValue:Bool;
|
||||
public var printRequired:Bool;
|
||||
|
||||
public var formatter:Formatter;
|
||||
public var inputType : InputType;
|
||||
|
||||
public function new(name:String, label:String, ?value:T, ?required=false, ?validators:Array<Validator<T>>, ?attributes="")
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
this.required = required;
|
||||
this.attributes = attributes;
|
||||
|
||||
if (validators != null)
|
||||
{
|
||||
for (i in validators)
|
||||
{
|
||||
this.validators.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
this.password = false;
|
||||
this.disabled = false;
|
||||
inputType = ITText;
|
||||
|
||||
printRequired = false;
|
||||
if(Form.USE_TWITTER_BOOTSTRAP) cssClass = "form-control";
|
||||
}
|
||||
|
||||
public function get_password(){
|
||||
return inputType == ITPassword;
|
||||
}
|
||||
|
||||
public function set_password(v:Bool){
|
||||
if (v){
|
||||
inputType = ITPassword;
|
||||
}else{
|
||||
inputType = ITText;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var n = parentForm.name + "_" +name;
|
||||
var tType = switch(inputType){
|
||||
case ITHidden: "hidden";
|
||||
case ITPassword : "password" ;
|
||||
case ITText : "text" ;
|
||||
case ITColor : "color";
|
||||
}
|
||||
|
||||
return "<input class=\""+ getClasses() +"\" type=\""+tType+"\" name=\""+n+"\" id=\""+n+"\" value=\"" +safeString(value)+ "\" "+attributes+" "+ (disabled?"disabled":"")+"/>" + ((required && parentForm.isSubmitted() && printRequired)?" required":"") ;
|
||||
}
|
||||
|
||||
override public function getTypedValue(str:String):T{
|
||||
|
||||
if (str == "" || str==null) {
|
||||
return null;
|
||||
}
|
||||
return cast StringTools.trim(str);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* render label + field
|
||||
*/
|
||||
override public function getFullRow():String {
|
||||
if (this.inputType == ITHidden){
|
||||
return this.render();
|
||||
}else{
|
||||
return super.getFullRow();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
|
||||
|
||||
class IntInput extends Input<Int>
|
||||
{
|
||||
|
||||
public function new(name, label, value, ?required=false){
|
||||
super(name, label, value, required);
|
||||
}
|
||||
|
||||
override public function getTypedValue(str:String):Int{
|
||||
if(str!=null) str = StringTools.trim(str);
|
||||
|
||||
if (str == "" || str==null) {
|
||||
|
||||
if (this.required){
|
||||
return 0;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
var v = Std.parseInt(str);
|
||||
|
||||
if (v == null){
|
||||
if (this.required){
|
||||
return 0;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}else{
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
/**
|
||||
* ...
|
||||
* @author fbarbut
|
||||
*/
|
||||
class IntSelect extends Selectbox<Int>
|
||||
{
|
||||
|
||||
override function getTypedValue(str:String):Int{
|
||||
|
||||
if (str != null) str = StringTools.trim(str);
|
||||
|
||||
if (str==null || str=="") {
|
||||
return null;
|
||||
}else{
|
||||
return Std.parseInt(str);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* ...
|
||||
* @author Tonypee
|
||||
*/
|
||||
|
||||
package form.elements;
|
||||
|
||||
typedef KeyVal = {
|
||||
var key:String;
|
||||
var value:Dynamic;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package form;
|
||||
|
||||
class Label
|
||||
{
|
||||
public var forElement:FormElement;
|
||||
public var value:String;
|
||||
|
||||
public function new()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function populate(data:String)
|
||||
{
|
||||
value = data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package sugoi.form.elements;
|
||||
import sugoi.form.Form;
|
||||
import sugoi.form.FormElement;
|
||||
|
||||
class RadioGroup extends FormElement<String>
|
||||
{
|
||||
public var data:ListData.FormData<String>;
|
||||
public var selectMessage:String;
|
||||
public var labelLeft:Bool;
|
||||
public var labelRight:Bool;
|
||||
public var vertical:Bool;
|
||||
|
||||
public function new(name:String, label:String, ?data:Array<{label:String,value:String}>, ?selected:String, ?defaultValue:String, ?vertical:Bool=true, ?labelRight:Bool=true,?required=false)
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.data = data != null ? data : [];
|
||||
this.value = selected != null ? selected : defaultValue;
|
||||
this.vertical = vertical;
|
||||
this.labelRight = labelRight;
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public function addOption(label:String, value:String)
|
||||
{
|
||||
data.push( { label:label, value:value } );
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var s = "";
|
||||
var n = parentForm.name + "_" +name;
|
||||
|
||||
var c = 0;
|
||||
if (data != null)
|
||||
{
|
||||
for (row in data)
|
||||
{
|
||||
var vClass = vertical ? " radioItemVertical" : " radioItemHorizontal";
|
||||
s += '<div class="radioItem'+vClass+'">';
|
||||
var radio = "<input type=\"radio\" name=\""+n+"\" id=\""+n+c+"\" value=\"" + row.value + "\" " + (row.value == Std.string(value) ? "checked":"") +" />\n";
|
||||
var label = "<label for=\"" + n+c + "\" >" + row.label +"</label>";
|
||||
|
||||
s += labelRight ? radio + " "+label+" ": label+" "+radio+" ";
|
||||
s += '</div>';
|
||||
//if (verticle) s += "<br />";
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
override function getTypedValue(str:String){
|
||||
if(str==null) return null;
|
||||
str = StringTools.trim(str);
|
||||
return (str == "") ? return null : str;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
import sugoi.form.Form;
|
||||
import sugoi.form.FormElement;
|
||||
|
||||
class Readonly<T> extends FormElement<T>
|
||||
{
|
||||
public var display:Bool;
|
||||
|
||||
public function new(name:String, label:String, ?value:T, ?required:Bool = false, ?display:Bool = false, ?attributes:String = "")
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
this.required = required;
|
||||
this.display = display;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var n = parentForm.name + "_" + name;
|
||||
|
||||
var str:StringBuf = new StringBuf();
|
||||
|
||||
str.add("<input type=\"hidden\" name=\"" + n + "\" id=\"" + n + "\" value=\"" +value + "\"/>");
|
||||
if (display) {
|
||||
str.add(value);
|
||||
}
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
override public function getTypedValue(str:String):T
|
||||
{
|
||||
if (str == "" || str==null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return cast StringTools.trim(str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package form.elements;
|
||||
/*
|
||||
* TinyMCE rich text editor
|
||||
*
|
||||
*/
|
||||
|
||||
import form.Form;
|
||||
import form.FormElement;
|
||||
|
||||
class Richtext extends FormElement
|
||||
{
|
||||
public var width:Float;
|
||||
public var height:Float;
|
||||
public var content_css:String;
|
||||
public var mode:RichtextMode;
|
||||
|
||||
public function new(name:String, label:String, ?value:String, ?required:Bool=false, ?attibutes:String="")
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
this.required = required;
|
||||
this.attributes = attibutes;
|
||||
|
||||
width = 300;
|
||||
height = 300;
|
||||
content_css = "css/cms/richtext_default.css";
|
||||
|
||||
mode = RichtextMode.SIMPLE;
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var n = form.name + "_" +name;
|
||||
|
||||
if(content_css != "") content_css += "?" + Date.now().getTime();
|
||||
|
||||
var str:StringBuf = new StringBuf();
|
||||
str.add("\n <textarea name=\"" + n + "\" id=\"" + n + "\" >"+value+"</textarea>");
|
||||
str.add("\n <script> ");
|
||||
str.add("\n tinyMCE.init({ ");
|
||||
str.add("\n mode : \"exact\", ");
|
||||
str.add("\n elements : \""+n+"\", ");
|
||||
|
||||
str.add("\n theme : \""+(mode == RichtextMode.SIMPLE ? "simple" : "advanced")+"\", ");
|
||||
|
||||
str.add("\n width : \""+width+"\", ");
|
||||
str.add("\n height : \""+height+"\", ");
|
||||
str.add("\n content_css : \"" + content_css + "\", ");
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case SIMPLE:
|
||||
case FORMAT:
|
||||
str.add("\n plugins : \"advlink,inlinepopups,paste\", ");
|
||||
str.add("\n theme_advanced_buttons1 : \"bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,|,link,unlink,|,pastetext,cleanup,removeformat\", ");
|
||||
str.add("\n theme_advanced_buttons2 : \"\", ");
|
||||
str.add("\n theme_advanced_toolbar_location : \"top\", ");
|
||||
str.add("\n theme_advanced_statusbar_location : \"bottom\", ");
|
||||
str.add("\n theme_advanced_resizing : true, ");
|
||||
case SIMPLE_TABLES:
|
||||
str.add("\n plugins : \"table,advlink,inlinepopups,paste\", ");
|
||||
str.add("\n theme_advanced_buttons1 : \"bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,|,link,unlink,|,pastetext,cleanup,removeformat\", ");
|
||||
str.add("\n theme_advanced_buttons2 : \"table,tablecontrols\", ");
|
||||
str.add("\n theme_advanced_buttons3 : \"\", ");
|
||||
|
||||
str.add("\n theme_advanced_toolbar_location : \"top\", ");
|
||||
str.add("\n theme_advanced_statusbar_location : \"bottom\", ");
|
||||
str.add("\n theme_advanced_resizing : true, ");
|
||||
case ADVANCED:
|
||||
str.add("\n theme_advanced_styles: \"Small 1=small1\", ");
|
||||
str.add("\n plugins : \"safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template\", ");
|
||||
str.add("\n theme_advanced_buttons1 : \"bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect,|,forecolor\", ");
|
||||
str.add("\n theme_advanced_buttons2 : \"cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code\", ");
|
||||
str.add("\n theme_advanced_buttons3 : \"tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen\", ");
|
||||
str.add("\n theme_advanced_buttons4 : \"insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak\", ");
|
||||
str.add("\n theme_advanced_toolbar_location : \"top\", ");
|
||||
str.add("\n theme_advanced_toolbar_align : \"left\", ");
|
||||
str.add("\n theme_advanced_statusbar_location : \"bottom\", ");
|
||||
str.add("\n theme_advanced_resizing : false, ");
|
||||
}
|
||||
str.add("\n file_browser_callback : 'myFileBrowser', ");
|
||||
|
||||
str.add("\n }); ");
|
||||
str.add("\n </script>\n ");
|
||||
|
||||
if (!isValid()) str.add(" required");
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
public function toString() :String
|
||||
{
|
||||
return render();
|
||||
}
|
||||
}
|
||||
|
||||
enum RichtextMode
|
||||
{
|
||||
SIMPLE;
|
||||
FORMAT;
|
||||
SIMPLE_TABLES;
|
||||
ADVANCED;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* WYMEditor ( XHTML wysiwig editor )
|
||||
* http://files.wymeditor.org/wymeditor-1.0.0b2/examples/
|
||||
*/
|
||||
package form.elements;
|
||||
|
||||
import form.Form;
|
||||
import form.FormElement;
|
||||
|
||||
class RichtextWym extends FormElement
|
||||
{
|
||||
public var width:Float;
|
||||
public var height:Float;
|
||||
public var allowImages:Bool;
|
||||
public var allowTables:Bool;
|
||||
public var editorStyles:String;
|
||||
public var containersItems:String;
|
||||
public var classesItems:String;
|
||||
|
||||
public function new(name:String, label:String, ?value:String, ?required:Bool=false, ?attibutes:String="")
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
this.required = required;
|
||||
this.attributes = attibutes;
|
||||
|
||||
width = 500;
|
||||
height = 300;
|
||||
|
||||
allowImages = true;
|
||||
allowTables = false;
|
||||
editorStyles = "";
|
||||
containersItems = "";
|
||||
classesItems = "";
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var n = form.name + "_" +name;
|
||||
|
||||
editorStyles = StringTools.replace(editorStyles, "\n", " ");
|
||||
editorStyles = StringTools.replace(editorStyles, "\r", " ");
|
||||
|
||||
var str:StringBuf = new StringBuf();
|
||||
str.add("\n <textarea name=\"" + n + "\" id=\"" + n + "\" >" + value + "</textarea>");
|
||||
str.add("<script type=\"text/javascript\">");
|
||||
str.add("jQuery(function() {");
|
||||
str.add(" jQuery('#" + n + "').wymeditor({");
|
||||
str.add("logoHtml: '',");
|
||||
//str.add(" stylesheet: './css/site.css',");
|
||||
str.add("editorStyles: [\""+editorStyles+"\"],");
|
||||
str.add("postInit: function(wym) {");
|
||||
str.add(" jQuery(wym._box).find(wym._options.containersSelector).removeClass('wym_dropdown').addClass('wym_panel').find('h2 > span').remove();");
|
||||
str.add(" jQuery(wym._box).find(wym._options.iframeSelector).css('height', '"+height+"px').css('width', '"+width+"px');");
|
||||
str.add("},");
|
||||
str.add("toolsItems: [");
|
||||
str.add(" {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, ");
|
||||
str.add(" {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},");
|
||||
str.add(" {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},");
|
||||
str.add(" {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},");
|
||||
if(allowImages) str.add("{'name': 'InsertImage', 'title': 'Image', 'css': 'wym_tools_image'},");
|
||||
str.add(" {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},");
|
||||
str.add(" {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},");
|
||||
if(allowTables) str.add("{'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},");
|
||||
str.add(" {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},");
|
||||
str.add(" {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},");
|
||||
str.add(" {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},");
|
||||
str.add(" {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'}");
|
||||
str.add("],");
|
||||
str.add("containersItems: [" + containersItems + "],");
|
||||
if (classesItems != "") {
|
||||
str.add("classesItems: [" + classesItems + "],");
|
||||
}else {
|
||||
str.add("classesHtml: '',");
|
||||
}
|
||||
str.add("postInitDialog: function (wym, wdw) { if(wymeditor_filebrowser != null) wymeditor_filebrowser(wym, wdw); }");
|
||||
str.add(" });");
|
||||
str.add("});");
|
||||
str.add("</script>");
|
||||
|
||||
if (!isValid()) str.add(" required");
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
public function toString() :String
|
||||
{
|
||||
return render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package sugoi.form.elements;
|
||||
import sugoi.form.Form;
|
||||
import sugoi.form.FormElement;
|
||||
|
||||
class Selectbox<T> extends FormElement<T>
|
||||
{
|
||||
public var data:Array<{label:String,value:T}>;
|
||||
public var nullMessage:String;
|
||||
public var onChange:String;
|
||||
public var size:Int;
|
||||
public var multiple:Bool;
|
||||
|
||||
public function new(name:String, label:String, ?data:Array<{label:String,value:T}>, ?selected:T, required:Bool=false, ?nullMessage="-", ?attributes="")
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.data = data != null ? data: new Array();
|
||||
this.value = selected;
|
||||
this.required = required;
|
||||
this.nullMessage = nullMessage;
|
||||
this.attributes = attributes;
|
||||
size = 1;
|
||||
multiple = false;
|
||||
onChange = "";
|
||||
if(Form.USE_TWITTER_BOOTSTRAP) cssClass = "form-control";
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var s = "";
|
||||
var n = parentForm.name;
|
||||
n += "_" +name;
|
||||
|
||||
s += '\n<select name="' + n + '" id="' + n + '" '+attributes+' class="'+ getClasses() +'" onChange="'+onChange+'" size="'+size+'" '+(multiple ? "multiple" : "")+'/>';
|
||||
|
||||
if (nullMessage != "")
|
||||
s += "<option value=\"\" " + (Std.string(value) == "" ? "selected":"") + ">" + nullMessage + "</option>";
|
||||
|
||||
if (data != null){
|
||||
for (row in data) {
|
||||
s += "<option value=\"" + Std.string(row.value) + "\" " + (Std.string(row.value) == Std.string(value) ? "selected":"") + ">" + Std.string(row.label) + "</option>";
|
||||
}
|
||||
}
|
||||
s += "</select>";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
|
||||
|
||||
class StringInput extends Input<String>
|
||||
{
|
||||
|
||||
override public function getTypedValue(str:String):String{
|
||||
|
||||
if (str != null)
|
||||
str = StringTools.trim(str);
|
||||
|
||||
if (str == "" || str==null) {
|
||||
return null;
|
||||
}else{
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package sugoi.form.elements;
|
||||
|
||||
/**
|
||||
* ...
|
||||
* @author fbarbut
|
||||
*/
|
||||
class StringSelect extends Selectbox<String>
|
||||
{
|
||||
|
||||
override function getTypedValue(str:String){
|
||||
str = StringTools.trim(str);
|
||||
if (str == "" || str==null) {
|
||||
return null;
|
||||
}else{
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package sugoi.form.elements;
|
||||
import sugoi.form.Form;
|
||||
import sugoi.form.FormElement;
|
||||
|
||||
|
||||
class Submit extends FormElement<String>
|
||||
{
|
||||
public function new(name:String, value:String)
|
||||
{
|
||||
super();
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
|
||||
}
|
||||
|
||||
override public function isValid():Bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
override public function render() :String
|
||||
{
|
||||
if (Form.USE_TWITTER_BOOTSTRAP) cssClass = "btn btn-primary";
|
||||
|
||||
var s = "<input type=\"submit\" class=\"" + getClasses() +"\" value=\"" + value + "\" " + attributes + " name=\"" +parentForm.name + "_" +name + "\" id=\"" +parentForm.name + "_" +name + "\" />";
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
override public function getFullRow():String
|
||||
{
|
||||
return "<div class='col-sm-4'></div><div class='col-sm-8'>" + this.render() + "</div>";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
package sugoi.form.elements;
|
||||
|
||||
import sugoi.form.elements.Input;
|
||||
import sugoi.form.Form;
|
||||
import sugoi.form.validators.*;
|
||||
|
||||
class TextArea extends StringInput
|
||||
{
|
||||
public var height:Int;
|
||||
|
||||
public function new(name:String, label:String, ?value:String, ?required:Bool=false, ?validators:Array<Validator<String>>, ?attributes:String)
|
||||
{
|
||||
super(name, label, value, required, validators, attributes);
|
||||
|
||||
}
|
||||
|
||||
override public function render():String
|
||||
{
|
||||
var n = parentForm.name + "_" +name;
|
||||
|
||||
//if (showLabelAsDefaultValue && value == label){
|
||||
//addValidator(new BoolValidator(false, "Not valid"));
|
||||
//}
|
||||
|
||||
if ((value == null || value == "") && showLabelAsDefaultValue) {
|
||||
value = label;
|
||||
}
|
||||
|
||||
var s = "";
|
||||
if (required && parentForm.isSubmitted() && printRequired) s += "required<br />";
|
||||
|
||||
s += "<textarea class=\""+ getClasses() +"\" name=\"" + n + "\" id=\"" + n + "\" " + attributes + " >" + safeString(value) + "</textarea>";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user