CustomField.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ CCfvZkZY3G0JuSCcSwfGJ1E7a/R7OassUhPY9+BlaSY=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2017 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.10 [rev.7.10.01]
  11. */
  12. namespace Ppb\Model\Elements;
  13. class CustomField extends AbstractElements
  14. {
  15. /**
  16. *
  17. * form id
  18. *
  19. * @var array
  20. */
  21. protected $_formId = array();
  22. /**
  23. *
  24. * element types allowed
  25. *
  26. * @var array
  27. */
  28. protected $_elements = array(
  29. 'text' => 'text',
  30. 'select' => 'select',
  31. 'radio' => 'radio',
  32. 'checkbox' => 'checkbox',
  33. 'password' => 'password',
  34. 'textarea' => 'textarea',
  35. );
  36. /**
  37. *
  38. * class constructor
  39. *
  40. * @param mixed $formId
  41. */
  42. public function __construct($formId = null)
  43. {
  44. parent::__construct();
  45. $this->_formId = (array)$formId;
  46. }
  47. /**
  48. *
  49. * generate custom field creation form elements
  50. *
  51. * @return array
  52. */
  53. public function getElements()
  54. {
  55. return array(
  56. array(
  57. 'form_id' => 'global',
  58. 'id' => 'element',
  59. 'element' => 'select',
  60. 'label' => $this->_('Html Element'),
  61. 'multiOptions' => $this->_elements,
  62. 'description' => $this->_('Choose the element type you wish to create.'),
  63. 'attributes' => array(
  64. 'class' => 'form-control input-medium field-changeable',
  65. ),
  66. 'bodyCode' => "
  67. <script type=\"text/javascript\">
  68. function updateCustomFieldProperties() {
  69. var el = $('select[name=\"element\"]').val();
  70. var productAttribute = $('input:checkbox[name=\"product_attribute\"]');
  71. if (el === 'select' || el === 'radio' || el === 'checkbox') {
  72. $('.multi-options').closest('.form-group').show();
  73. }
  74. else {
  75. $('.multi-options').closest('.form-group').hide();
  76. }
  77. if (el === 'select') {
  78. $('input:checkbox[name=\"multiple\"]').closest('.form-group').show();
  79. }
  80. else {
  81. $('input:checkbox[name=\"multiple\"]').prop('checked', false).closest('.form-group').hide();
  82. }
  83. if (el === 'checkbox') {
  84. productAttribute.closest('.form-group').show();
  85. }
  86. else {
  87. productAttribute.prop('checked', false).closest('.form-group').hide();
  88. }
  89. if (productAttribute.is(':checked')) {
  90. $('input:checkbox[name=\"required\"]').prop('checked', false).closest('.form-group').hide();
  91. }
  92. else {
  93. $('input:checkbox[name=\"required\"]').closest('.form-group').show();
  94. }
  95. }
  96. $(document).ready(function() {
  97. updateCustomFieldProperties();
  98. });
  99. $(document).on('change', '.field-changeable', function() {
  100. updateCustomFieldProperties();
  101. });
  102. </script>",
  103. ),
  104. array(
  105. 'form_id' => 'global',
  106. 'id' => 'product_attribute',
  107. 'element' => 'checkbox',
  108. 'label' => $this->_('Product Attribute'),
  109. 'description' => $this->_('Check the above checkbox if this element will be a product attribute.'),
  110. 'multiOptions' => array(
  111. 1 => null,
  112. ),
  113. 'attributes' => array(
  114. 'class' => 'field-changeable',
  115. ),
  116. ),
  117. array(
  118. 'form_id' => 'global',
  119. 'id' => 'label',
  120. 'element' => 'text',
  121. 'label' => $this->_('Label'),
  122. 'description' => $this->_('Enter a label for the element.'),
  123. 'attributes' => array(
  124. 'class' => 'form-control input-medium',
  125. ),
  126. 'required' => true,
  127. ),
  128. array(
  129. 'form_id' => 'global',
  130. 'id' => 'description',
  131. 'element' => 'text',
  132. 'label' => $this->_('Description'),
  133. 'description' => $this->_('Enter a description for the element (optional).'),
  134. 'attributes' => array(
  135. 'class' => 'form-control input-xlarge',
  136. ),
  137. ),
  138. array(
  139. 'form_id' => 'global',
  140. 'id' => 'subtitle',
  141. 'element' => 'text',
  142. 'label' => $this->_('Subtitle'),
  143. 'description' => $this->_('Enter a subtitle for the element. The subtitle can be used for separating '
  144. . 'custom fields into different sections (optional).'),
  145. 'attributes' => array(
  146. 'class' => 'form-control input-xlarge',
  147. ),
  148. ),
  149. array(
  150. 'form_id' => 'global',
  151. 'id' => 'prefix',
  152. 'element' => 'text',
  153. 'label' => $this->_('Prefix'),
  154. 'description' => $this->_('Enter a prefix for the element (optional).'),
  155. 'attributes' => array(
  156. 'class' => 'form-control input-mini',
  157. ),
  158. ),
  159. array(
  160. 'form_id' => 'global',
  161. 'id' => 'suffix',
  162. 'element' => 'text',
  163. 'label' => $this->_('Suffix'),
  164. 'description' => $this->_('Enter a suffix for the element (optional).'),
  165. 'attributes' => array(
  166. 'class' => 'form-control input-mini',
  167. ),
  168. ),
  169. array(
  170. 'form_id' => 'item',
  171. 'id' => 'category_ids',
  172. 'element' => '\\Ppb\\Form\\Element\\ChznSelect',
  173. 'label' => $this->_('Select Categories'),
  174. 'description' => $this->_('Choose for which categories this field will apply, or leave selection empty if it should apply to all categories.'),
  175. 'multiOptions' => $this->getCategories()->getMultiOptions(null, null, false, true),
  176. 'attributes' => array(
  177. 'style' => 'width: 350px;',
  178. 'data-placeholder' => 'Choose Categories...',
  179. ),
  180. 'multiple' => true,
  181. ),
  182. array(
  183. 'form_id' => 'global',
  184. 'id' => 'attributes',
  185. 'element' => '\\Ppb\\Form\\Element\\MultiKeyValue',
  186. 'label' => $this->_('Attributes'),
  187. 'description' => $this->_('Add attributes for the element (class, id etc.) (optional).<br>'
  188. . 'Recommended attribute: class => form-control'),
  189. 'attributes' => array(
  190. 'class' => 'form-control input-medium',
  191. ),
  192. ),
  193. array(
  194. 'form_id' => 'global',
  195. 'id' => 'multiOptions',
  196. 'element' => '\\Ppb\\Form\\Element\\MultiKeyValue',
  197. 'label' => $this->_('Options'),
  198. 'description' => $this->_('Add options for the element.'),
  199. 'attributes' => array(
  200. 'class' => 'form-control input-medium multi-options',
  201. )
  202. ),
  203. array(
  204. 'form_id' => 'global',
  205. 'id' => 'required',
  206. 'element' => 'checkbox',
  207. 'label' => $this->_('Required'),
  208. 'description' => $this->_('Check the above checkbox if the element is required.'),
  209. 'multiOptions' => array(
  210. 1 => null,
  211. ),
  212. ),
  213. array(
  214. 'form_id' => 'item',
  215. 'id' => 'searchable',
  216. 'element' => 'checkbox',
  217. 'label' => $this->_('Searchable'),
  218. 'description' => $this->_('Check the above checkbox if the element will be searchable.'),
  219. 'multiOptions' => array(
  220. 1 => null,
  221. ),
  222. ),
  223. );
  224. }
  225. }