コード例 #1
0
ファイル: Contact.class.php プロジェクト: Cloudrexx/cloudrexx
    /**
     * Inits the uploader when displaying a contact form.
     */
    protected function initUploader($fieldId, $restrictUpload2SingleFile = true)
    {
        try {
            $cx = \Cx\Core\Core\Controller\Cx::instanciate();
            $sessionObj = $cx->getComponent('Session')->getSession();
            $uploader = new \Cx\Core_Modules\Uploader\Model\Entity\Uploader();
            //set instance name so we are able to catch the instance with js
            $uploader->setCallback('contactFormUploader_' . $fieldId);
            $cx = \Cx\Core\Core\Controller\Cx::instanciate();
            // specifies the function to call when upload is finished. must be a static function
            $uploader->setFinishedCallback(array($cx->getCodeBaseCoreModulePath() . '/Contact/Controller/Contact.class.php', '\\Cx\\Core_Modules\\Contact\\Controller\\Contact', 'uploadFinished'));
            if ($restrictUpload2SingleFile) {
                $uploader->setData(array('singleFile' => $restrictUpload2SingleFile));
                $uploader->setUploadLimit(1);
            }
            $uploaderId = $uploader->getId();
            $uploader->setOptions(array('id' => 'contactUploader_' . $uploaderId, 'style' => 'display: none'));
            //initialize the widget displaying the folder contents
            $folderWidget = new \Cx\Core_Modules\MediaBrowser\Model\Entity\FolderWidget($_SESSION->getTempPath() . '/' . $uploaderId);
            $this->objTemplate->setVariable(array('CONTACT_UPLOADER_FOLDER_WIDGET_' . $fieldId => $folderWidget->getXhtml(), 'CONTACT_UPLOADER_ID_' . $fieldId => $uploaderId));
            $folderWidgetId = $folderWidget->getId();
            $strInputfield = $uploader->getXHtml();
            $strInputfield .= <<<CODE
            <script type="text/javascript">
            cx.ready(function() {
                    jQuery('#contactFormFieldId_{$fieldId}').bind('click', function() {
                        jQuery('#contactUploader_{$uploaderId}').trigger('click');
                        return false;
                    }).removeAttr('disabled');
            });

            //uploader javascript callback function
            function contactFormUploader_{$fieldId}(callback) {
                    angular.element('#mediaBrowserfolderWidget_{$folderWidgetId}').scope().refreshBrowser();
            }
            </script>
CODE;
            return $strInputfield;
        } catch (Exception $e) {
            return '<!-- failed initializing uploader, exception ' . get_class($e) . ' with message "' . $e->getMessage() . '" -->';
        }
    }