Exemple #1
0
 /**
  * HTML view display method
  *
  * @param   string  $tpl  The name of the template file to parse
  * @return  void
  * @since   1.5.5
  */
 public function display($tpl = null)
 {
     $item = $this->get('Data');
     $isNew = $item->id < 1;
     $rating = 0.0;
     // Get the form and fill the fields
     $form = $this->get('Form');
     if ($isNew) {
         // Set some field attributes for javascript validation
         $form->setFieldAttribute('detail_catid', 'required', true);
         $form->setFieldAttribute('detail_catid', 'validate', 'joompositivenumeric');
         $form->setFieldAttribute('thumb_catid', 'required', true);
         $form->setFieldAttribute('thumb_catid', 'validate', 'joompositivenumeric');
         $form->setFieldAttribute('imgfilename', 'required', true);
         $form->setFieldAttribute('imgthumbname', 'required', true);
         // Detail images
         $detail_catpath = JoomHelper::getCatPath($item->detail_catid);
         $detail_path = $this->_ambit->get('img_path') . $detail_catpath;
         $form->setFieldAttribute('imgfilename', 'directory', $detail_path);
         $imgfilename_field = $this->_findFieldByFieldName($form, 'imgfilename');
         $imagelib_field = $this->_findFieldByFieldName($form, 'imagelib2');
         // Thumbnail images
         $thumb_catpath = JoomHelper::getCatPath($item->thumb_catid);
         $thumb_path = $this->_ambit->get('thumb_path') . $thumb_catpath;
         $form->setFieldAttribute('imgthumbname', 'directory', $thumb_path);
         $imgthumbname_field = $this->_findFieldByFieldName($form, 'imgthumbname');
         $imagelib_field = $this->_findFieldByFieldName($form, 'imagelib');
     } else {
         if ($item->imgvotes > 0) {
             $rating = JoomHelper::getRating($item->id);
         }
     }
     // Bind the data to the form
     $form->bind($item);
     // Set some form fields manually
     if ($isNew) {
         // Does the original image file exist
         if ($form->getValue('imgfilename', null) == '') {
             $form->setValue('original_exists', null, JText::_('COM_JOOMGALLERY_IMGMAN_NO_IMAGE_SELECTED'));
         } else {
             if (JFile::exists($this->_ambit->getImg('orig_path', $item->imgfilename, null, $item->detail_catid))) {
                 $orig_msg = JText::_('COM_JOOMGALLERY_IMGMAN_ORIGINAL_EXIST');
                 $color = 'green';
             } else {
                 $orig_msg = JText::_('COM_JOOMGALLERY_IMGMAN_ORIGINAL_NOT_EXIST');
                 $color = 'red';
             }
             $form->setValue('original_exists', null, $orig_msg);
             $original_exists_field = $this->_findFieldByFieldName($form, 'original_exists');
             $js = "\n        window.addEvent('domready', function() {\n          \$('" . $original_exists_field->id . "').setStyle('color', '" . $color . "');\n        });";
             $this->_doc->addScriptDeclaration($js);
         }
     } else {
         // Plublished and hidden state
         if ($item->published) {
             $form->setValue('publishhiddenstate', null, $item->hidden ? JText::_('COM_JOOMGALLERY_COMMON_PUBLISHED_BUT_HIDDEN') : JText::_('COM_JOOMGALLERY_COMMON_STATE_PUBLISHED'));
         } else {
             $form->setValue('publishhiddenstate', null, JText::_('COM_JOOMGALLERY_COMMON_STATE_UNPUBLISHED'));
         }
         // Rating
         $form->setValue('rating', null, JText::sprintf('COM_JOOMGALLERY_IMGMAN_IMAGE_VOTES', $rating, $item->imgvotes));
         // Date
         $form->setValue('date', null, JHTML::_('date', $item->imgdate, JText::_('DATE_FORMAT_LC2')));
     }
     // Set image source for detail image preview
     if ($item->imgfilename) {
         if ($isNew) {
             // We have to look for the image ID fist because the image may have to be output through the script
             $id = $this->getModel()->getIdByFilename($item->imgfilename, $item->detail_catid);
             $imgsource = $this->_ambit->getImg('img_url', $id);
         } else {
             $imgsource = $this->_ambit->getImg('img_url', $item);
         }
     } else {
         $imgsource = '../media/system/images/blank.png';
     }
     $form->setValue('imagelib2', null, $imgsource);
     // Set image source for thumbnail preview
     if ($item->imgthumbname) {
         if ($isNew) {
             // We have to look for the image ID fist because the image may have to be output through the script
             $id = $this->getModel()->getIdByFilename($item->imgthumbname, $item->thumb_catid, true);
             $thumbsource = $this->_ambit->getImg('thumb_url', $id);
         } else {
             $thumbsource = $this->_ambit->getImg('thumb_url', $item);
         }
     } else {
         $thumbsource = '../media/system/images/blank.png';
     }
     $form->setValue('imagelib', null, $thumbsource);
     $this->assignRef('item', $item);
     $this->assignRef('isNew', $isNew);
     $this->assignRef('form', $form);
     $this->addToolbar();
     parent::display($tpl);
 }