1
0

BxBaseStudioGridStorages.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  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. echoJson(array('grid' => $this->getCode(false), 'blink' => $aFiles));
  38. }
  39. }
  40. else {
  41. $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(
  42. 'form_id' => $oForm->aFormAttrs['id'],
  43. 'form' => $oForm->getCode(true),
  44. 'object' => $this->_sObject,
  45. 'action' => $sAction
  46. )));
  47. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  48. }
  49. }
  50. public function performActionDelete()
  51. {
  52. $aIds = bx_get('ids');
  53. if(!$aIds || !is_array($aIds)) {
  54. echoJson(array());
  55. exit;
  56. }
  57. $iAffected = $this->_oStorage->queueFilesForDeletion($aIds);
  58. if($iAffected > 0)
  59. $aRes = array('msg' => _t($this->_aT['msg_files_delete']), 'grid' => $this->getCode(false));
  60. else
  61. $aRes = array('msg' => _t($this->_aT['err_files_delete']));
  62. echoJson($aRes);
  63. }
  64. protected function _addJsCss()
  65. {
  66. $oTemplate = BxDolStudioTemplate::getInstance();
  67. foreach($this->_aUploaders as $sUploader) {
  68. $oUploader = BxDolUploader::getObjectInstance($sUploader, $this->_sStorage, '', $oTemplate);
  69. if($oUploader)
  70. $oUploader->addCssJs();
  71. }
  72. $oForm = new BxTemplStudioFormView(array());
  73. $oForm->addCssJs();
  74. parent::_addJsCss();
  75. $this->_oTemplate->addJs(array('jquery.form.min.js'));
  76. $this->_oTemplate->addCss(array('storages.css'));
  77. }
  78. protected function _getCellPath ($mixedValue, $sKey, $aField, $aRow)
  79. {
  80. $oForm = new BxTemplStudioFormView(array());
  81. $aInput = array(
  82. 'type' => 'text',
  83. 'name' => 'url-' . $aRow['id'],
  84. 'value' => $this->_oStorage->getFileUrlById($aRow['id']),
  85. 'attrs' => array(
  86. 'readonly' => 1
  87. ),
  88. 'tr_attrs' => array(
  89. 'class' => 'bx-strg-field-url',
  90. ),
  91. );
  92. return parent::_getCellDefault($oForm->genRow($aInput), $sKey, $aField, $aRow);
  93. }
  94. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  95. {
  96. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  97. }
  98. protected function _getActionDownload ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  99. {
  100. $sUrl = $this->_oStorage->getFileUrlById($aRow['id']);
  101. unset($a['attr']['bx_grid_action_single']);
  102. $a['attr'] = array_merge($a['attr'], array(
  103. "onclick" => "window.open('" . $sUrl . "','_blank');"
  104. ));
  105. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  106. }
  107. protected function _getFormObject($sAction)
  108. {
  109. bx_import('BxTemplStudioFormView');
  110. $aForm = array(
  111. 'form_attrs' => array(
  112. 'id' => 'adm-strg-' . $this->_sType . '-' . $sAction,
  113. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  114. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  115. ),
  116. 'params' => array (
  117. 'db' => array(
  118. 'table' => '',
  119. 'key' => '',
  120. 'uri' => '',
  121. 'uri_title' => '',
  122. 'submit_name' => 'do_submit'
  123. ),
  124. ),
  125. 'inputs' => array (
  126. $this->_sType => array(
  127. 'type' => 'files',
  128. 'name' => $this->_sType,
  129. 'storage_object' => $this->_sStorage,
  130. 'images_transcoder' => $this->_sTranscoder,
  131. 'uploaders' => $this->_aUploaders,
  132. 'multiple' => true,
  133. 'content_id' => 0,
  134. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('strg_fgt_' . $this->_sType . '.html', array(
  135. 'name' => $this->_sType . '[]'
  136. )),
  137. 'caption' => ''
  138. ),
  139. 'submit' => array(
  140. 'type' => 'submit',
  141. 'name' => 'do_submit',
  142. 'value' => _t('_adm_strg_btn_done'),
  143. )
  144. )
  145. );
  146. return new BxTemplStudioFormView($aForm);
  147. }
  148. }
  149. /** @} */