JJ
Utilizando o Plugin JQuery imgAreaSelect no Adianti
Fechado
No livro na página 182 na subseção 4.9.1 existe um exemplo da Integração do Adianti com o JQuery. Existe até um exemplo no Tutor app/control/Presentation/WebSpecific/JqueryGalleryView.class.php.
No entanto, tentei integra o exemplo de seleção de imagens fornecido pelo site odyniec.net/projects/imgareaselect/ sem sucesso.
Segue meu código
*/
class QuadraForm extends TPage
{
protected $form; // form
/**
* Form constructor
* @param $param Request
*/
public function __construct( $param )
{
parent::__construct();
// creates the form
$this->form = new TQuickForm('form_Quadra');
$this->form->class = 'tform'; // change CSS class
$this->form->style = 'display: table;width:100%'; // change style
// define the form title
$this->form->setFormTitle(_t('Block'));
// create the form fields
2350 = new TEntry('id');
$numero = new TEntry('numero');
2350_unidade = new TDBCombo('id_unidade','sgu','Unidade', 'id','nome' );
2350->setEditable(false);
$numero->setMask('9!');
// add the fields
$this->form->addQuickField('ID', 2350, 100 );
$this->form->addQuickField(_t('Number'), $numero, 100 , new TRequiredValidator);
$this->form->addQuickField(_t('Unit'), 2350_unidade, 200 , new TRequiredValidator);
if (!empty(2350))
{
2350->setEditable(FALSE);
}
// carrega o arquivo javascript e css da biblioteca
TPage::include_css('app/lib/imgareaselect/css/imgareaselect-default.css');
// TPage::include_js('app/lib/imgareaselect/scripts/jquery.min.js');
TPage::include_js('app/lib/imgareaselect/scripts/jquery.imgareaselect.pack.js');
$this->frame = new TElement('div');
$this->frame->id = 'photo_frame';
$this->frame->style = 'width:800px;height:auto;min-height:400px;border:1px solid gray;padding:4px;';
$row = $this->form->addRow();
$row->addCell('');
$row->addCell($this->frame);
//$image = new TImage('app/resources/plantaII.jpg');
//$image->style = 'width: 100%';
//$image->id = 'photo';
$image = new TElement('img');
$image->src = 'app/resources/plantaII.jpg';
$image->id = 'photo';
$image->style = 'width: 100%';
$this->frame->add( $image );
$script = new TElement('script');
$script->type = 'text/javascript';
$script->add('
$(document).ready(function () {
$("img#photo").imgAreaSelect({
handles: true,
onSelectEnd: someFunction
});
});
');
/** samples
$this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
$fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
$fieldX->setSize( 100, 40 ); // set size
**/
// create the form actions
$this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
$this->form->addQuickAction(_t('New'), new TAction(array($this, 'onClear')), 'bs:plus-sign green');
$this->form->addQuickAction(_t('Back to the listing'), new TAction(array('QuadraList','onReload')), 'fa:table blue');
// vertical box container
$container = new TVBox;
$container->style = 'width: 90%';
$menu_file_name = AdiantiMenuBuilder::get_file_menu() ? AdiantiMenuBuilder::get_file_menu() : 'menu_pt.xml';
$container->add(new TXMLBreadCrumb($menu_file_name, 'QuadraList'));
$container->add($this->form);
parent::add($container);
}
No entanto, tentei integra o exemplo de seleção de imagens fornecido pelo site odyniec.net/projects/imgareaselect/ sem sucesso.
Segue meu código
*/
class QuadraForm extends TPage
{
protected $form; // form
/**
* Form constructor
* @param $param Request
*/
public function __construct( $param )
{
parent::__construct();
// creates the form
$this->form = new TQuickForm('form_Quadra');
$this->form->class = 'tform'; // change CSS class
$this->form->style = 'display: table;width:100%'; // change style
// define the form title
$this->form->setFormTitle(_t('Block'));
// create the form fields
2350 = new TEntry('id');
$numero = new TEntry('numero');
2350_unidade = new TDBCombo('id_unidade','sgu','Unidade', 'id','nome' );
2350->setEditable(false);
$numero->setMask('9!');
// add the fields
$this->form->addQuickField('ID', 2350, 100 );
$this->form->addQuickField(_t('Number'), $numero, 100 , new TRequiredValidator);
$this->form->addQuickField(_t('Unit'), 2350_unidade, 200 , new TRequiredValidator);
if (!empty(2350))
{
2350->setEditable(FALSE);
}
// carrega o arquivo javascript e css da biblioteca
TPage::include_css('app/lib/imgareaselect/css/imgareaselect-default.css');
// TPage::include_js('app/lib/imgareaselect/scripts/jquery.min.js');
TPage::include_js('app/lib/imgareaselect/scripts/jquery.imgareaselect.pack.js');
$this->frame = new TElement('div');
$this->frame->id = 'photo_frame';
$this->frame->style = 'width:800px;height:auto;min-height:400px;border:1px solid gray;padding:4px;';
$row = $this->form->addRow();
$row->addCell('');
$row->addCell($this->frame);
//$image = new TImage('app/resources/plantaII.jpg');
//$image->style = 'width: 100%';
//$image->id = 'photo';
$image = new TElement('img');
$image->src = 'app/resources/plantaII.jpg';
$image->id = 'photo';
$image->style = 'width: 100%';
$this->frame->add( $image );
$script = new TElement('script');
$script->type = 'text/javascript';
$script->add('
$(document).ready(function () {
$("img#photo").imgAreaSelect({
handles: true,
onSelectEnd: someFunction
});
});
');
/** samples
$this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
$fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
$fieldX->setSize( 100, 40 ); // set size
**/
// create the form actions
$this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
$this->form->addQuickAction(_t('New'), new TAction(array($this, 'onClear')), 'bs:plus-sign green');
$this->form->addQuickAction(_t('Back to the listing'), new TAction(array('QuadraList','onReload')), 'fa:table blue');
// vertical box container
$container = new TVBox;
$container->style = 'width: 90%';
$menu_file_name = AdiantiMenuBuilder::get_file_menu() ? AdiantiMenuBuilder::get_file_menu() : 'menu_pt.xml';
$container->add(new TXMLBreadCrumb($menu_file_name, 'QuadraList'));
$container->add($this->form);
parent::add($container);
}
resolvido pessoal:
Solução:
// carrega o arquivo javascript e css da biblioteca
TPage::include_css('app/lib/imgareaselect/css/imgareaselect-default.css');
TPage::include_js('app/lib/imgareaselect/scripts/jquery.imgareaselect.min.js');
TPage::include_js('app/lib/imgareaselect/scripts/quadra.js');
$this->frame = new TElement('div');
$this->frame->id = 'frame';
$this->frame->style = 'margin: 0 0.3em; width: 300px; height: 300px;';
$row = $this->form->addRow();
$row->addCell('');
$row->addCell($this->frame);
$image = new TElement('img');
$image->src = 'app/resources/plantaII_mini.jpg';
$image->id = 'photo';
$image->style = '';
$this->frame->add( $image );
Sendo que o conteúdo do arquivo quadra.js
function preview(img, selection) {
if (!selection.width || !selection.height)
return;
var scaleX = 100 / selection.width;
var scaleY = 100 / selection.height;
$('#preview img').css({
width: Math.round(scaleX * 800),
height: Math.round(scaleY * 600),
marginLeft: -Math.round(scaleX * selection.x1),
marginTop: -Math.round(scaleY * selection.y1)
});
$('#x1').val(selection.x1);
$('#y1').val(selection.y1);
$('#x2').val(selection.x2);
$('#y2').val(selection.y2);
$('#w').val(selection.width);
$('#h').val(selection.height);
}
$(function () {
$('#photo').imgAreaSelect({ aspectRatio: '1:1', handles: true,
fadeSpeed: 200, onSelectChange: preview });
});