Ejemplo n.º 1
0
 /**
  * Method to get the field input markup.
  *
  * @return  string    The field input markup.
  */
 protected function getInput()
 {
     static $fabrikElements;
     if (!isset($fabrikElements)) {
         $fabrikElements = array();
     }
     $src[] = 'administrator/components/com_fabrik/views/namespace.js';
     $c = (int) @$this->form->repeatCounter;
     $table = $this->getAttribute('table');
     if ($table == '') {
         $table = $this->form->getValue('params.list_id');
     }
     $includeCalculations = (int) $this->getAttribute('include_calculations');
     $published = (int) $this->getAttribute('published');
     $showInTable = (int) $this->getAttribute('showintable');
     $highlightPk = FabrikWorker::toBoolean($this->getAttribute('highlightpk', false), false);
     $mode = $this->getAttribute('mode');
     $connection = $this->getAttribute('connection');
     $connectionInRepeat = FabrikWorker::toBoolean($this->getAttribute('connection_in_repeat', true), true);
     $excludeJoined = (int) $this->getAttribute('excludejoined');
     if ($includeCalculations != 1) {
         $includeCalculations = 0;
     }
     $opts = new stdClass();
     if ($this->form->repeat) {
         // In repeat fieldset/group
         $conn = $connection . '-' . $this->form->repeatCounter;
         $opts->table = 'jform_' . $table . '-' . $this->form->repeatCounter;
     } else {
         $conn = $c === false || !$connectionInRepeat ? $connection : $connection . '-' . $c;
         $opts->table = $c === false || !$connectionInRepeat ? 'jform_' . $table : 'jform_' . $table . '-' . $c;
     }
     $opts->published = $published;
     $opts->showintable = $showInTable;
     $opts->excludejoined = $excludeJoined;
     $opts->livesite = COM_FABRIK_LIVESITE;
     $opts->conn = 'jform_' . $conn;
     $opts->value = $this->value;
     $opts->include_calculations = $includeCalculations;
     $opts->highlightpk = (int) $highlightPk;
     $opts = json_encode($opts);
     $script = array();
     $script[] = "var p = new elementElement('{$this->id}', {$opts});";
     $script[] = "FabrikAdmin.model.fields.element['{$this->id}'] = p;";
     $script = implode("\n", $script);
     $fabrikElements[$this->id] = true;
     $src[] = 'administrator/components/com_fabrik/models/fields/element.js';
     FabrikHelperHTML::script($src, $script);
     if ($mode === 'gui') {
         $return = $this->gui();
     } else {
         $return = parent::getInput();
         $return .= '<img style="margin-left:10px;display:none" id="' . $this->id . '_loader" src="components/com_fabrik/images/ajax-loader.gif" alt="' . FText::_('COM_FABRIK_LOADING') . '" />';
     }
     FabrikHelperHTML::framework();
     FabrikHelperHTML::iniRequireJS();
     return $return;
 }
Ejemplo n.º 2
0
 /**
  * Method to get the field input markup.
  *
  * @return  string    The field input markup.
  */
 protected function getInput()
 {
     $c = isset($this->form->repeatCounter) ? (int) $this->form->repeatCounter : 0;
     $connectionDd = $this->getAttribute('observe');
     $connectionInRepeat = FabrikWorker::toBoolean($this->getAttribute('connection_in_repeat', 'true'), true);
     $script = array();
     if (!isset($fabrikTables)) {
         $fabrikTables = array();
     }
     if ($connectionDd != '' && !array_key_exists($this->id, $fabrikTables)) {
         $repeatCounter = empty($this->form->repeatCounter) ? 0 : $this->form->repeatCounter;
         if ($this->form->repeat) {
             // In repeat fieldset/group
             $connectionDd = $connectionDd . '-' . $repeatCounter;
         } else {
             $connectionDd = $c === false || !$connectionInRepeat ? $connectionDd : $connectionDd . '-' . $c;
         }
         $opts = new stdClass();
         $opts->livesite = COM_FABRIK_LIVESITE;
         $opts->conn = 'jform_' . $connectionDd;
         $opts->value = $this->value;
         $opts->connInRepeat = $connectionInRepeat;
         $opts->inRepeatGroup = $this->form->repeat;
         $opts->repeatCounter = $repeatCounter;
         $opts->container = 'test';
         $opts = json_encode($opts);
         $script[] = "var p = new fabriktablesElement('{$this->id}', {$opts});";
         $script[] = "FabrikAdmin.model.fields.fabriktable['{$this->id}'] = p;";
         $fabrikTables[$this->id] = true;
         $src['Fabrik'] = 'media/com_fabrik/js/fabrik.js';
         $src['Namespace'] = 'administrator/components/com_fabrik/views/namespace.js';
         $src['FabrikTables'] = 'administrator/components/com_fabrik/models/fields/fabriktables.js';
         FabrikHelperHTML::script($src, $script);
     }
     $html = parent::getInput();
     $html .= '<img style="margin-left:10px;display:none" id="' . $this->id . '_loader" src="components/com_fabrik/images/ajax-loader.gif" alt="' . FText::_('LOADING') . '" />';
     FabrikHelperHTML::framework();
     FabrikHelperHTML::iniRequireJS();
     return $html;
 }
