Slider Vertical Olá, Tenho uma tarefa para uma entrevista de emprego que gostaria de desenvolver usando o framework. Todavia é solicitado que o formulário tenha vários campos do tipo slider verticais, tal como (https://jqueryui.com/slider/#multiple-vertical), porém no framework, até onde vi, só tem slide horizontal. Gostaria muito se alguém pudesse indicar o melhor caminho a seguir nesse caso. Abs...
FC
Slider Vertical  
Fechado
Olá,

Tenho uma tarefa para uma entrevista de emprego que gostaria de desenvolver usando o framework.
Todavia é solicitado que o formulário tenha vários campos do tipo slider verticais, tal como (https://jqueryui.com/slider/#multiple-vertical), porém no framework, até onde vi, só tem slide horizontal.
Gostaria muito se alguém pudesse indicar o melhor caminho a seguir nesse caso.

Abs,

Felipe

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (3)


FC

Olá Xará o primeiro salário será meu. ou como fazemos aqui no serviço vai perder o ticket rsrss

Essa alteração exige um pouco de conhecimento em JavaScript porém como o Framework é fantástico fica fácil fazer modificações lembrando que a solução que te passarei deveria seguir algumas regras de extensibilidade porém como há a necessidade de modificar o Java Script quando tiver atualização do core irá precisar rever.


Será necessário alterar a classe TSlider e o arquivo Java Sript components.min.js

Arquivo components.min.js JavaScript troque essa função note que acrescentei uma variável
function tslider_start(a, b, c, d, e, f) { $(function() { $(a + "_div").slider({ orientation: f, value: b, min: c, max: d, step: e, slide: function(b, c) { $(a).val(c.value) } }) }) }


Ok na Classe TSlider ficará assim
 
  1. <?php
  2. Namespace Adianti\\Widget\\Form;
  3. use Adianti\\Widget\\Form\\AdiantiWidgetInterface;
  4. use Adianti\\Widget\\Base\\TElement;
  5. use Adianti\\Widget\\Base\\TScript;
  6. use Adianti\\Widget\\Form\\TField;
  7. /**
  8. * Slider Widget
  9. *
  10. * @version 2.0
  11. * @package widget
  12. * @subpackage form
  13. * @author Pablo Dall'Oglio
  14. * @copyright Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  15. * @license http://www.adianti.com.br/framework-license
  16. */
  17. class TSlider extends TField implements AdiantiWidgetInterface
  18. {
  19. protected $id;
  20. private $min;
  21. private $max;
  22. private $step;
  23. private $direction;
  24. /**
  25. * Class Constructor
  26. * @param $name Name of the widget
  27. */
  28. public function __construct($name)
  29. {
  30. parent::__construct($name);
  31. $this->id = 'tslider_'.uniqid();
  32. }
  33. /**
  34. * Define the field's range
  35. * @param $min Minimal value
  36. * @param $max Maximal value
  37. * @param $step Step value
  38. */
  39. public function setRange($min, $max, $step, $direction)
  40. {
  41. $this->min = $min;
  42. $this->max = $max;
  43. $this->step = $step;
  44. $this->value = $min;
  45. $this->direction = '"'.$direction.'"';
  46. }
  47. /**
  48. * Enable the field
  49. * @param $form_name Form name
  50. * @param $field Field name
  51. */
  52. public static function enableField($form_name, $field)
  53. {
  54. TScript::create( " tslider_enable_field('{$form_name}', '{$field}'); " );
  55. }
  56. /**
  57. * Disable the field
  58. * @param $form_name Form name
  59. * @param $field Field name
  60. */
  61. public static function disableField($form_name, $field)
  62. {
  63. TScript::create( " tslider_disable_field('{$form_name}', '{$field}'); " );
  64. }
  65. /**
  66. * Shows the widget at the screen
  67. */
  68. public function show()
  69. {
  70. // define the tag properties
  71. $this->tag-> name = $this->name; // TAG name
  72. $this->tag-> value = $this->value; // TAG value
  73. $this->tag-> type = 'text'; // input type
  74. $this->tag-> style = "width:{$this->size}px"; // size
  75. if ($this->id)
  76. {
  77. $this->tag->{'id'} = $this->id;
  78. }
  79. // verify if the widget is editable
  80. if (parent::getEditable())
  81. {
  82. $this->tag-> readonly = "1";
  83. $this->tag-> style = "width:40px;-moz-user-select:none;border:0;text-align:center";
  84. $div = new TElement('div');
  85. $div-> id = $this->id.'_div';
  86. $div-> style = "width:{$this->size}px";
  87. $main_div = new TElement('div');
  88. $main_div-> style="text-align:center;width:{$this->size}px";
  89. TScript::create(" tslider_start( '#{$this->id}', {$this->value}, {$this->min}, {$this->max}, {$this->step}, {$this->direction} ); ");
  90. $main_div->add($this->tag);
  91. $main_div->add($div);
  92. $main_div->show();
  93. }
  94. else
  95. {
  96. $this->tag-> readonly = "1";
  97. $this->tag->{'class'} = 'tfield_disabled'; // CSS
  98. $this->tag-> style = "width:40px;-moz-user-select:none;";
  99. $this->tag-> onmouseover = "style.cursor='default'";
  100. $this->tag->show();
  101. }
  102. }
  103. /**
  104. * Set the value
  105. */
  106. public function setValue($value)
  107. {
  108. parent::setValue( (int) $value);
  109. }
  110. }
  111. ?>


agora o que nós fizemos acrescentamos uma variável que iremos dizer a orientação do Slider conforme a documentação
https://api.jqueryui.com/slider/

Eu usei um form do tutor para testar:


 
  1. <?php
  2. /**
  3. * FormCustomView
  4. *
  5. * @version 1.0
  6. * @package samples
  7. * @subpackage tutor
  8. * @author Pablo Dall'Oglio
  9. * @copyright Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10. * @license http://www.adianti.com.br/framework-license
  11. */
  12. class FormCustomView extends TPage
  13. {
  14. private $form;
  15. /**
  16. * Class constructor
  17. * Creates the page
  18. */
  19. function __construct()
  20. {
  21. parent::__construct();
  22. // create the notebook
  23. $notebook = new TNotebook(620, 340);
  24. // create the form
  25. $this->form = new TForm;
  26. // creates the notebook page
  27. $table = new TTable;
  28. // add the notebook inside the form
  29. $this->form->add($table);
  30. // adds the notebook page
  31. $notebook->appendPage('Input elements', $this->form);
  32. // create the form fields
  33. $field1 = new TEntry('field1');
  34. $field2 = new TEntry('field2');
  35. $field3 = new TEntry('field3');
  36. $field4 = new TEntry('field4');
  37. $field5 = new TPassword('field5');
  38. $field6 = new TDate('field6');
  39. $field7 = new TSpinner('field7');
  40. $field8 = new TSlider('field8');
  41. $field9 = new TText('field9');
  42. $field1->setTip('Tip for field 1');
  43. $field2->setTip('Tip for field 2');
  44. $field3->setTip('Tip for field 3');
  45. $field4->setTip('Tip for field 4');
  46. $field5->setTip('Tip for field 5');
  47. $field6->setTip('Tip for field 6');
  48. $field7->setTip('Tip for field 7');
  49. $field8->setTip('Tip for field 8');
  50. $field9->setTip('Tip for field 9');
  51. $field2->setValue('123');
  52. $field2->setEditable(FALSE);
  53. $field3->setMask('99.999-999');
  54. $field4->setMaxLength(10);
  55. $field6->setSize(100);
  56. $field7->setRange(0,100,10);
  57. $field8->setSize(10);//alterado o tamanho do slider
  58. $field8->setRange(0,100,5,'vertical');//acresentado a variavel direction
  59. $field7->setValue(30);
  60. $field8->setValue(50);
  61. $field9->setSize(300, 50);
  62. // add rows for the fields
  63. $table->addRowSet( new TLabel('TEntry object:'), $field1 );
  64. $table->addRowSet( new TLabel('TEntry not editable:'), $field2 );
  65. $table->addRowSet( new TLabel('TEntry with mask:'), $field3, new TLabel('99.999-999') );
  66. $table->addRowSet( new TLabel('TEntry with maxlength (10):'), $field4 );
  67. $table->addRowSet( new TLabel('TPassword object:'), $field5 );
  68. $table->addRowSet( new TLabel('TDate Object:'), $field6 );
  69. $table->addRowSet( new TLabel('Spinner Object:'), $field7 );
  70. $table->addRowSet( new TLabel('Slider Object:'), $field8 );
  71. $table->addRowSet( new TLabel('TText Object:'), $field9 );
  72. // creates the action button
  73. $button1=new TButton('action1');
  74. // define the button action
  75. $button1->setAction(new TAction(array($this, 'onSave')), 'Save');
  76. $button1->setImage('ico_save.png');
  77. // define wich are the form fields
  78. $this->form->setFields(array($field1, $field2, $field3, $field4, $field5,
  79. $field6, $field7, $field8, $field9, $button1));
  80. // add a row for the button
  81. $row=$table->addRow();
  82. $row->addCell($button1);
  83. // wrap the page content using vertical box
  84. $vbox = new TVBox;
  85. $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  86. $vbox->add($notebook);
  87. parent::add($vbox);
  88. }
  89. /**
  90. * Simulates an save button
  91. * Show the form content
  92. */
  93. public function onSave($param)
  94. {
  95. $data = $this->form->getData(); // optional parameter: active record class
  96. // put the data back to the form
  97. $this->form->setData($data);
  98. // creates a string with the form element's values
  99. $message = 'Field 1 : ' . $data->field1 . '<br>';
  100. $message.= 'Field 2 : ' . $data->field2 . '<br>';
  101. $message.= 'Field 3 : ' . $data->field3 . '<br>';
  102. $message.= 'Field 4 : ' . $data->field4 . '<br>';
  103. $message.= 'Field 5 : ' . $data->field5 . '<br>';
  104. $message.= 'Field 6 : ' . $data->field6 . '<br>';
  105. $message.= 'Field 7 : ' . $data->field7 . '<br>';
  106. $message.= 'Field 8 : ' . $data->field8 . '<br>';
  107. $message.= 'Field 9 : ' . $data->field9 . '<br>';
  108. // show the message
  109. new TMessage('info', $message);
  110. }
  111. }
  112. ?>


Boa Sorte !

Felipe Cortez


FC

Felipe Fica melhor assim não acha?

$field8->setSize(10);//alterado o tamanho do slider
$field8->setRange(0,100,10);// Range
$field8->setDirection('vertical');//acresentado a variavel direction

 
  1. <?php
  2. Namespace Adianti\Widget\Form;
  3. use Adianti\Widget\Form\AdiantiWidgetInterface;
  4. use Adianti\Widget\Base\TElement;
  5. use Adianti\Widget\Base\TScript;
  6. use Adianti\Widget\Form\TField;
  7. /**
  8. * Slider Widget
  9. *
  10. * @version 2.0
  11. * @package widget
  12. * @subpackage form
  13. * @author Pablo Dall'Oglio
  14. * @copyright Copyright (c) 2006-2014 Adianti Solutions Ltd. (http://www.adianti.com.br)
  15. * @license http://www.adianti.com.br/framework-license
  16. */
  17. class TSlider extends TField implements AdiantiWidgetInterface
  18. {
  19. protected $id;
  20. private $min;
  21. private $max;
  22. private $step;
  23. private $direction;
  24. /**
  25. * Class Constructor
  26. * @param $name Name of the widget
  27. */
  28. public function __construct($name)
  29. {
  30. parent::__construct($name);
  31. $this->id = 'tslider_'.uniqid();
  32. }
  33. /**
  34. * Define the field's range
  35. * @param $min Minimal value
  36. * @param $max Maximal value
  37. * @param $step Step value
  38. */
  39. public function setRange($min, $max, $step)
  40. {
  41. $this->min = $min;
  42. $this->max = $max;
  43. $this->step = $step;
  44. $this->value = $min;
  45. }
  46. //rotina para modificar o direction do slider
  47. public function setDirection($direction)
  48. {
  49. $this->direction = '"'.$direction.'"';
  50. }
  51. /**
  52. * Enable the field
  53. * @param $form_name Form name
  54. * @param $field Field name
  55. */
  56. public static function enableField($form_name, $field)
  57. {
  58. TScript::create( " tslider_enable_field('{$form_name}', '{$field}'); " );
  59. }
  60. /**
  61. * Disable the field
  62. * @param $form_name Form name
  63. * @param $field Field name
  64. */
  65. public static function disableField($form_name, $field)
  66. {
  67. TScript::create( " tslider_disable_field('{$form_name}', '{$field}'); " );
  68. }
  69. /**
  70. * Shows the widget at the screen
  71. */
  72. public function show()
  73. {
  74. // define the tag properties
  75. $this->tag-> name = $this->name; // TAG name
  76. $this->tag-> value = $this->value; // TAG value
  77. $this->tag-> type = 'text'; // input type
  78. $this->tag-> style = "width:{$this->size}px"; // size
  79. if ($this->id)
  80. {
  81. $this->tag->{'id'} = $this->id;
  82. }
  83. // verify if the widget is editable
  84. if (parent::getEditable())
  85. {
  86. $this->tag-> readonly = "1";
  87. $this->tag-> style = "width:40px;-moz-user-select:none;border:0;text-align:center";
  88. $div = new TElement('div');
  89. $div-> id = $this->id.'_div';
  90. $div-> style = "width:{$this->size}px";
  91. $main_div = new TElement('div');
  92. $main_div-> style="text-align:center;width:{$this->size}px";
  93. TScript::create(" tslider_start( '#{$this->id}', {$this->value}, {$this->min}, {$this->max}, {$this->step}, {$this->direction} ); ");
  94. $main_div->add($this->tag);
  95. $main_div->add($div);
  96. $main_div->show();
  97. }
  98. else
  99. {
  100. $this->tag-> readonly = "1";
  101. $this->tag->{'class'} = 'tfield_disabled'; // CSS
  102. $this->tag-> style = "width:40px;-moz-user-select:none;";
  103. $this->tag-> onmouseover = "style.cursor='default'";
  104. $this->tag->show();
  105. }
  106. }
  107. /**
  108. * Set the value
  109. */
  110. public function setValue($value)
  111. {
  112. parent::setValue( (int) $value);
  113. }
  114. }
  115. ?>
FC

Caro Felipe,

Você ajudou muito, não sabe quanto... Me passa a conta, rsrsrs.
Vou executar suas sugestões e assim que conseguir lhe falo.

Muito obrigado mesmo.

Abs,

Felipe