Exemplo n.º 1
0
 /**
  * Shows the field in the edit entry or add entry form
  * @param bool $return return or display directly
  * @return string
  */
 public function field($return = false)
 {
     if (!$this->enabled) {
         return false;
     }
     $class = $this->required ? $this->cssClass . ' required' : $this->cssClass;
     $show = null;
     $field = null;
     static $js = false;
     $params = array('id' => $this->nid, 'class' => $class);
     if ($this->width) {
         $params['style'] = "width: {$this->width}px;";
     }
     $files = $this->getExistingFiles();
     if (is_array($files) && count($files)) {
         if (isset($files['ico'])) {
             $show = $files['ico'];
         } elseif (isset($files['thumb'])) {
             $show = $files['thumb'];
         }
     }
     $noncropsize = "";
     $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80'));
     if ($show) {
         $img = Sobi::Cfg('live_site') . $show;
         if (!$this->crop) {
             $noncropsize = "style=\"width: {$icoSize[0]}px; height: {$icoSize[1]}px;\"";
         }
     }
     $field .= "\n<div class=\"spImageField\">";
     $field .= "\n<div>";
     $field .= "\n<div id=\"{$this->nid}_img_preview\" class=\"spEditImage\">";
     $field .= "\n<div class=\"spEditImagePreview\" >";
     if ($show) {
         $field .= "\n\t<img src=\"{$img}\" alt=\"{$this->name}\" {$noncropsize} />";
     }
     $field .= "\n</div>";
     $field .= "\n</div>";
     $field .= "\n</div>";
     $field .= "\n<div class=\"spImageUpDelete\">";
     if ($show) {
         $field .= SPHtml_Input::checkbox($this->nid . '_delete', 1, Sobi::Txt('FD.IMG_DELETE_CURRENT_IMAGE'), $this->nid . '_delete', false, array('class' => $this->cssClass));
     }
     $field .= SPHtml_Input::fileUpload($this->nid, 'image/*', null, 'spImageUpload', str_replace('field_', 'field.', $this->nid) . '.upload');
     $field .= "\n</div>";
     $field .= "\n</div>";
     if (!$js) {
         SPFactory::header()->addJsFile('opt.field_image_edit')->addJsCode('SobiPro.jQuery( document ).ready( function () { SobiPro.jQuery( ".spImageUpload" ).SPFileUploader(); } );');
         $js = true;
     }
     if ($this->crop) {
         $modalclass = 'modal hide';
         if (Sobi::Cfg('template.bootstrap3-styles') && !defined('SOBIPRO_ADM')) {
             $modalclass = 'modal fade';
         }
         SPFactory::header()->addJsFile('cropper')->addCssFile('cropper');
         $field .= SPHtml_Input::modalWindow(Sobi::Txt('IMAGE_CROP_HEADER'), $this->nid . '_modal', null, $modalclass, 'CLOSE', 'SAVE');
     }
     if (!$return) {
         echo $field;
     } else {
         return $field;
     }
 }
Exemplo n.º 2
0
 protected function tree()
 {
     $selector = null;
     $selectedCategories = array();
     $tree = SPFactory::Instance('mlo.tree', Sobi::Cfg('list.categories_ordering'), array('preventParents' => !$this->catsWithChilds));
     $tree->setHref('#');
     $tree->setTask('category.chooser');
     $tree->setId($this->nid);
     $tree->disable(Sobi::Section());
     $tree->init(Sobi::Section());
     $params = array();
     $params['maxcats'] = $this->catsMaxLimit;
     $params['field'] = $this->nid;
     $params['preventParents'] = !$this->catsWithChilds;
     $setheight = '';
     if ($this->height > 0) {
         $setheight = " style=\"height: {$this->height}px;\"";
     }
     $addBtParams = array('class' => 'btn');
     $delBtParams = array('class' => 'btn');
     $selectParams = array();
     SPFactory::header()->addJsFile('opt.field_category_tree')->addJsCode('SobiPro.jQuery( document ).ready( function () { new SigsiuTreeEdit( ' . json_encode($params) . '); } );');
     $selector = $selector . '<div class="tree"' . $setheight . '>' . $tree->display(true) . '</div>';
     if (count($this->_selectedCats)) {
         $selected = SPLang::translateObject($this->_selectedCats, 'name', 'category');
         if (count($selected)) {
             $count = 0;
             foreach ($selected as $category) {
                 if ($category['id'] == $this->sid && SPRequest::task() != 'entry.add') {
                     continue;
                 }
                 $selectedCategories[$category['id']] = $category['value'];
                 $count++;
                 if ($count == $this->catsMaxLimit) {
                     break;
                 }
             }
         }
     }
     if (count($selectedCategories) >= $this->catsMaxLimit) {
         $addBtParams['disabled'] = 'disabled';
         $selectParams['readonly'] = 'readonly';
     } elseif (!count($selectedCategories)) {
         $delBtParams['disabled'] = 'disabled';
     }
     $selector .= '<div class="selected">';
     $selector .= SPHtml_Input::select($this->nid . '_list', $selectedCategories, null, true, $selectParams);
     $selector .= SPHtml_Input::hidden($this->nid, 'json://' . json_encode(array_keys($selectedCategories)));
     $selector .= '</div>';
     $selector .= '<div class="buttons">';
     $selector .= SPHtml_Input::button('addCategory', Sobi::Txt('CC.ADD_BT'), $addBtParams);
     $selector .= SPHtml_Input::button('removeCategory', Sobi::Txt('CC.DEL_BT'), $delBtParams);
     $selector .= '</div>';
     $selector = '<div class="SigsiuTree" id="' . $this->nid . '_canvas">' . $selector . '</div>';
     if ($this->modal) {
         $selector = SPHtml_Input::modalWindow(Sobi::Txt('EN.SELECT_CAT_PATH'), $this->nid . '_modal', $selector, 'modaltree modal hide', 'CLOSE', null);
         $field = SPHtml_Input::button('select-category', Sobi::Txt('EN.SELECT_CAT_PATH'), array('class' => 'btn btn-primary', 'href' => '#' . $this->nid . '_modal', 'data-toggle' => 'modal', 'id' => $this->nid . '_modal_fire'));
         return $field . $selector;
     } else {
         return $selector;
     }
 }