BxBaseStudioFormsPreLists.php 13 KB

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