BxBaseStudioNavigationSets.php 14 KB

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