BxBaseStudioFormsPreLists.php 13 KB

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