BxBaseStudioFormsPreLists.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. {
  14. protected $sUrlViewValues;
  15. function __construct($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct($aOptions, $oTemplate);
  18. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_form_btn_pre_lists_edit');
  19. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_form_btn_pre_lists_delete');
  20. $this->sUrlViewValues = BX_DOL_URL_STUDIO . 'builder_forms.php?page=pre_values&module=%s&list=%s';
  21. }
  22. public function performActionAdd()
  23. {
  24. $sAction = 'add';
  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. bx_import('BxDolStudioLanguagesUtils');
  97. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  98. $sLanguage = $oLanguage->getCurrentLangName(false);
  99. $sKey = BxDolForm::getSubmittedValue('title-' . $sLanguage, $aForm['form_attrs']['method']);
  100. $sKey = uriGenerate($sKey, 'sys_form_pre_lists', 'key', 'key');
  101. $iId = (int)$oForm->insert(array('key' => $sKey));
  102. if($iId != 0)
  103. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  104. else
  105. $aRes = array('msg' => _t('_adm_form_err_pre_lists_create'));
  106. $this->_echoResultJson($aRes, true);
  107. } else {
  108. bx_import('BxTemplStudioFunctions');
  109. $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(
  110. 'form_id' => $aForm['form_attrs']['id'],
  111. 'form' => $oForm->getCode(true),
  112. 'object' => $this->_sObject,
  113. 'action' => $sAction
  114. )));
  115. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  116. }
  117. }
  118. public function performActionEdit()
  119. {
  120. $sAction = 'edit';
  121. $aList = $this->_getItem('getLists');
  122. if($aList === false) {
  123. $this->_echoResultJson(array());
  124. exit;
  125. }
  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. } else {
  195. bx_import('BxTemplStudioFunctions');
  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. bx_import('BxDolStudioLanguagesUtils');
  225. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aList['title']);
  226. $aIdsAffected[] = $iId;
  227. $iAffected++;
  228. }
  229. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_from_err_pre_lists_delete')));
  230. }
  231. function getJsObject()
  232. {
  233. return 'oBxDolStudioFormsPreLists';
  234. }
  235. function getCode($isDisplayHeader = true)
  236. {
  237. return $this->_oTemplate->parseHtmlByName('forms_lists.html', array(
  238. 'content' => parent::getCode($isDisplayHeader),
  239. 'js_object' => $this->getJsObject(),
  240. 'grid_object' => $this->_sObject,
  241. 'params_divider' => $this->sParamsDivider
  242. ));
  243. }
  244. protected function _addJsCss()
  245. {
  246. parent::_addJsCss();
  247. $this->_oTemplate->addJs(array('jquery.form.min.js', 'forms_lists.js'));
  248. bx_import('BxTemplStudioFormView');
  249. $oForm = new BxTemplStudioFormView(array());
  250. $oForm->addCssJs();
  251. }
  252. protected function _getCellValues ($mixedValue, $sKey, $aField, $aRow)
  253. {
  254. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  255. 'href' => sprintf($this->sUrlViewValues, $aRow['module'], $aRow['key']),
  256. 'title' => _t('_adm_form_txt_pre_lists_manage_values'),
  257. 'bx_repeat:attrs' => array(),
  258. 'content' => _t('_adm_form_txt_pre_lists_n_values', $aRow['values_count'])
  259. ));
  260. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  261. }
  262. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  263. {
  264. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  265. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  266. }
  267. protected function _getCellUseForSets ($mixedValue, $sKey, $aField, $aRow)
  268. {
  269. $aChanger = array(
  270. '0' => '_adm_form_txt_pre_lists_no',
  271. '1' => '_adm_form_txt_pre_lists_yes'
  272. );
  273. $mixedValue = $this->_limitMaxLength(_t($aChanger[$mixedValue]), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  274. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  275. }
  276. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  277. {
  278. if(!$this->_canDelete($aRow))
  279. return '';
  280. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  281. }
  282. protected function _getFilterControls ()
  283. {
  284. $sContent = parent::_getFilterControls();
  285. bx_import('BxTemplStudioFormView');
  286. $oForm = new BxTemplStudioFormView(array());
  287. $aInputModules = array(
  288. 'type' => 'select',
  289. 'name' => 'module',
  290. 'attrs' => array(
  291. 'id' => 'bx-grid-module-' . $this->_sObject,
  292. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  293. ),
  294. 'value' => '',
  295. 'values' => $this->getModules()
  296. );
  297. $aCounter = array();
  298. $this->oDb->getLists(array('type' => 'counter_by_modules'), $aCounter, false);
  299. foreach($aInputModules['values'] as $sKey => $sValue)
  300. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . (isset($aCounter[$sKey]) ? $aCounter[$sKey] : "0") . ")";
  301. $aInputModules['values'] = array_merge(array('' => _t('_adm_form_txt_all_modules')), $aInputModules['values']);
  302. return $oForm->genRow($aInputModules) . $sContent;
  303. }
  304. protected function _canDelete($aList)
  305. {
  306. return $aList['module'] == BX_DOL_STUDIO_MODULE_CUSTOM;
  307. }
  308. }
  309. /** @} */