BxBaseStudioGridStorages.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  8. * @{
  9. */
  10. class BxBaseStudioGridStorages extends BxDolStudioGridStorages
  11. {
  12. public function __construct($aOptions, $oTemplate = false)
  13. {
  14. parent::__construct($aOptions, $oTemplate);
  15. }
  16. public function getCode($isDisplayHeader = true)
  17. {
  18. return $this->_oTemplate->parseHtmlByName('strg_' . $this->_sType . '.html', array(
  19. 'content' => parent::getCode($isDisplayHeader),
  20. 'js_object' => $this->getJsObject(),
  21. 'page' => $this->_sType,
  22. 'grid_object' => $this->_sObject,
  23. 'params_divider' => $this->sParamsDivider
  24. ));
  25. }
  26. public function performActionAdd()
  27. {
  28. $sAction = 'add';
  29. $oForm = $this->_getFormObject($sAction);
  30. $oForm->initChecker();
  31. if($oForm->isSubmittedAndValid()) {
  32. $iProfileId = bx_get_logged_profile_id();
  33. $aFiles = $oForm->getCleanValue($this->_sType);
  34. if(!empty($aFiles) && is_array($aFiles)) {
  35. foreach($aFiles as $iFileId)
  36. $this->_oStorage->updateGhostsContentId($iFileId, $iProfileId, time());
  37. $aRes = array('grid' => $this->getCode(false), 'blink' => $aFiles);
  38. }
  39. else
  40. $aRes = array('msg' => _t($this->_aT['err_files_add']));
  41. echoJson($aRes);
  42. }
  43. else {
  44. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-strg-' . $this->_sType . '-add-popup', _t($this->_aT['txt_files_add_popup']), $this->_oTemplate->parseHtmlByName('strg_add_' . $this->_sType . '.html', array(
  45. 'form_id' => $oForm->aFormAttrs['id'],
  46. 'form' => $oForm->getCode(true),
  47. 'object' => $this->_sObject,
  48. 'action' => $sAction
  49. )));
  50. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  51. }
  52. }
  53. public function performActionDelete()
  54. {
  55. $aIds = bx_get('ids');
  56. if(!$aIds || !is_array($aIds)) {
  57. echoJson(array());
  58. exit;
  59. }
  60. $iAffected = $this->_oStorage->queueFilesForDeletion($aIds);
  61. if($iAffected > 0)
  62. $aRes = array('msg' => _t($this->_aT['msg_files_delete']), 'grid' => $this->getCode(false));
  63. else
  64. $aRes = array('msg' => _t($this->_aT['err_files_delete']));
  65. echoJson($aRes);
  66. }
  67. protected function _addJsCss()
  68. {
  69. $oTemplate = BxDolStudioTemplate::getInstance();
  70. foreach($this->_aUploaders as $sUploader) {
  71. $oUploader = BxDolUploader::getObjectInstance($sUploader, $this->_sStorage, '', $oTemplate);
  72. if($oUploader)
  73. $oUploader->addCssJs();
  74. }
  75. $oForm = new BxTemplStudioFormView(array());
  76. $oForm->addCssJs();
  77. parent::_addJsCss();
  78. $this->_oTemplate->addJs(array('jquery.form.min.js'));
  79. $this->_oTemplate->addCss(array('storages.css'));
  80. }
  81. protected function _getCellPath ($mixedValue, $sKey, $aField, $aRow)
  82. {
  83. $sValue = $this->_oStorage->getFileUrlById($aRow['id']);
  84. $aValue = $this->_limitMaxLength($sValue, $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow, false);
  85. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  86. 'href' => $sValue,
  87. 'title' => _t('_adm_strg_txt_download'),
  88. 'bx_repeat:attrs' => array(
  89. array('key' => 'target', 'value' => '_blank')
  90. ),
  91. 'content' => $aValue[0]
  92. )) . (isset($aValue[1]) ? $aValue[1] : '');
  93. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  94. }
  95. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  96. {
  97. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  98. }
  99. protected function _getFormObject($sAction)
  100. {
  101. bx_import('BxTemplStudioFormView');
  102. $aForm = array(
  103. 'form_attrs' => array(
  104. 'id' => 'adm-strg-' . $this->_sType . '-' . $sAction,
  105. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  106. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  107. ),
  108. 'params' => array (
  109. 'db' => array(
  110. 'table' => '',
  111. 'key' => '',
  112. 'uri' => '',
  113. 'uri_title' => '',
  114. 'submit_name' => 'do_submit'
  115. ),
  116. ),
  117. 'inputs' => array (
  118. $this->_sType => array(
  119. 'type' => 'files',
  120. 'name' => $this->_sType,
  121. 'storage_object' => $this->_sStorage,
  122. 'images_transcoder' => $this->_sTranscoder,
  123. 'uploaders' => $this->_aUploaders,
  124. 'multiple' => true,
  125. 'content_id' => 0,
  126. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('strg_fgt_' . $this->_sType . '.html', array(
  127. 'name' => $this->_sType . '[]'
  128. )),
  129. 'caption' => ''
  130. ),
  131. 'controls' => array(
  132. 'name' => 'controls',
  133. 'type' => 'input_set',
  134. array(
  135. 'type' => 'submit',
  136. 'name' => 'do_submit',
  137. 'value' => _t('_adm_strg_btn_add'),
  138. ),
  139. array (
  140. 'type' => 'reset',
  141. 'name' => 'close',
  142. 'value' => _t('_adm_strg_btn_cancel'),
  143. 'attrs' => array(
  144. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  145. 'class' => 'bx-def-margin-sec-left',
  146. ),
  147. )
  148. )
  149. )
  150. );
  151. return new BxTemplStudioFormView($aForm);
  152. }
  153. }
  154. /** @} */