Added new fields and forms

This commit is contained in:
Antonio de la Rosa 2015-08-28 23:43:08 +02:00
parent 52d75b8029
commit 9db16a5edd
27 changed files with 832 additions and 34 deletions

View file

@ -38,6 +38,33 @@ class BaseForm {
}
/**
* Static method where is registered the js necessary for a field
*/
static public function js()
{
}
/**
* Static method where is registered the js necessary for a field
*/
static public function css()
{
}
/**
* Static method where is registered the js necessary for a field
*/
static public function header()
{
}
/**
* Method for escape value for html input
*/

View file

@ -0,0 +1,22 @@
<?php
namespace PhangoApp\PhaModels\Forms;
use PhangoApp\PhaModels\CoreFields\DateTimeField;
class DateTimeForm {
public $set_time=1;
function form()
{
$timestamp=DateTimeField::obtain_timestamp_datefield($value);
// return '<input type="'.$this->type.'" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($this->default_value).'">';
return DateForm($this->name, $class, $this->default_value, $this->set_time);
}
}
?>

211
src/Forms/MultiLangForm.php Normal file
View file

@ -0,0 +1,211 @@
<?php
namespace PhangoApp\PhaModels\Forms;
use PhangoApp\PhaI18n\I18n;
use PhangoApp\PhaUtils\Utils;
use PhangoApp\PhaModels\Forms\BaseForm;
use PhangoApp\PhaView\View;
class MultiLangForm extends BaseForm{
public $type_form='PhangoApp\PhaModels\Forms\BaseForm';
public function form()
{
//make a foreach with all langs
//default, es_ES, en_US, show default if no exists translation for selected language.
foreach(I18n::$arr_i18n as $lang_select)
{
/* $arr_selected[Utils::slugify($lang_select)]='hidden_form';
$arr_selected[Utils::slugify(I18n::$language)]='no_hidden_form';*/
/*settype($arr_values[$lang_select], 'string');
echo '<div class="'.$arr_selected[Utils::slugify($lang_select)].'" id="'.$this->name.'_'.$lang_select.'">';
echo $this->type_form($this->name.'['.$lang_select.']', '', $arr_values[$lang_select]);
echo '</div>';*/
}
?>
<div id="languages">
<?php
$arr_selected=array();
foreach(I18n::$arr_i18n as $lang_item)
{
//set
$arr_selected[Utils::slugify($lang_item)]='no_choose_flag';
$arr_selected[Utils::slugify(I18n::$language)]='choose_flag';
?>
<a class="<?php echo $arr_selected[Utils::slugify($lang_item)]; ?>" id="<?php echo $this->name.'_'.$lang_item; ?>_flag" href="#" onclick="change_form_language_<?php echo $this->name; ?>('<?php echo $this->name; ?>', '<?php echo $this->name.'_'.$lang_item; ?>'); return false;"><img src="<?php echo View::get_media_url('images/languages/'.$lang_item.'.png'); ?>" alt="<?php echo $lang_item; ?>"/></a>&nbsp;
<?php
}
?>
</div>
<hr />
<script language="Javascript">
function change_form_language_<?php echo $this->name; ?>(field, lang_field)
{
if(typeof jQuery == 'undefined')
{
alert('<?php echo I18n::lang('common', 'cannot_load_jquery', 'Cannot load jquery'); ?>');
return false;
}
<?php
foreach(I18n::$arr_i18n as $lang_item)
{
?>
$("#<?php echo $this->name.'_'.$lang_item; ?>").hide();//removeClass("no_hidden_form").addClass("hidden_form");
$("#<?php echo $this->name.'_'.$lang_item; ?>_flag").removeClass("choose_flag").addClass("no_choose_flag");
<?php
}
?>
lang_field=lang_field.replace('[', '\\[');
lang_field=lang_field.replace(']', '\\]');
$("#"+lang_field).show();//.removeClass("hidden_form").addClass("no_hidden_form");
$("#"+lang_field+'_flag').removeClass("no_choose_flag").addClass("choose_flag");
}
</script>
<?php
/*
ob_start();
if(gettype($arr_values)!='array')
{
$arr_values = @unserialize( $arr_values );
if(gettype($arr_values)!='array')
{
$arr_values=array();
}
}
foreach(I18n::$arr_i18n as $lang_select)
{
$arr_selected[Utils::slugify($lang_select)]='hidden_form';
$arr_selected[Utils::slugify(I18n::$language)]='no_hidden_form';
settype($arr_values[$lang_select], 'string');
echo '<div class="'.$arr_selected[Utils::slugify($lang_select)].'" id="'.$this->name.'_'.$lang_select.'">';
echo $this->type_form($this->name.'['.$lang_select.']', '', $arr_values[$lang_select]);
echo '</div>';
}
?>
<div id="languages">
<?php
$arr_selected=array();
foreach(PhangoVar::$arr_i18n as $lang_item)
{
//set
$arr_selected[Utils::slugify($lang_item)]='no_choose_flag';
$arr_selected[Utils::slugify(I18n::$language)]='choose_flag';
?>
<a class="<?php echo $arr_selected[Utils::slugify($lang_item)]; ?>" id="<?php echo $this->name.'_'.$lang_item; ?>_flag" href="#" onclick="change_form_language_<?php echo $this->name; ?>('<?php echo $this->name; ?>', '<?php echo $this->name.'_'.$lang_item; ?>'); return false;"><img src="<?php echo get_url_image('languages/'.$lang_item.'.png'); ?>" alt="<?php echo $lang_item; ?>"/></a>&nbsp;
<?php
}
?>
</div>
<hr />
<script language="Javascript">
function change_form_language_<?php echo $this->name; ?>(field, lang_field)
{
if(typeof jQuery == 'undefined')
{
alert('<?php echo PhangoVar::$lang['common']['cannot_load_jquery']; ?>');
return false;
}
<?php
foreach(PhangoVar::$arr_i18n as $lang_item)
{
?>
$("#<?php echo $this->name.'_'.$lang_item; ?>").hide();//removeClass("no_hidden_form").addClass("hidden_form");
$("#<?php echo $this->name.'_'.$lang_item; ?>_flag").removeClass("choose_flag").addClass("no_choose_flag");
<?php
}
?>
lang_field=lang_field.replace('[', '\\[');
lang_field=lang_field.replace(']', '\\]');
$("#"+lang_field).show();//.removeClass("hidden_form").addClass("no_hidden_form");
$("#"+lang_field+'_flag').removeClass("no_choose_flag").addClass("choose_flag");
}
</script>
<?php
$text_form=ob_get_contents();
ob_end_clean();
return $text_form;
*/
}
function setform($value)
{
if(!gettype($value)=='array')
{
settype($arr_value, 'array');
$arr_value = @unserialize( $value );
return $arr_value;
}
else
{
return $value;
}
}
}
?>

