1
0

BxBaseStudioFormsPreLists.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. $aIds = bx_get('ids');
  120. if(!$aIds || !is_array($aIds)) {
  121. $iId = (int)bx_get('id');
  122. if(!$iId) {
  123. $this->_echoResultJson(array());
  124. exit;
  125. }
  126. $aIds = array($iId);
  127. }
  128. $iId = $aIds[0];
  129. $aList = array();
  130. $this->oDb->getLists(array('type' => 'by_id', 'value' => $iId), $aList, false);
  131. if(!is_array($aList) || empty($aList)){
  132. $this->_echoResultJson(array());
  133. exit;
  134. }
  135. $aForm = array(
  136. 'form_attrs' => array(
  137. 'id' => 'adm-form-list-edit',
  138. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  139. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  140. ),
  141. 'params' => array (
  142. 'db' => array(
  143. 'table' => 'sys_form_pre_lists',
  144. 'key' => 'id',
  145. 'uri' => '',
  146. 'uri_title' => '',
  147. 'submit_name' => 'do_submit'
  148. ),
  149. ),
  150. 'inputs' => array (
  151. 'id' => array(
  152. 'type' => 'hidden',
  153. 'name' => 'id',
  154. 'value' => $iId,
  155. 'db' => array (
  156. 'pass' => 'Int',
  157. ),
  158. ),
  159. 'title' => array(
  160. 'type' => 'text_translatable',
  161. 'name' => 'title',
  162. 'caption' => _t('_adm_form_txt_pre_lists_title'),
  163. 'info' => _t('_adm_form_dsc_pre_lists_title'),
  164. 'value' => $aList['title'],
  165. 'required' => '1',
  166. 'db' => array (
  167. 'pass' => 'Xss',
  168. ),
  169. 'checker' => array (
  170. 'func' => 'LengthTranslatable',
  171. 'params' => array(3,100, 'title'),
  172. 'error' => _t('_adm_form_err_pre_lists_title'),
  173. ),
  174. ),
  175. 'controls' => array(
  176. 'name' => 'controls',
  177. 'type' => 'input_set',
  178. array(
  179. 'type' => 'submit',
  180. 'name' => 'do_submit',
  181. 'value' => _t('_adm_form_btn_pre_lists_save'),
  182. ),
  183. array (
  184. 'type' => 'reset',
  185. 'name' => 'close',
  186. 'value' => _t('_adm_form_btn_pre_lists_cancel'),
  187. 'attrs' => array(
  188. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  189. 'class' => 'bx-def-margin-sec-left',
  190. ),
  191. )
  192. )
  193. )
  194. );
  195. $oForm = new BxTemplStudioFormView($aForm);
  196. $oForm->initChecker();
  197. if($oForm->isSubmittedAndValid()) {
  198. if($oForm->update($iId) !== false)
  199. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  200. else
  201. $aRes = array('msg' => _t('_adm_form_err_pre_lists_edit'));
  202. $this->_echoResultJson($aRes, true);
  203. }
  204. else {
  205. bx_import('BxTemplStudioFunctions');
  206. $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(
  207. 'form_id' => $aForm['form_attrs']['id'],
  208. 'form' => $oForm->getCode(true),
  209. 'object' => $this->_sObject,
  210. 'action' => $sAction
  211. )));
  212. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  213. }
  214. }
  215. public function performActionDelete() {
  216. $sAction = 'delete';
  217. $iAffected = 0;
  218. $aIds = bx_get('ids');
  219. if(!$aIds || !is_array($aIds)) {
  220. $this->_echoResultJson(array());
  221. exit;
  222. }
  223. $aIdsAffected = array ();
  224. foreach($aIds as $iId) {
  225. $aList = array();
  226. $this->oDb->getLists(array('type' => 'by_id', 'value' => (int)$iId), $aList, false);
  227. if(!is_array($aList) || empty($aList))
  228. continue;
  229. if(!$this->_canDelete($aList))
  230. continue;
  231. if(!$this->oDb->deleteValues(array('type' => 'by_key', 'value' => $aList['key'])) || (int)$this->_delete($iId) <= 0)
  232. continue;
  233. bx_import('BxDolStudioLanguagesUtils');
  234. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aList['title']);
  235. $aIdsAffected[] = $iId;
  236. $iAffected++;
  237. }
  238. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_from_err_pre_lists_delete')));
  239. }
  240. function getJsObject() {
  241. return 'oBxDolStudioFormsPreLists';
  242. }
  243. function getCode($isDisplayHeader = true) {
  244. return $this->_oTemplate->parseHtmlByName('forms_lists.html', array(
  245. 'content' => parent::getCode($isDisplayHeader),
  246. 'js_object' => $this->getJsObject(),
  247. 'grid_object' => $this->_sObject,
  248. 'params_divider' => $this->sParamsDivider
  249. ));
  250. }
  251. protected function _addJsCss() {
  252. parent::_addJsCss();
  253. $this->_oTemplate->addJs(array('jquery.form.js', 'forms_lists.js'));
  254. bx_import('BxTemplStudioFormView');
  255. $oForm = new BxTemplStudioFormView(array());
  256. $oForm->addCssJs();
  257. }
  258. protected function _getCellValues ($mixedValue, $sKey, $aField, $aRow) {
  259. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  260. 'href' => sprintf($this->sUrlViewValues, $aRow['module'], $aRow['key']),
  261. 'title' => _t('_adm_form_txt_pre_lists_manage_values'),
  262. 'bx_repeat:attrs' => array(),
  263. 'content' => _t('_adm_form_txt_pre_lists_n_values', $aRow['values_count'])
  264. ));
  265. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  266. }
  267. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow) {
  268. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  269. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  270. }
  271. protected function _getCellUseForSets ($mixedValue, $sKey, $aField, $aRow) {
  272. $aChanger = array(
  273. '0' => '_adm_form_txt_pre_lists_no',
  274. '1' => '_adm_form_txt_pre_lists_yes'
  275. );
  276. $mixedValue = $this->_limitMaxLength(_t($aChanger[$mixedValue]), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  277. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  278. }
  279. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  280. if(!$this->_canDelete($aRow))
  281. return '';
  282. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  283. }
  284. protected function _getFilterControls () {
  285. $sContent = parent::_getFilterControls();
  286. bx_import('BxTemplStudioFormView');
  287. $oForm = new BxTemplStudioFormView(array());
  288. $aInputModules = array(
  289. 'type' => 'select',
  290. 'name' => 'module',
  291. 'attrs' => array(
  292. 'id' => 'bx-grid-module-' . $this->_sObject,
  293. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  294. ),
  295. 'value' => '',
  296. 'values' => $this->getModules()
  297. );
  298. $aCounter = array();
  299. $this->oDb->getLists(array('type' => 'counter_by_modules'), $aCounter, false);
  300. foreach($aInputModules['values'] as $sKey => $sValue)
  301. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . (isset($aCounter[$sKey]) ? $aCounter[$sKey] : "0") . ")";
  302. $aInputModules['values'] = array_merge(array('' => _t('_adm_form_txt_all_modules')), $aInputModules['values']);
  303. return $oForm->genRow($aInputModules) . $sContent;
  304. }
  305. protected function _canDelete($aList) {
  306. return $aList['module'] == BX_DOL_STUDIO_MODULE_CUSTOM;
  307. }
  308. }
  309. /** @} */