BxBaseStudioFormsPreLists.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. defined('BX_DOL') or die('hack attempt');
  11. bx_import('BxDolStudioFormsPreLists');
  12. bx_import('BxTemplStudioFormView');
  13. class BxBaseStudioFormsPreLists extends BxDolStudioFormsPreLists {
  14. protected $sUrlViewValues;
  15. function __construct($aOptions, $oTemplate = false) {
  16. parent::__construct($aOptions, $oTemplate);
  17. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_form_btn_pre_lists_edit');
  18. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_form_btn_pre_lists_delete');
  19. $this->sUrlViewValues = BX_DOL_URL_STUDIO . 'builder_forms.php?page=pre_values&module=%s&list=%s';
  20. }
  21. public function performActionAdd() {
  22. $sAction = 'add';
  23. $aForm = array(
  24. 'form_attrs' => array(
  25. 'id' => 'adm-form-pre-list-create',
  26. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  27. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  28. ),
  29. 'params' => array (
  30. 'db' => array(
  31. 'table' => 'sys_form_pre_lists',
  32. 'key' => 'id',
  33. 'uri' => '',
  34. 'uri_title' => '',
  35. 'submit_name' => 'do_submit'
  36. ),
  37. ),
  38. 'inputs' => array (
  39. 'module' => array(
  40. 'type' => 'hidden',
  41. 'name' => 'module',
  42. 'value' => BX_DOL_STUDIO_MODULE_CUSTOM,
  43. 'db' => array (
  44. 'pass' => 'Xss',
  45. ),
  46. ),
  47. 'use_for_sets' => array(
  48. 'type' => 'hidden',
  49. 'name' => 'use_for_sets',
  50. 'value' => 1,
  51. 'db' => array (
  52. 'pass' => 'Int',
  53. ),
  54. ),
  55. 'title' => array(
  56. 'type' => 'text_translatable',
  57. 'name' => 'title',
  58. 'caption' => _t('_adm_form_txt_pre_lists_title'),
  59. 'info' => _t('_adm_form_dsc_pre_lists_title'),
  60. 'value' => '_adm_form_txt_pre_lists',
  61. 'required' => '1',
  62. 'db' => array (
  63. 'pass' => 'Xss',
  64. ),
  65. 'checker' => array (
  66. 'func' => 'LengthTranslatable',
  67. 'params' => array(3,100, 'title'),
  68. 'error' => _t('_adm_form_err_pre_lists_title'),
  69. ),
  70. ),
  71. 'controls' => array(
  72. 'name' => 'controls',
  73. 'type' => 'input_set',
  74. array(
  75. 'type' => 'submit',
  76. 'name' => 'do_submit',
  77. 'value' => _t('_adm_form_btn_pre_lists_add'),
  78. ),
  79. array (
  80. 'type' => 'reset',
  81. 'name' => 'close',
  82. 'value' => _t('_adm_form_btn_pre_lists_cancel'),
  83. 'attrs' => array(
  84. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  85. 'class' => 'bx-def-margin-sec-left',
  86. ),
  87. )
  88. )
  89. )
  90. );
  91. $oForm = new BxTemplStudioFormView($aForm);
  92. $oForm->initChecker();
  93. if($oForm->isSubmittedAndValid()) {
  94. bx_import('BxDolStudioLanguagesUtils');
  95. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  96. $sLanguage = $oLanguage->getCurrentLangName(false);
  97. $sKey = BxDolForm::getSubmittedValue('title-' . $sLanguage, $aForm['form_attrs']['method']);
  98. $sKey = uriGenerate($sKey, 'sys_form_pre_lists', 'key', 'key');
  99. $iId = (int)$oForm->insert(array('key' => $sKey));
  100. if($iId != 0)
  101. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  102. else
  103. $aRes = array('msg' => _t('_adm_form_err_pre_lists_create'));
  104. $this->_echoResultJson($aRes, true);
  105. }
  106. else {
  107. bx_import('BxTemplStudioFunctions');
  108. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-form-pre-list-create-popup', _t('_adm_form_txt_pre_lists_create_popup'), $this->_oTemplate->parseHtmlByName('form_add_list.html', array(
  109. 'form_id' => $aForm['form_attrs']['id'],
  110. 'form' => $oForm->getCode(true),
  111. 'object' => $this->_sObject,
  112. 'action' => $sAction
  113. )));
  114. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  115. }
  116. }
  117. public function performActionEdit() {
  118. $sAction = 'edit';
  119. $aList = $this->_getItem('getLists');
  120. if($aList === false) {
  121. $this->_echoResultJson(array());
  122. exit;
  123. }
  124. $aForm = array(
  125. 'form_attrs' => array(
  126. 'id' => 'adm-form-list-edit',
  127. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  128. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  129. ),
  130. 'params' => array (
  131. 'db' => array(
  132. 'table' => 'sys_form_pre_lists',
  133. 'key' => 'id',
  134. 'uri' => '',
  135. 'uri_title' => '',
  136. 'submit_name' => 'do_submit'
  137. ),
  138. ),
  139. 'inputs' => array (
  140. 'id' => array(
  141. 'type' => 'hidden',
  142. 'name' => 'id',
  143. 'value' => $aList['id'],
  144. 'db' => array (
  145. 'pass' => 'Int',
  146. ),
  147. ),
  148. 'title' => array(
  149. 'type' => 'text_translatable',
  150. 'name' => 'title',
  151. 'caption' => _t('_adm_form_txt_pre_lists_title'),
  152. 'info' => _t('_adm_form_dsc_pre_lists_title'),
  153. 'value' => $aList['title'],
  154. 'required' => '1',
  155. 'db' => array (
  156. 'pass' => 'Xss',
  157. ),
  158. 'checker' => array (
  159. 'func' => 'LengthTranslatable',
  160. 'params' => array(3,100, 'title'),
  161. 'error' => _t('_adm_form_err_pre_lists_title'),
  162. ),
  163. ),
  164. 'controls' => array(
  165. 'name' => 'controls',
  166. 'type' => 'input_set',
  167. array(
  168. 'type' => 'submit',
  169. 'name' => 'do_submit',
  170. 'value' => _t('_adm_form_btn_pre_lists_save'),
  171. ),
  172. array (
  173. 'type' => 'reset',
  174. 'name' => 'close',
  175. 'value' => _t('_adm_form_btn_pre_lists_cancel'),
  176. 'attrs' => array(
  177. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  178. 'class' => 'bx-def-margin-sec-left',
  179. ),
  180. )
  181. )
  182. )
  183. );
  184. $oForm = new BxTemplStudioFormView($aForm);
  185. $oForm->initChecker();
  186. if($oForm->isSubmittedAndValid()) {
  187. if($oForm->update($aList['id']) !== false)
  188. $aRes = array('grid' => $this->getCode(false), 'blink' => $aList['id']);
  189. else
  190. $aRes = array('msg' => _t('_adm_form_err_pre_lists_edit'));
  191. $this->_echoResultJson($aRes, true);
  192. }
  193. else {
  194. bx_import('BxTemplStudioFunctions');
  195. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-form-pre-list-edit-popup', _t('_adm_form_txt_pre_lists_edit_popup', _t($aList['title'])), $this->_oTemplate->parseHtmlByName('form_add_list.html', array(
  196. 'form_id' => $aForm['form_attrs']['id'],
  197. 'form' => $oForm->getCode(true),
  198. 'object' => $this->_sObject,
  199. 'action' => $sAction
  200. )));
  201. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  202. }
  203. }
  204. public function performActionDelete() {
  205. $sAction = 'delete';
  206. $iAffected = 0;
  207. $aIds = bx_get('ids');
  208. if(!$aIds || !is_array($aIds)) {
  209. $this->_echoResultJson(array());
  210. exit;
  211. }
  212. $aIdsAffected = array ();
  213. foreach($aIds as $iId) {
  214. $aList = array();
  215. $this->oDb->getLists(array('type' => 'by_id', 'value' => (int)$iId), $aList, false);
  216. if(!is_array($aList) || empty($aList))
  217. continue;
  218. if(!$this->_canDelete($aList))
  219. continue;
  220. if(!$this->oDb->deleteValues(array('type' => 'by_key', 'value' => $aList['key'])) || (int)$this->_delete($iId) <= 0)
  221. continue;
  222. bx_import('BxDolStudioLanguagesUtils');
  223. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aList['title']);
  224. $aIdsAffected[] = $iId;
  225. $iAffected++;
  226. }
  227. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_from_err_pre_lists_delete')));
  228. }
  229. function getJsObject() {
  230. return 'oBxDolStudioFormsPreLists';
  231. }
  232. function getCode($isDisplayHeader = true) {
  233. return $this->_oTemplate->parseHtmlByName('forms_lists.html', array(
  234. 'content' => parent::getCode($isDisplayHeader),
  235. 'js_object' => $this->getJsObject(),
  236. 'grid_object' => $this->_sObject,
  237. 'params_divider' => $this->sParamsDivider
  238. ));
  239. }
  240. protected function _addJsCss() {
  241. parent::_addJsCss();
  242. $this->_oTemplate->addJs(array('jquery.form.js', 'forms_lists.js'));
  243. bx_import('BxTemplStudioFormView');
  244. $oForm = new BxTemplStudioFormView(array());
  245. $oForm->addCssJs();
  246. }
  247. protected function _getCellValues ($mixedValue, $sKey, $aField, $aRow) {
  248. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  249. 'href' => sprintf($this->sUrlViewValues, $aRow['module'], $aRow['key']),
  250. 'title' => _t('_adm_form_txt_pre_lists_manage_values'),
  251. 'bx_repeat:attrs' => array(),
  252. 'content' => _t('_adm_form_txt_pre_lists_n_values', $aRow['values_count'])
  253. ));
  254. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  255. }
  256. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow) {
  257. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  258. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  259. }
  260. protected function _getCellUseForSets ($mixedValue, $sKey, $aField, $aRow) {
  261. $aChanger = array(
  262. '0' => '_adm_form_txt_pre_lists_no',
  263. '1' => '_adm_form_txt_pre_lists_yes'
  264. );
  265. $mixedValue = $this->_limitMaxLength(_t($aChanger[$mixedValue]), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  266. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  267. }
  268. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  269. if(!$this->_canDelete($aRow))
  270. return '';
  271. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  272. }
  273. protected function _getFilterControls () {
  274. $sContent = parent::_getFilterControls();
  275. bx_import('BxTemplStudioFormView');
  276. $oForm = new BxTemplStudioFormView(array());
  277. $aInputModules = array(
  278. 'type' => 'select',
  279. 'name' => 'module',
  280. 'attrs' => array(
  281. 'id' => 'bx-grid-module-' . $this->_sObject,
  282. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  283. ),
  284. 'value' => '',
  285. 'values' => $this->getModules()
  286. );
  287. $aCounter = array();
  288. $this->oDb->getLists(array('type' => 'counter_by_modules'), $aCounter, false);
  289. foreach($aInputModules['values'] as $sKey => $sValue)
  290. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . (isset($aCounter[$sKey]) ? $aCounter[$sKey] : "0") . ")";
  291. $aInputModules['values'] = array_merge(array('' => _t('_adm_form_txt_all_modules')), $aInputModules['values']);
  292. return $oForm->genRow($aInputModules) . $sContent;
  293. }
  294. protected function _canDelete($aList) {
  295. return $aList['module'] == BX_DOL_STUDIO_MODULE_CUSTOM;
  296. }
  297. }
  298. /** @} */