Ejemplo n.º 3
0
 /**
  * Load the element list from the group id
  *
  * @param   int $groupId Group id
  *
  * @since   3.0.6
  *
  * @return array
  */
 protected function loadFromGroupId($groupId)
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $controller = $input->get('view', $input->get('task'));
     $valueFormat = (string) $this->getAttribute('valueformat', 'id');
     $onlyListFields = (int) $this->getAttribute('onlylistfields', 0);
     $filter = (string) $this->getAttribute('filter', '');
     $pluginFilters = trim($filter) == '' ? array() : explode('|', $filter);
     $labelMethod = (string) $this->getAttribute('label_method');
     $noJoins = FabrikWorker::toBoolean($this->getAttribute('nojoins', false), false);
     $bits = array();
     $showRaw = FabrikWorker::toBoolean($this->getAttribute('raw', false), false);
     /** @var FabrikFEModelGroup $groupModel */
     $groupModel = JModelLegacy::getInstance('Group', 'FabrikFEModel');
     $groupModel->setId($groupId);
     $optsKey = $valueFormat == 'tableelement' ? 'name' : 'id';
     $useStep = FabrikWorker::toBoolean($this->getAttribute('usestep', false), false);
     $hash = $controller . '.' . implode('.', $bits);
     if (array_key_exists($hash, $this->results)) {
         $res = $this->results[$hash];
     } else {
         $res = $groupModel->getFormModel()->getElementOptions($useStep, $optsKey, $onlyListFields, $showRaw, $pluginFilters, $labelMethod, $noJoins);
         $this->results[$hash] =& $res;
     }
     return $res;
 }