View file

@ -0,0 +1,80 @@
<?php
namespace PhangoApp\PhaModels\Forms;
use PhangoApp\PhaModels\Forms\BaseForm;
use PhangoApp\PhaUtils\Utils;
use PhangoApp\PhaView\View;
use PhangoApp\PhaRouter\Routes;
use PhangoApp\PhaI18n\I18n;
class TextAreaEditor extends BaseForm {
public function form()
{
//PhangoVar::$arr_cache_jscript[]='tinymce_path.js';
if(!isset(View::$header['tinymce']))
{
View::$js[]='jquery.min.js';
View::$js[]='tinymce/tinymce.min.js';
$this->name=Utils::slugify($this->name);
ob_start();
?>
<script type="text/javascript">
$(document).ready( function () {
tinymce.init({
selector: "textarea.tinymce_editor",
//theme: "modern",
height: 300,
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"table contextmenu directionality emoticons template paste textcolor"
],
file_browser_callback: function(field_name, url, type, win){
var filebrowser = "<?php echo Routes::make_module_url('gallery', 'index'); ?>";
tinymce.activeEditor.windowManager.open({
title : "<?php echo I18n::lang('common', 'load_file', 'Load_image'); ?>",
width : 520,
height : 400,
url : filebrowser
}, {
window : win,
input : field_name
});
return false;
}
});
});
</script>
<?php
View::$header['tinymce']=ob_get_contents();
ob_end_clean();
}
?>
<p><textarea class="tinymce_editor" name="<?php echo $this->name; ?>"><?php echo $this->default_value; ?></textarea></p>
<?php
}
}
?>