BxBaseStudioNavigationSets.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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('BxDolStudioNavigationSets');
  11. bx_import('BxTemplStudioFormView');
  12. class BxBaseStudioNavigationSets extends BxDolStudioNavigationSets {
  13. protected $sUrlViewItems;
  14. function __construct($aOptions, $oTemplate = false) {
  15. parent::__construct($aOptions, $oTemplate);
  16. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_nav_btn_sets_edit');
  17. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_nav_btn_sets_delete');
  18. $this->sUrlViewItems = BX_DOL_URL_STUDIO . 'builder_menu.php?page=items&module=%s&set=%s';
  19. }
  20. public function performActionAdd() {
  21. $sAction = 'add';
  22. $aForm = array(
  23. 'form_attrs' => array(
  24. 'id' => 'adm-nav-set-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_menu_sets',
  31. 'key' => 'set_name',
  32. 'uri' => '',
  33. 'uri_title' => '',
  34. 'submit_name' => 'do_submit'
  35. ),
  36. ),
  37. 'inputs' => array (
  38. 'title' => array(
  39. 'type' => 'text_translatable',
  40. 'name' => 'title',
  41. 'caption' => _t('_adm_nav_txt_sets_title'),
  42. 'info' => _t('_adm_nav_dsc_sets_title'),
  43. 'value' => '_adm_nav_txt_set',
  44. 'required' => '1',
  45. 'db' => array (
  46. 'pass' => 'Xss',
  47. ),
  48. 'checker' => array (
  49. 'func' => 'LengthTranslatable',
  50. 'params' => array(3, 100, 'title'),
  51. 'error' => _t('_adm_nav_err_sets_title'),
  52. ),
  53. ),
  54. 'deletable' => array(
  55. 'type' => 'hidden',
  56. 'name' => 'deletable',
  57. 'value' => 1,
  58. 'db' => array (
  59. 'pass' => 'Int',
  60. ),
  61. ),
  62. 'controls' => array(
  63. 'name' => 'controls',
  64. 'type' => 'input_set',
  65. array(
  66. 'type' => 'submit',
  67. 'name' => 'do_submit',
  68. 'value' => _t('_adm_nav_btn_sets_add'),
  69. ),
  70. array (
  71. 'type' => 'reset',
  72. 'name' => 'close',
  73. 'value' => _t('_adm_nav_btn_sets_cancel'),
  74. 'attrs' => array(
  75. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  76. 'class' => 'bx-def-margin-sec-left',
  77. ),
  78. )
  79. )
  80. )
  81. );
  82. $oForm = new BxTemplStudioFormView($aForm);
  83. $oForm->initChecker();
  84. if($oForm->isSubmittedAndValid()) {
  85. bx_import('BxDolStudioLanguagesUtils');
  86. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  87. $sName = BxDolForm::getSubmittedValue('title-' . $sLanguage, $aForm['form_attrs']['method']);
  88. $sName = uriGenerate($sName, 'sys_menu_sets', 'set_name', 'set');
  89. if($oForm->insert(array('set_name' => $sName, 'module' => BX_DOL_STUDIO_MODULE_CUSTOM)) !== false)
  90. $aRes = array('grid' => $this->getCode(false), 'blink' => $sName);
  91. else
  92. $aRes = array('msg' => _t('_adm_nav_err_sets_create'));
  93. $this->_echoResultJson($aRes, true);
  94. }
  95. else {
  96. bx_import('BxTemplStudioFunctions');
  97. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-set-create-popup', _t('_adm_nav_txt_sets_create_popup'), $this->_oTemplate->parseHtmlByName('nav_add_set.html', array(
  98. 'form_id' => $aForm['form_attrs']['id'],
  99. 'form' => $oForm->getCode(true),
  100. 'object' => $this->_sObject,
  101. 'action' => $sAction
  102. )));
  103. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  104. }
  105. }
  106. public function performActionEdit() {
  107. $sAction = 'edit';
  108. $aIds = bx_get('ids');
  109. if(!$aIds || !is_array($aIds)) {
  110. $sId = bx_get('set_name');
  111. if(!$sId) {
  112. $this->_echoResultJson(array());
  113. exit;
  114. }
  115. $aIds = array($sId);
  116. }
  117. $sId = bx_process_input($aIds[0]);
  118. $aSet = array();
  119. $iSet = $this->oDb->getSets(array('type' => 'by_name', 'value' => $sId), $aSet);
  120. if($iSet != 1 || empty($aSet)) {
  121. $this->_echoResultJson(array());
  122. exit;
  123. }
  124. $aForm = array(
  125. 'form_attrs' => array(
  126. 'id' => 'adm-nav-set-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_menu_sets',
  133. 'key' => 'set_name',
  134. 'uri' => '',
  135. 'uri_title' => '',
  136. 'submit_name' => 'do_submit'
  137. ),
  138. ),
  139. 'inputs' => array (
  140. 'set_name' => array(
  141. 'type' => 'hidden',
  142. 'name' => 'set_name',
  143. 'value' => $sId,
  144. 'db' => array (
  145. 'pass' => 'Xss',
  146. ),
  147. ),
  148. 'title' => array(
  149. 'type' => 'text_translatable',
  150. 'name' => 'title',
  151. 'caption' => _t('_adm_nav_txt_sets_title'),
  152. 'info' => _t('_adm_nav_dsc_sets_title'),
  153. 'value' => $aSet['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_nav_err_sets_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_nav_btn_menus_save'),
  171. ),
  172. array (
  173. 'type' => 'reset',
  174. 'name' => 'close',
  175. 'value' => _t('_adm_nav_btn_menus_cancel'),
  176. 'attrs' => array(
  177. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  178. 'class' => 'bx-def-margin-sec-left',
  179. ),
  180. )
  181. )
  182. )
  183. );
  184. bx_import('BxTemplStudioFormView');
  185. $oForm = new BxTemplStudioFormView($aForm);
  186. $oForm->initChecker();
  187. if($oForm->isSubmittedAndValid()) {
  188. if($oForm->update($sId) !== false)
  189. $aRes = array('grid' => $this->getCode(false), 'blink' => $sId);
  190. else
  191. $aRes = array('msg' => _t('_adm_nav_err_sets_edit'));
  192. $this->_echoResultJson($aRes, true);
  193. }
  194. else {
  195. bx_import('BxTemplStudioFunctions');
  196. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-set-edit-popup', _t('_adm_nav_txt_sets_edit_popup', _t($aSet['title'])), $this->_oTemplate->parseHtmlByName('nav_add_set.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. $iAffected = 0;
  207. $aIds = bx_get('ids');
  208. if(!$aIds || !is_array($aIds)) {
  209. $this->_echoResultJson(array());
  210. exit;
  211. }
  212. $oGridItems = BxDolGrid::getObjectInstance('sys_studio_nav_items');
  213. if(!$oGridItems) {
  214. $this->_echoResultJson(array());
  215. exit;
  216. }
  217. $aIdsAffected = array ();
  218. foreach($aIds as $sId) {
  219. $sId = bx_process_input($sId);
  220. $aSet = array();
  221. $this->oDb->getSets(array('type' => 'by_name', 'value' => $sId), $aSet, false);
  222. if(!is_array($aSet) || empty($aSet))
  223. continue;
  224. $aMenus = array();
  225. $this->oDb->getMenus(array('type' => 'by_set_name', 'value' => $sId), $aMenus, false);
  226. if(is_array($aMenus) && count($aMenus) > 0) {
  227. $this->_echoResultJson(array('msg' => _t('_adm_nav_err_sets_delete_used')));
  228. exit;
  229. }
  230. if((int)$this->_delete($sId) <= 0)
  231. continue;
  232. $aItems = array();
  233. $this->oDb->getItems(array('type' => 'by_set_name', 'value' => $aSet['name']), $aItems, false);
  234. if(is_array($aItems) && !empty($aItems))
  235. foreach($aItems as $aItem)
  236. $oGridItems->deleteByItem($aItem);
  237. bx_import('BxDolStudioLanguagesUtils');
  238. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aSet['title']);
  239. $aIdsAffected[] = $sId;
  240. $iAffected++;
  241. }
  242. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_sets_delete')));
  243. }
  244. function getJsObject() {
  245. return 'oBxDolStudioNavigationSets';
  246. }
  247. function getCode($isDisplayHeader = true) {
  248. return $this->_oTemplate->parseHtmlByName('nav_sets.html', array(
  249. 'content' => parent::getCode($isDisplayHeader),
  250. 'js_object' => $this->getJsObject(),
  251. 'grid_object' => $this->_sObject,
  252. 'params_divider' => $this->sParamsDivider
  253. ));
  254. }
  255. protected function _addJsCss() {
  256. parent::_addJsCss();
  257. $this->_oTemplate->addJs(array('jquery.form.js', 'navigation_sets.js'));
  258. bx_import('BxTemplStudioFormView');
  259. $oForm = new BxTemplStudioFormView(array());
  260. $oForm->addCssJs();
  261. }
  262. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow) {
  263. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  264. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  265. }
  266. protected function _getCellItems ($mixedValue, $sKey, $aField, $aRow) {
  267. $aSets = array();
  268. $this->oDb->getSets(array('type' => 'by_name', 'value' => $aRow['set_name']), $aSets, false);
  269. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  270. 'href' => sprintf($this->sUrlViewItems, $aRow['module'], $aRow['set_name']),
  271. 'title' => _t('_adm_nav_txt_manage_items'),
  272. 'bx_repeat:attrs' => array(),
  273. 'content' => _t('_adm_nav_txt_n_items', $aSets['items_count'])
  274. ));
  275. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  276. }
  277. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  278. if ($sType == 'single' && (int)$aRow['deletable'] != 1)
  279. return '';
  280. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  281. }
  282. protected function _getFilterControls () {
  283. parent::_getFilterControls();
  284. return $this->getModulesSelectAll('getSets') . $this->getSearchInput();
  285. }
  286. }
  287. /** @} */