Ejemplo n.º 4
0
    /**
     * Method to get the field input markup for the editor area
     *
     * @return  string  The field input markup.
     *
     * @since   1.6
     */
    protected function getInput()
    {
        // Initialize some field attributes.
        $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
        $disabled = (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : '';
        $columns = $this->element['cols'] ? ' cols="' . (int) $this->element['cols'] . '"' : '';
        $rows = $this->element['rows'] ? ' rows="' . (int) $this->element['rows'] . '"' : '';
        $required = $this->required ? ' required="required" aria-required="true"' : '';
        // JS events are saved as encoded html - so we don't want to double encode them
        $encoded = FabrikWorker::toBoolean($this->getAttribute('encoded', false), false);
        if (!$encoded) {
            $this->value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
        }
        $onChange = FabrikWorker::toBoolean($this->getAttribute('onchange', false), false);
        $onChange = $onChange ? ' onchange="' . (string) $onChange . '"' : '';
        // Joomla 3 version
        FabrikWorker::toBoolean($this->getAttribute('highlightpk', false), false);
        $mode = $this->getAttribute('mode', 'html');
        $theme = $this->getAttribute('theme', 'github');
        $height = $this->getAttribute('height', '300px');
        $width = $this->getAttribute('width', '100%');
        $maxHeight = $this->getAttribute('max-height', str_ireplace('px', '', $height) * 2 . 'px');
        $editor = '<textarea name="' . $this->name . '" id="' . $this->id . '"' . $columns . $rows . $class . $disabled . $onChange . $required . '>' . $this->value . '</textarea>';
        $version = new JVersion();
        if ($version->RELEASE == 2.5) {
            return $editor;
        }
        FabrikHelperHTML::framework();
        FabrikHelperHTML::iniRequireJS();
        if ($mode === 'php') {
            $aceMode = '{path:"ace/mode/php", inline:true}';
        } else {
            $aceMode = '"ace/mode/' . $mode . '"';
        }
        $minHeight = str_ireplace('px', '', $height);
        $maxHeight = str_ireplace('px', '', $maxHeight);
        /**
         * In code below...
         *   the +/- 2 is to account for the top/bottom border of 1px each
         *
         *   pluginmanager.js renames names/ids when you delete a preceding plugin which breaks ace
         *   so we need to keep ace-ids intact and avoid issues with duplicate ids by:
         *       adding a random string to the id where ace needs id to be kept the same; and
         *       save dom object for textarea so that change of id doesn't break it.
         **/
        $aceId = $this->id . '_' . sprintf("%06x", mt_rand(0, 0xffffff));
        $script = '
window.addEvent(\'domready\', function () {
	if (Fabrik.debug) {
		fconsole("Fabrik editor initialising: ' . $this->id . '");
	}
	var field = document.id("' . $this->id . '");
	var FbEditor = ace.edit("' . $aceId . '-ace");
	FbEditor.setTheme("ace/theme/' . $theme . '");
	FbEditor.getSession().setMode(' . $aceMode . ');
	FbEditor.setValue(field.value);
	FbEditor.navigateFileStart();
	FbEditor.setAnimatedScroll(true);
	FbEditor.setBehavioursEnabled(true);
	FbEditor.setDisplayIndentGuides(true);
	FbEditor.setHighlightGutterLine(true);
	FbEditor.setHighlightSelectedWord(true);
	FbEditor.setShowFoldWidgets(true);
	FbEditor.setWrapBehavioursEnabled(true);
	FbEditor.getSession().setUseWrapMode(true);
	FbEditor.getSession().setTabSize(2);
	FbEditor.on("blur", function () {
		if (field.value !== FbEditor.getValue()) {
			field.value = FbEditor.getValue();
			field.fireEvent("change", field);
		}
		field.fireEvent("blur", field);
	});
	var maxlines = Math.floor((' . $maxHeight . ' - 2) / FbEditor.renderer.lineHeight);
	var updateHeight = function () {
		var s = FbEditor.getSession();
		var r = FbEditor.renderer;
		var l = s.getScreenLength();
		var h = (l > maxlines ? maxlines : l)
		      * r.lineHeight
		      + (r.$horizScroll ? r.scrollBar.getWidth() : 0)
		      + 2;
		h = h < ' . $minHeight . ' ? ' . $minHeight . ' : h;
		c = document.id("' . $aceId . '-aceContainer").getStyle("height").toInt();
		if (c !== h) {
			document.id("' . $aceId . '-aceContainer").setStyle("height", h.toString() + "px");
			FbEditor.resize();
		}
	}
	updateHeight();
	FbEditor.getSession().on("change", updateHeight);
});
		';
        $src = array('media/com_fabrik/js/lib/ace/src-min-noconflict/ace.js', 'media/com_fabrik/js/fabrik.js');
        FabrikHelperHTML::script($src, $script);
        echo '<style type="text/css" media="screen">
	#' . $aceId . '-ace {
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		border: 1px solid #c0c0c0;
		border-radius: 3px;
	}

	#' . $aceId . '-aceContainer {
		position: relative;
		width: ' . $width . ';
		height: ' . $height . ';
	}
</style>';
        $this->element['cols'] = 1;
        $this->element['rows'] = 1;
        // For element js event code.
        return '<div id="' . $aceId . '-aceContainer"><div id="' . $aceId . '-ace"></div>' . $editor . '</div>';
    }