From 1a538e71d76dd9bf08c9758db7b976978ab2424a Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Thu, 31 Jan 2019 23:44:21 +0200 Subject: [PATCH] Added buttons to edit cutomcode directly from where it is added in other areas around the component. This will improve the customcode workflow in JCB. --- README.md | 4 +- admin/README.txt | 4 +- admin/controllers/ajax.json.php | 39 ++++ admin/helpers/componentbuilder.php | 100 +++++++++ .../en-GB/en-GB.com_componentbuilder.ini | 1 + admin/models/admin_fields_relations.php | 31 +++ admin/models/admin_view.php | 2 +- admin/models/ajax.php | 122 ++++++++++- admin/models/component_dashboard.php | 30 +++ admin/models/custom_admin_view.php | 2 +- admin/models/custom_code.php | 31 +++ admin/models/dynamic_get.php | 2 +- admin/models/field.php | 2 +- admin/models/fieldtype.php | 30 +++ admin/models/forms/admin_fields_relations.js | 44 ++++ admin/models/forms/admin_view.js | 189 +++++++++++------- admin/models/forms/component_dashboard.js | 48 ++++- admin/models/forms/custom_admin_view.js | 41 ++++ admin/models/forms/custom_code.js | 47 ++++- admin/models/forms/dynamic_get.js | 85 ++++++-- admin/models/forms/field.js | 139 ++++++++----- admin/models/forms/fieldtype.js | 48 ++++- admin/models/forms/joomla_component.js | 42 +++- admin/models/forms/layout.js | 44 ++++ admin/models/forms/library.js | 146 +++++++++----- admin/models/forms/site_view.js | 41 ++++ admin/models/forms/template.js | 44 ++++ admin/models/forms/validation_rule.js | 42 ++++ admin/models/joomla_component.php | 2 +- admin/models/joomla_components.php | 9 +- admin/models/language_translation.php | 2 +- admin/models/layout.php | 2 +- admin/models/library.php | 2 +- admin/models/site_view.php | 2 +- admin/models/template.php | 2 +- admin/models/validation_rule.php | 2 +- .../admin_fields_relations/view.html.php | 6 +- admin/views/admin_view/view.html.php | 4 +- admin/views/component_dashboard/view.html.php | 10 +- admin/views/custom_admin_view/view.html.php | 4 +- admin/views/custom_code/view.html.php | 4 + admin/views/dynamic_get/view.html.php | 4 +- admin/views/field/view.html.php | 4 +- admin/views/fieldtype/view.html.php | 58 +++++- admin/views/joomla_component/view.html.php | 4 +- admin/views/layout/view.html.php | 4 +- admin/views/library/view.html.php | 4 +- admin/views/site_view/view.html.php | 4 +- admin/views/template/view.html.php | 4 +- admin/views/validation_rule/view.html.php | 4 +- componentbuilder.xml | 2 +- site/helpers/componentbuilder.php | 100 +++++++++ 52 files changed, 1407 insertions(+), 236 deletions(-) diff --git a/README.md b/README.md index 9735cf1d9..c23d89aab 100644 --- a/README.md +++ b/README.md @@ -144,11 +144,11 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 30th January, 2019 ++ *Last Build*: 31st January, 2019 + *Version*: 2.9.10 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **194699** ++ *Line count*: **195869** + *Field count*: **1089** + *File count*: **1277** + *Folder count*: **201** diff --git a/admin/README.txt b/admin/README.txt index 9735cf1d9..c23d89aab 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -144,11 +144,11 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 30th January, 2019 ++ *Last Build*: 31st January, 2019 + *Version*: 2.9.10 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **194699** ++ *Line count*: **195869** + *Field count*: **1089** + *File count*: **1277** + *Folder count*: **201** diff --git a/admin/controllers/ajax.json.php b/admin/controllers/ajax.json.php index 0ac05027c..b4bd9365c 100644 --- a/admin/controllers/ajax.json.php +++ b/admin/controllers/ajax.json.php @@ -45,6 +45,7 @@ class ComponentbuilderControllerAjax extends JControllerLegacy $this->registerTask('getDynamicValues', 'ajax'); $this->registerTask('checkFunctionName', 'ajax'); $this->registerTask('usedin', 'ajax'); + $this->registerTask('getEditCustomCodeButtons', 'ajax'); $this->registerTask('getExistingValidationRuleCode', 'ajax'); $this->registerTask('getValidationRulesTable', 'ajax'); $this->registerTask('checkRuleName', 'ajax'); @@ -838,6 +839,44 @@ class ComponentbuilderControllerAjax extends JControllerLegacy } } break; + case 'getEditCustomCodeButtons': + try + { + $returnRaw = $jinput->get('raw', false, 'BOOLEAN'); + $idValue = $jinput->get('id', NULL, 'INT'); + if($idValue && $user->id != 0) + { + $result = $this->getModel('ajax')->getEditCustomCodeButtons($idValue); + } + else + { + $result = false; + } + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback . "(".json_encode($result).");"; + } + elseif($returnRaw) + { + echo json_encode($result); + } + else + { + echo "(".json_encode($result).");"; + } + } + catch(Exception $e) + { + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback."(".json_encode($e).");"; + } + else + { + echo "(".json_encode($e).");"; + } + } + break; case 'getExistingValidationRuleCode': try { diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index 7421ad656..35d3dbfbb 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -4050,6 +4050,106 @@ abstract class ComponentbuilderHelper return ''; } + /** + * Get an edit text button + * + * @param string $text The button text + * @param int $item The item to edit + * @param string $view The type of item to edit + * @param string $views The list view controller name + * @param string $ref The return path + * @param string $component The component these views belong to + * @param string $headsup The message to show on click of button + * + * @return string On success the full html link + * + */ + public static function getEditTextButton($text, &$item, $view, $views, $ref = '', $component = 'com_componentbuilder', $jRoute = true, $class = 'uk-button', $headsup = 'COM_COMPONENTBUILDER_ALL_UNSAVED_WORK_ON_THIS_PAGE_WILL_BE_LOST_ARE_YOU_SURE_YOU_WANT_TO_CONTINUE') + { + // make sure we have text + if (!self::checkString($text)) + { + return self::getEditButton($item, $view, $views, $ref, $component, $headsup); + } + // get URL + $url = self::getEditURL($item, $view, $views, $ref, $component, $jRoute); + // check if we found any + if (self::checkString($url)) + { + // get the global settings + if (!self::checkObject(self::$params)) + { + self::$params = JComponentHelper::getParams('com_componentbuilder'); + } + // get UIKIT version + $uikit = self::$params->get('uikit_version', 2); + // check that we have the ID + if (self::checkObject($item) && isset($item->id)) + { + // check if the checked_out is available + if (isset($item->checked_out)) + { + $checked_out = (int) $item->checked_out; + } + } + elseif (self::checkArray($item) && isset($item['id'])) + { + // check if the checked_out is available + if (isset($item['checked_out'])) + { + $checked_out = (int) $item['checked_out']; + } + } + // set the link title + $title = self::safeString(JText::_('COM_COMPONENTBUILDER_EDIT') . ' ' . $view, 'W'); + // check that there is a check message + if (self::checkString($headsup)) + { + if (3 == $uikit) + { + $href = 'onclick="UIkit.modal.confirm(\''.JText::_($headsup).'\').then( function(){ window.location.href = \'' . $url . '\' } )" href="javascript:void(0)"'; + } + else + { + $href = 'onclick="UIkit2.modal.confirm(\''.JText::_($headsup).'\', function(){ window.location.href = \'' . $url . '\' })" href="javascript:void(0)"'; + } + } + else + { + $href = 'href="' . $url . '"'; + } + // return UIKIT version 3 + if (3 == $uikit) + { + // check if it is checked out + if (isset($checked_out) && $checked_out > 0) + { + // is this user the one who checked it out + if ($checked_out == JFactory::getUser()->id) + { + return ' ' . $text . ''; + } + return ' ' . $text . ''; + } + // return normal edit link + return ' ' . $text . ''; + } + // check if it is checked out (return UIKIT version 2) + if (isset($checked_out) && $checked_out > 0) + { + // is this user the one who checked it out + if ($checked_out == JFactory::getUser()->id) + { + return ' ' . $text . ''; + } + return ' ' . $text . ''; + } + // return normal edit link + return ' ' . $text . ''; + } + return ''; + } + /** * Get the edit URL * diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.ini b/admin/language/en-GB/en-GB.com_componentbuilder.ini index 9dd6c7536..8a5c5cd38 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.ini @@ -3718,6 +3718,7 @@ COM_COMPONENTBUILDER_CUSTOM_CODE_NOTE_PLACEHOLDERS_EXPLAINED_DESCRIPTION=" + diff --git a/admin/models/admin_fields_relations.php b/admin/models/admin_fields_relations.php index 6fc966ac0..30027d55b 100644 --- a/admin/models/admin_fields_relations.php +++ b/admin/models/admin_fields_relations.php @@ -50,6 +50,11 @@ class ComponentbuilderModelAdmin_fields_relations extends JModelAdmin $this->addTablePath(JPATH_ADMINISTRATOR . '/components/com_componentbuilder/tables'); // get instance of the table return JTable::getInstance($type, $prefix, $config); + } + + public function getVDM() + { + return $this->vastDevMod; } /** @@ -87,6 +92,32 @@ class ComponentbuilderModelAdmin_fields_relations extends JModelAdmin $addrelations = new Registry; $addrelations->loadString($item->addrelations); $item->addrelations = $addrelations->toArray(); + } + + + if (empty($item->id)) + { + $id = 0; + } + else + { + $id = $item->id; + } + // set the id and view name to session + if ($vdm = ComponentbuilderHelper::get('admin_fields_relations__'.$id)) + { + $this->vastDevMod = $vdm; + } + else + { + // set the vast development method key + $this->vastDevMod = ComponentbuilderHelper::randomkey(50); + ComponentbuilderHelper::set($this->vastDevMod, 'admin_fields_relations__'.$id); + ComponentbuilderHelper::set('admin_fields_relations__'.$id, $this->vastDevMod); + // set a return value if found + $jinput = JFactory::getApplication()->input; + $return = $jinput->get('return', null, 'base64'); + ComponentbuilderHelper::set($this->vastDevMod . '__return', $return); } if (!empty($item->id)) diff --git a/admin/models/admin_view.php b/admin/models/admin_view.php index 23d4f3099..1a5cab6d0 100644 --- a/admin/models/admin_view.php +++ b/admin/models/admin_view.php @@ -366,7 +366,7 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('admin_view__'.$id)) { diff --git a/admin/models/ajax.php b/admin/models/ajax.php index c43f0cfa1..98d8a072d 100644 --- a/admin/models/ajax.php +++ b/admin/models/ajax.php @@ -1876,6 +1876,101 @@ class ComponentbuilderModelAjax extends JModelList } // Used in custom_code + public function getEditCustomCodeButtons($id) + { + $view = $this->getViewID(); + // only continue if this is a legitimate call + if (isset($view['a_id']) && $view['a_id'] == $id && isset($view['a_view']) && ($target = $this->getCodeSearchKeys($view['a_view'], 'query_')) !== false) + { + $db = JFactory::getDbo(); + $query = $db->getQuery(true) + ->select($db->quoteName($target['select'])) + ->from($db->quoteName('#__componentbuilder_' . $target['table'], 'a')) + ->where('a.id = ' . (int) $id); + $db->setQuery($query); + $db->execute(); + if ($db->loadRowList()) + { + $data = $db->loadAssoc(); + // some helper for some fields + $helper = array('xml' => 'note_select_field_type'); + // reset the bucket + $bucket = array(); + foreach ($data as $key => $value) + { + if ('id' !== $key && $target['name'] !== $key) + { + if (!isset($target['not_base64'][$key])) + { + $value = ComponentbuilderHelper::openValidBase64($value, null); + } + elseif ('json' === $target['not_base64'][$key] && 'xml' === $key) // just for field search + { + $value = json_decode($value); + } + // check if we should search for base64 string inside the text + if (isset($target['base64_search']) && isset($target['base64_search'][$key]) + && isset($target['base64_search'][$key]['start']) && strpos($value, $target['base64_search'][$key]['start']) !== false) + { + // search and open the base64 strings + $this->searchOpenBase64($value, $target['base64_search'][$key]); + } + // check if place holder set + if (strpos($value, '[CUSTOMC' . 'ODE=') !== false) + { + // get all custom codes in value + $bucket[$key] = ComponentbuilderHelper::getAllBetween($value, '[CUSTOMC' . 'ODE=', ']'); + } + } + } + // check if any values found + if (ComponentbuilderHelper::checkArray($bucket)) + { + // get input + $jinput = JFactory::getApplication()->input; + $return_here = $jinput->get('return_here', null, 'base64'); + // set the return here value if not found + if (ComponentbuilderHelper::checkString($return_here)) + { + $return_here = '&return=' . $return_here; + } + else + { + $return_here = '&ref=' . $view['a_view'] . '&refid=' . (int) $id; + } + // reset the buttons bucket + $buttons = array(); + foreach ($bucket as $field => $customcodes) + { + $edit_icon = ' '; + // see if the field needs some help :) + if (isset($helper[$field])) + { + $field = $helper[$field]; + } + $buttons[$field] = array(); + foreach ($customcodes as $customcode) + { + $key = (array) explode('+', $customcode); + if (!isset($buttons[$field][$key[0]]) && ($_id = ComponentbuilderHelper::getVar('custom_code', $key[0], 'function_name')) !== false + && ($button = ComponentbuilderHelper::getEditTextButton($edit_icon . $key[0], $_id, 'custom_code', 'custom_codes', $return_here, 'com_componentbuilder', false, 'btn btn-small button-edit" style="margin: 0 0 5px 0;')) + && ComponentbuilderHelper::checkString($button)) + { + $buttons[$field][$key[0]] = $button; + } + } + } + // only continue if we have buttons in array + if (ComponentbuilderHelper::checkArray($buttons, true)) + { + return $buttons; + } + } + } + } + return false; + } + public function checkFunctionName($name, $id) { $nameArray = (array) $this->splitAtUpperCase($name); @@ -1970,10 +2065,26 @@ class ComponentbuilderModelAjax extends JModelList // check if any values found if (ComponentbuilderHelper::checkArray($bucket)) { + // get input + $jinput = JFactory::getApplication()->input; + $return_here = $jinput->get('return_here', null, 'base64'); + // set the return here value if not found + if (ComponentbuilderHelper::checkString($return_here)) + { + $return_here = '&return=' . $return_here; + } + else + { + $return_here = '&ref=custom_code&refid=' . (int) $id; + } $usedin = array(); foreach ($bucket as $editId => $values) { - $usedin[] = '' . $values['name'] . ' (' . implode(', ', $values['fields']) . ')'; + if (($button = ComponentbuilderHelper::getEditTextButton($values['name'], $editId, $target['table'], $target['views'], $return_here, 'com_componentbuilder', false, '')) + && ComponentbuilderHelper::checkString($button)) + { + $usedin[] = $button. ' (' . implode(', ', $values['fields']) . ')'; + } } $html = ''; return array('in' => $html, 'id' => $targeting); @@ -2156,6 +2267,13 @@ class ComponentbuilderModelAjax extends JModelList 'views' => 'custom_codes', 'not_base64' => array(), 'name' => 'system_name' + ), + // #__componentbuilder_validation_rule (n) + 'validation_rule' => array( + 'search' => array('id', 'name', 'php'), + 'views' => 'validation_rules', + 'not_base64' => array(), + 'name' => 'name' ) ); @@ -2188,7 +2306,7 @@ class ComponentbuilderModelAjax extends JModelList } } // return result ready for a.query - if ('query' === $type && isset($this->codeSearchKeys[$target])) + if (('query' === $type || 'query_' === $type) && isset($this->codeSearchKeys[$target])) { // set the targets $codeSearchTarget = $this->codeSearchKeys[$target]; diff --git a/admin/models/component_dashboard.php b/admin/models/component_dashboard.php index 8566339b4..4422fbee0 100644 --- a/admin/models/component_dashboard.php +++ b/admin/models/component_dashboard.php @@ -50,6 +50,11 @@ class ComponentbuilderModelComponent_dashboard extends JModelAdmin $this->addTablePath(JPATH_ADMINISTRATOR . '/components/com_componentbuilder/tables'); // get instance of the table return JTable::getInstance($type, $prefix, $config); + } + + public function getVDM() + { + return $this->vastDevMod; } /** @@ -95,6 +100,31 @@ class ComponentbuilderModelComponent_dashboard extends JModelAdmin $item->dashboard_tab = $dashboard_tab->toArray(); } + + if (empty($item->id)) + { + $id = 0; + } + else + { + $id = $item->id; + } + // set the id and view name to session + if ($vdm = ComponentbuilderHelper::get('components_dashboard__'.$id)) + { + $this->vastDevMod = $vdm; + } + else + { + // set the vast development method key + $this->vastDevMod = ComponentbuilderHelper::randomkey(50); + ComponentbuilderHelper::set($this->vastDevMod, 'components_dashboard__'.$id); + ComponentbuilderHelper::set('components_dashboard__'.$id, $this->vastDevMod); + // set a return value if found + $jinput = JFactory::getApplication()->input; + $return = $jinput->get('return', null, 'base64'); + ComponentbuilderHelper::set($this->vastDevMod . '__return', $return); + } // update the fields $objectUpdate = new stdClass(); $objectUpdate->id = (int) $item->id; diff --git a/admin/models/custom_admin_view.php b/admin/models/custom_admin_view.php index 4f10ef5b9..6927cc399 100644 --- a/admin/models/custom_admin_view.php +++ b/admin/models/custom_admin_view.php @@ -198,7 +198,7 @@ class ComponentbuilderModelCustom_admin_view extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('custom_admin_view__'.$id)) { diff --git a/admin/models/custom_code.php b/admin/models/custom_code.php index 3dab5e615..6cd09d550 100644 --- a/admin/models/custom_code.php +++ b/admin/models/custom_code.php @@ -50,6 +50,11 @@ class ComponentbuilderModelCustom_code extends JModelAdmin $this->addTablePath(JPATH_ADMINISTRATOR . '/components/com_componentbuilder/tables'); // get instance of the table return JTable::getInstance($type, $prefix, $config); + } + + public function getVDM() + { + return $this->vastDevMod; } /** @@ -85,6 +90,32 @@ class ComponentbuilderModelCustom_code extends JModelAdmin { // base64 Decode code. $item->code = base64_decode($item->code); + } + + + if (empty($item->id)) + { + $id = 0; + } + else + { + $id = $item->id; + } + // set the id and view name to session + if ($vdm = ComponentbuilderHelper::get('custom_code__'.$id)) + { + $this->vastDevMod = $vdm; + } + else + { + // set the vast development method key + $this->vastDevMod = ComponentbuilderHelper::randomkey(50); + ComponentbuilderHelper::set($this->vastDevMod, 'custom_code__'.$id); + ComponentbuilderHelper::set('custom_code__'.$id, $this->vastDevMod); + // set a return value if found + $jinput = JFactory::getApplication()->input; + $return = $jinput->get('return', null, 'base64'); + ComponentbuilderHelper::set($this->vastDevMod . '__return', $return); } if (!empty($item->id)) diff --git a/admin/models/dynamic_get.php b/admin/models/dynamic_get.php index ab4e8b5c5..e9defcec1 100644 --- a/admin/models/dynamic_get.php +++ b/admin/models/dynamic_get.php @@ -196,7 +196,7 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('dynamic_get__'.$id)) { diff --git a/admin/models/field.php b/admin/models/field.php index 6e9d793f7..3c25a6ab3 100644 --- a/admin/models/field.php +++ b/admin/models/field.php @@ -124,7 +124,7 @@ class ComponentbuilderModelField extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('field__'.$id)) { diff --git a/admin/models/fieldtype.php b/admin/models/fieldtype.php index eb099db26..0c6680e86 100644 --- a/admin/models/fieldtype.php +++ b/admin/models/fieldtype.php @@ -50,6 +50,11 @@ class ComponentbuilderModelFieldtype extends JModelAdmin $this->addTablePath(JPATH_ADMINISTRATOR . '/components/com_componentbuilder/tables'); // get instance of the table return JTable::getInstance($type, $prefix, $config); + } + + public function getVDM() + { + return $this->vastDevMod; } /** @@ -89,6 +94,31 @@ class ComponentbuilderModelFieldtype extends JModelAdmin $item->properties = $properties->toArray(); } + + if (empty($item->id)) + { + $id = 0; + } + else + { + $id = $item->id; + } + // set the id and view name to session + if ($vdm = ComponentbuilderHelper::get('fieldtype__'.$id)) + { + $this->vastDevMod = $vdm; + } + else + { + // set the vast development method key + $this->vastDevMod = ComponentbuilderHelper::randomkey(50); + ComponentbuilderHelper::set($this->vastDevMod, 'fieldtype__'.$id); + ComponentbuilderHelper::set('fieldtype__'.$id, $this->vastDevMod); + // set a return value if found + $jinput = JFactory::getApplication()->input; + $return = $jinput->get('return', null, 'base64'); + ComponentbuilderHelper::set($this->vastDevMod . '__return', $return); + } // check what type of properties array we have here (should be subform... but just incase) // This could happen due to huge data sets if (isset($item->properties) && isset($item->properties['name'])) diff --git a/admin/models/forms/admin_fields_relations.js b/admin/models/forms/admin_fields_relations.js index 15990d741..5d5e93e2d 100644 --- a/admin/models/forms/admin_fields_relations.js +++ b/admin/models/forms/admin_fields_relations.js @@ -11,6 +11,11 @@ +jQuery(document).ready(function() +{ + // check and load all the customcode edit buttons + getEditCustomCodeButtons(); +}); // little script to set the value function getCodeGlueOptions(field) { // get the ID @@ -67,4 +72,43 @@ function _isSet(val) } return false; } + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; +} diff --git a/admin/models/forms/admin_view.js b/admin/models/forms/admin_view.js index 28ec70746..1220cad76 100644 --- a/admin/models/forms/admin_view.js +++ b/admin/models/forms/admin_view.js @@ -1312,6 +1312,8 @@ jQuery(document).ready(function() addButtonID('admin_fields_relations','create_edit_buttons', 1); // <-- forth // set button addButtonID('admin_custom_tabs','addtabs-lbl', 1); // <-- fifth + // check and load all the customcode edit buttons + getEditCustomCodeButtons(); }); function checkAliasField() { @@ -1370,80 +1372,6 @@ function getAjaxDisplay_server(type){ function addData(result,where){ jQuery(result).insertAfter(jQuery(where).closest('.control-group')); } - -function addButtonID_server(type, size){ - var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getButtonID&format=json&raw=true&vdm="+vastDevMod); - if(token.length > 0 && type.length > 0 && size > 0){ - var request = 'token='+token+'&type='+type+'&size='+size; - } - return jQuery.ajax({ - type: 'GET', - url: getUrl, - dataType: 'json', - data: request, - jsonp: false - }); -} -function addButtonID(type, where, size){ - addButtonID_server(type, size).done(function(result) { - if(result){ - if (2 == size) { - jQuery('#'+where).html(result); - } else { - addData(result, '#jform_'+where); - } - } - }); -} - -function addButton_server(type, size){ - var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getButton&format=json&raw=true&vdm="+vastDevMod); - if(token.length > 0 && type.length > 0){ - var request = 'token='+token+'&type='+type+'&size='+size; - } - return jQuery.ajax({ - type: 'GET', - url: getUrl, - dataType: 'json', - data: request, - jsonp: false - }); -} -function addButton(type, where, size){ - // just to insure that default behaviour still works - size = typeof size !== 'undefined' ? size : 1; - addButton_server(type, size).done(function(result) { - if(result){ - if (2 == size) { - jQuery('#'+where).html(result); - } else { - addData(result, '#jform_'+where); - } - } - }) -} - -function getLinked_server(type){ - var getUrl = "index.php?option=com_componentbuilder&task=ajax.getLinked&format=json&raw=true&vdm="+vastDevMod; - if(token.length > 0 && type > 0){ - var request = 'token='+token+'&type='+type; - } - return jQuery.ajax({ - type: 'GET', - url: getUrl, - dataType: 'json', - data: request, - jsonp: false - }); -} - -function getLinked(){ - getLinked_server(1).done(function(result) { - if(result){ - jQuery('#display_linked_to').html(result); - } - }); -} function getTableColumns_server(tableName){ var getUrl = "index.php?option=com_componentbuilder&task=ajax.tableColumns&format=json&raw=true&vdm="+vastDevMod; @@ -1557,4 +1485,117 @@ function getDynamicScripts(id){ }); } } +} + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; +} + +function addButtonID_server(type, size){ + var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getButtonID&format=json&raw=true&vdm="+vastDevMod); + if(token.length > 0 && type.length > 0 && size > 0){ + var request = 'token='+token+'&type='+type+'&size='+size; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} +function addButtonID(type, where, size){ + addButtonID_server(type, size).done(function(result) { + if(result){ + if (2 == size) { + jQuery('#'+where).html(result); + } else { + addData(result, '#jform_'+where); + } + } + }); +} + +function addButton_server(type, size){ + var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getButton&format=json&raw=true&vdm="+vastDevMod); + if(token.length > 0 && type.length > 0){ + var request = 'token='+token+'&type='+type+'&size='+size; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} +function addButton(type, where, size){ + // just to insure that default behaviour still works + size = typeof size !== 'undefined' ? size : 1; + addButton_server(type, size).done(function(result) { + if(result){ + if (2 == size) { + jQuery('#'+where).html(result); + } else { + addData(result, '#jform_'+where); + } + } + }) +} + +function getLinked_server(type){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getLinked&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && type > 0){ + var request = 'token='+token+'&type='+type; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getLinked(){ + getLinked_server(1).done(function(result) { + if(result){ + jQuery('#display_linked_to').html(result); + } + }); } diff --git a/admin/models/forms/component_dashboard.js b/admin/models/forms/component_dashboard.js index 4bb347a82..1dd99e338 100644 --- a/admin/models/forms/component_dashboard.js +++ b/admin/models/forms/component_dashboard.js @@ -8,4 +8,50 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ - + + + +jQuery(document).ready(function() +{ + // check and load all the customcode edit buttons + getEditCustomCodeButtons(); +}); + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; +} diff --git a/admin/models/forms/custom_admin_view.js b/admin/models/forms/custom_admin_view.js index c37d18352..78befdc1e 100644 --- a/admin/models/forms/custom_admin_view.js +++ b/admin/models/forms/custom_admin_view.js @@ -440,6 +440,8 @@ jQuery(document).ready(function() { // get the linked details getLinked(); + // check and load all the custom code edit buttons + getEditCustomCodeButtons(); }); function getLinked_server(type){ @@ -662,4 +664,43 @@ function setSnippets(array){ jQuery('#jform_snippet').append(''); } jQuery('#jform_snippet').trigger('liszt:updated'); +} + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; } diff --git a/admin/models/forms/custom_code.js b/admin/models/forms/custom_code.js index d2332e6b7..c31de517d 100644 --- a/admin/models/forms/custom_code.js +++ b/admin/models/forms/custom_code.js @@ -232,6 +232,8 @@ jQuery(document).ready(function() jQuery('#html-comment-info').hide(); jQuery('#phpjs-comment-info').show(); } + // check and load all the custom code edit buttons + getEditCustomCodeButtons(); }); function setCustomCodePlaceholder() { var ide = jQuery('#jform_id').val(); @@ -308,8 +310,8 @@ function usedin(functioName, ide) { jQuery('#note-usedin-not').hide(); jQuery('#note-usedin-found').hide(); jQuery('#loading-usedin').show(); - var targets = ['a','b','c','d','e','f','g','h','i','j','k','l','m']; // if you update this, also update (below 11) & [customcode-codeUsedInHtmlNote]! - var targetNumber = 12; + var targets = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n']; // if you update this, also update (below 13) & [customcode-codeUsedInHtmlNote]! + var targetNumber = 13; var run = 0; var usedinChecker = setInterval(function(){ var target = targets[run]; @@ -340,7 +342,7 @@ function usedin(functioName, ide) { function usedin_server(functioName, ide, target){ var getUrl = "index.php?option=com_componentbuilder&task=ajax.usedin&format=json"; if(token.length > 0){ - var request = 'token='+token+'&functioName='+functioName+'&id='+ide+'&target='+target; + var request = 'token='+token+'&functioName='+functioName+'&id='+ide+'&target='+target+'&return_here='+return_here; } return jQuery.ajax({ type: 'GET', @@ -349,4 +351,43 @@ function usedin_server(functioName, ide, target){ data: request, jsonp: 'callback' }); +} + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; } diff --git a/admin/models/forms/dynamic_get.js b/admin/models/forms/dynamic_get.js index e7a704b6d..c4cc3d082 100644 --- a/admin/models/forms/dynamic_get.js +++ b/admin/models/forms/dynamic_get.js @@ -1527,29 +1527,9 @@ jQuery(document).ready(function() var select_all = jQuery("#jform_select_all input[type='radio']:checked").val(); // make sure the selection is correct setSelectAll(select_all); + // check and load all the custom code edit buttons + getEditCustomCodeButtons(); }); - -function getLinked_server(type){ - var getUrl = "index.php?option=com_componentbuilder&task=ajax.getLinked&format=json&raw=true&vdm="+vastDevMod; - if(token.length > 0 && type > 0){ - var request = 'token='+token+'&type='+type; - } - return jQuery.ajax({ - type: 'GET', - url: getUrl, - dataType: 'json', - data: request, - jsonp: false - }); -} - -function getLinked(){ - getLinked_server(1).done(function(result) { - if(result){ - jQuery('#display_linked_to').html(result); - } - }); -} function setSelectAll(select_all){ // get source type @@ -1744,4 +1724,65 @@ function getDynamicScripts(id){ }); } } +} + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; +} + +function getLinked_server(type){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getLinked&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && type > 0){ + var request = 'token='+token+'&type='+type; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getLinked(){ + getLinked_server(1).done(function(result) { + if(result){ + jQuery('#display_linked_to').html(result); + } + }); } diff --git a/admin/models/forms/field.js b/admin/models/forms/field.js index b4db1d3c5..33eb0762e 100644 --- a/admin/models/forms/field.js +++ b/admin/models/forms/field.js @@ -519,56 +519,9 @@ jQuery(document).ready(function() var fieldText = jQuery("#jform_fieldtype option:selected").text().toLowerCase(); // now check if database input is needed dbChecker(fieldText); + // check and load all the custom code edit buttons + getEditCustomCodeButtons(); }); - -function getLinked_server(type){ - var getUrl = "index.php?option=com_componentbuilder&task=ajax.getLinked&format=json&raw=true&vdm="+vastDevMod; - if(token.length > 0 && type > 0){ - var request = 'token='+token+'&type='+type; - } - return jQuery.ajax({ - type: 'GET', - url: getUrl, - dataType: 'json', - data: request, - jsonp: false - }); -} - -function getLinked(){ - getLinked_server(1).done(function(result) { - if(result){ - jQuery('#display_linked_to').html(result); - } - }); -} - -function addButton_server(type, size){ - var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getButton&format=json&raw=true&vdm="+vastDevMod); - if(token.length > 0 && type.length > 0){ - var request = 'token='+token+'&type='+type+'&size='+size; - } - return jQuery.ajax({ - type: 'GET', - url: getUrl, - dataType: 'json', - data: request, - jsonp: false - }); -} -function addButton(type, where, size){ - // just to insure that default behaviour still works - size = typeof size !== 'undefined' ? size : 1; - addButton_server(type, size).done(function(result) { - if(result){ - if (2 == size) { - jQuery('#'+where).html(result); - } else { - addData(result, '#jform_'+where); - } - } - }) -} // the options row id key var rowIdKey = 'properties'; @@ -815,4 +768,92 @@ function dbChecker(type){ jQuery('.note_no_database_settings_needed').closest('.control-group').hide(); jQuery('.note_database_settings_needed').closest('.control-group').show(); } +} + +function getLinked_server(type){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getLinked&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && type > 0){ + var request = 'token='+token+'&type='+type; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getLinked(){ + getLinked_server(1).done(function(result) { + if(result){ + jQuery('#display_linked_to').html(result); + } + }); +} + +function addButton_server(type, size){ + var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getButton&format=json&raw=true&vdm="+vastDevMod); + if(token.length > 0 && type.length > 0){ + var request = 'token='+token+'&type='+type+'&size='+size; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} +function addButton(type, where, size){ + // just to insure that default behaviour still works + size = typeof size !== 'undefined' ? size : 1; + addButton_server(type, size).done(function(result) { + if(result){ + if (2 == size) { + jQuery('#'+where).html(result); + } else { + addData(result, '#jform_'+where); + } + } + }) +} + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; } diff --git a/admin/models/forms/fieldtype.js b/admin/models/forms/fieldtype.js index 4bb347a82..ad43dbde5 100644 --- a/admin/models/forms/fieldtype.js +++ b/admin/models/forms/fieldtype.js @@ -8,4 +8,50 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ - + + + +jQuery(document).ready(function($) +{ + // check and load all the custom code edit buttons + getEditCustomCodeButtons(); +}); + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; +} diff --git a/admin/models/forms/joomla_component.js b/admin/models/forms/joomla_component.js index b3891eebd..283de060a 100644 --- a/admin/models/forms/joomla_component.js +++ b/admin/models/forms/joomla_component.js @@ -965,7 +965,8 @@ jQuery(document).ready(function() setTimeout(setDisplays2, 2500); setTimeout(setDisplays3, 3500); - // very basic I know... but it will have to do for now. + // check and load all the customcode edit buttons + setTimeout(getEditCustomCodeButtons, 400); }); function getAjaxDisplay(type){ @@ -1011,6 +1012,45 @@ function dasboardSwitch(value){ } +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; +} + function addButtonID_server(type, size){ var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getButtonID&format=json&raw=true&vdm="+vastDevMod); if(token.length > 0 && type.length > 0 && size > 0){ diff --git a/admin/models/forms/layout.js b/admin/models/forms/layout.js index 2eaa9007f..f8ada51fe 100644 --- a/admin/models/forms/layout.js +++ b/admin/models/forms/layout.js @@ -87,6 +87,50 @@ function isSet(val) } +jQuery(document).ready(function($) +{ + // check and load all the custom code edit buttons + getEditCustomCodeButtons(); +}); + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; +} function getSnippetDetails_server(snippetId){ var getUrl = "index.php?option=com_componentbuilder&task=ajax.snippetDetails&format=json"; diff --git a/admin/models/forms/library.js b/admin/models/forms/library.js index 88939bc8b..73b9f5767 100644 --- a/admin/models/forms/library.js +++ b/admin/models/forms/library.js @@ -410,11 +410,105 @@ jQuery(document).ready(function() // now load the displays getAjaxDisplay('library_config'); getAjaxDisplay('library_files_folders_urls'); + + // check and load all the customcode edit buttons + setTimeout(getEditCustomCodeButtons, 300); }); function addData(result,where){ jQuery(result).insertAfter(jQuery(where).closest('.control-group')); } + +function getAjaxDisplay(type){ + getAjaxDisplay_server(type).done(function(result) { + if (result) { + jQuery('#display_'+type).html(result); + } + // set button + addButtonID(type,'header_'+type+'_buttons', 2); // <-- little edit button + }); +} + +function getAjaxDisplay_server(type){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getAjaxDisplay&format=json&raw=true&vdm="+vastDevMod; + if (token.length > 0 && type.length > 0) { + var request = 'token='+token+'&type=' + type; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getFieldSelectOptions_server(fieldId){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.fieldSelectOptions&format=json&raw=true"; + if (token.length > 0 && fieldId > 0) { + var request = 'token='+token+'&id='+fieldId; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getFieldSelectOptions(fieldKey){ + // first check if the field is set + if(jQuery("#jform_addconditions__addconditions"+fieldKey+"__option_field").length) { + var fieldId = jQuery("#jform_addconditions__addconditions"+fieldKey+"__option_field option:selected").val(); + getFieldSelectOptions_server(fieldId).done(function(result) { + if(result) { + jQuery('textarea#jform_addconditions__addconditions'+fieldKey+'__field_options').val(result); + } else { + jQuery('textarea#jform_addconditions__addconditions'+fieldKey+'__field_options').val(''); + } + }); + } +} + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; +} function addButtonID_server(type, size){ var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getButtonID&format=json&raw=true&vdm="+vastDevMod); @@ -488,56 +582,4 @@ function getLinked(){ jQuery('#display_linked_to').html(result); } }); -} - -function getAjaxDisplay(type){ - getAjaxDisplay_server(type).done(function(result) { - if (result) { - jQuery('#display_'+type).html(result); - } - // set button - addButtonID(type,'header_'+type+'_buttons', 2); // <-- little edit button - }); -} - -function getAjaxDisplay_server(type){ - var getUrl = "index.php?option=com_componentbuilder&task=ajax.getAjaxDisplay&format=json&raw=true&vdm="+vastDevMod; - if (token.length > 0 && type.length > 0) { - var request = 'token='+token+'&type=' + type; - } - return jQuery.ajax({ - type: 'GET', - url: getUrl, - dataType: 'json', - data: request, - jsonp: false - }); -} - -function getFieldSelectOptions_server(fieldId){ - var getUrl = "index.php?option=com_componentbuilder&task=ajax.fieldSelectOptions&format=json&raw=true"; - if (token.length > 0 && fieldId > 0) { - var request = 'token='+token+'&id='+fieldId; - } - return jQuery.ajax({ - type: 'GET', - url: getUrl, - dataType: 'json', - data: request, - jsonp: false - }); -} - -function getFieldSelectOptions(fieldKey){ - // first check if the field is set - if(jQuery("#jform_addconditions__addconditions"+fieldKey+"__option_field").length) { - var fieldId = jQuery("#jform_addconditions__addconditions"+fieldKey+"__option_field option:selected").val(); - getFieldSelectOptions_server(fieldId).done(function(result) { - if(result) { - jQuery('textarea#jform_addconditions__addconditions'+fieldKey+'__field_options').val(result); - } else { - jQuery('textarea#jform_addconditions__addconditions'+fieldKey+'__field_options').val(''); - } - }); - } } diff --git a/admin/models/forms/site_view.js b/admin/models/forms/site_view.js index 19e1c804b..e4d934706 100644 --- a/admin/models/forms/site_view.js +++ b/admin/models/forms/site_view.js @@ -481,6 +481,8 @@ jQuery(document).ready(function() { // get the linked details getLinked(); + // check and load all the custom code edit buttons + getEditCustomCodeButtons(); }); function getLinked_server(type){ @@ -703,4 +705,43 @@ function setSnippets(array){ jQuery('#jform_snippet').append(''); } jQuery('#jform_snippet').trigger('liszt:updated'); +} + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; } diff --git a/admin/models/forms/template.js b/admin/models/forms/template.js index 0960a91b2..501a519d3 100644 --- a/admin/models/forms/template.js +++ b/admin/models/forms/template.js @@ -87,6 +87,50 @@ function isSet(val) } +jQuery(document).ready(function($) +{ + // check and load all the custom code edit buttons + getEditCustomCodeButtons(); +}); + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; +} function getSnippetDetails_server(snippetId){ var getUrl = "index.php?option=com_componentbuilder&task=ajax.snippetDetails&format=json"; diff --git a/admin/models/forms/validation_rule.js b/admin/models/forms/validation_rule.js index fb8317181..f793ba92d 100644 --- a/admin/models/forms/validation_rule.js +++ b/admin/models/forms/validation_rule.js @@ -26,6 +26,9 @@ jQuery(document).ready(function() // load the used in div // jQuery('#usedin').show(); + + // check and load all the customcode edit buttons + setTimeout(getEditCustomCodeButtons, 300); }); function getExistingValidationRuleCode_server(rulefilename){ @@ -92,4 +95,43 @@ function checkRuleName_server(ruleName, ide){ data: request, jsonp: 'callback' }); +} + +function getEditCustomCodeButtons_server(id){ + var getUrl = "index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod; + if(token.length > 0 && id > 0){ + var request = 'token='+token+'&id='+id+'&return_here='+return_here; + } + return jQuery.ajax({ + type: 'GET', + url: getUrl, + dataType: 'json', + data: request, + jsonp: false + }); +} + +function getEditCustomCodeButtons(){ + // get the id + id = jQuery("#jform_id").val(); + getEditCustomCodeButtons_server(id).done(function(result) { + if(isObject(result)){ + jQuery.each(result, function( field, buttons ) { + jQuery('
').insertBefore(".control-wrapper-"+ field); + jQuery.each(buttons, function( name, button ) { + jQuery(".control-customcode-buttons-"+field).append(button); + }); + }); + } + }) +} + +// check object is not empty +function isObject(obj) { + for(var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; } diff --git a/admin/models/joomla_component.php b/admin/models/joomla_component.php index 1179ec352..26f228dc3 100644 --- a/admin/models/joomla_component.php +++ b/admin/models/joomla_component.php @@ -221,7 +221,7 @@ class ComponentbuilderModelJoomla_component extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('joomla_component__'.$id)) { diff --git a/admin/models/joomla_components.php b/admin/models/joomla_components.php index 25ad6b568..a46edc767 100644 --- a/admin/models/joomla_components.php +++ b/admin/models/joomla_components.php @@ -1747,6 +1747,13 @@ class ComponentbuilderModelJoomla_components extends JModelList 'views' => 'custom_codes', 'not_base64' => array(), 'name' => 'system_name' + ), + // #__componentbuilder_validation_rule (n) + 'validation_rule' => array( + 'search' => array('id', 'name', 'php'), + 'views' => 'validation_rules', + 'not_base64' => array(), + 'name' => 'name' ) ); @@ -1779,7 +1786,7 @@ class ComponentbuilderModelJoomla_components extends JModelList } } // return result ready for a.query - if ('query' === $type && isset($this->codeSearchKeys[$target])) + if (('query' === $type || 'query_' === $type) && isset($this->codeSearchKeys[$target])) { // set the targets $codeSearchTarget = $this->codeSearchKeys[$target]; diff --git a/admin/models/language_translation.php b/admin/models/language_translation.php index 18e7bb8b1..aedc66b83 100644 --- a/admin/models/language_translation.php +++ b/admin/models/language_translation.php @@ -108,7 +108,7 @@ class ComponentbuilderModelLanguage_translation extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('language_translation__'.$id)) { diff --git a/admin/models/layout.php b/admin/models/layout.php index f13cf6b42..6aa637597 100644 --- a/admin/models/layout.php +++ b/admin/models/layout.php @@ -114,7 +114,7 @@ class ComponentbuilderModelLayout extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('layout__'.$id)) { diff --git a/admin/models/library.php b/admin/models/library.php index 7c9a26d84..a786b3f1d 100644 --- a/admin/models/library.php +++ b/admin/models/library.php @@ -116,7 +116,7 @@ class ComponentbuilderModelLibrary extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('library__'.$id)) { diff --git a/admin/models/site_view.php b/admin/models/site_view.php index 687c619f4..57023dffc 100644 --- a/admin/models/site_view.php +++ b/admin/models/site_view.php @@ -198,7 +198,7 @@ class ComponentbuilderModelSite_view extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('site_view__'.$id)) { diff --git a/admin/models/template.php b/admin/models/template.php index 59e8773fc..5c52b9125 100644 --- a/admin/models/template.php +++ b/admin/models/template.php @@ -114,7 +114,7 @@ class ComponentbuilderModelTemplate extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('template__'.$id)) { diff --git a/admin/models/validation_rule.php b/admin/models/validation_rule.php index a3b961937..bbd9466ef 100644 --- a/admin/models/validation_rule.php +++ b/admin/models/validation_rule.php @@ -100,7 +100,7 @@ class ComponentbuilderModelValidation_rule extends JModelAdmin else { $id = $item->id; - } + } // set the id and view name to session if ($vdm = ComponentbuilderHelper::get('validation_rule__'.$id)) { diff --git a/admin/views/admin_fields_relations/view.html.php b/admin/views/admin_fields_relations/view.html.php index e8fde91a2..392bc5378 100644 --- a/admin/views/admin_fields_relations/view.html.php +++ b/admin/views/admin_fields_relations/view.html.php @@ -191,7 +191,11 @@ class ComponentbuilderViewAdmin_fields_relations extends JViewLegacy // Add Ajax Token $this->document->addScriptDeclaration("var token = '".JSession::getFormToken()."';"); $this->document->addScript(JURI::root() . $this->script, (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); - $this->document->addScript(JURI::root() . "administrator/components/com_componentbuilder/views/admin_fields_relations/submitbutton.js", (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript(JURI::root() . "administrator/components/com_componentbuilder/views/admin_fields_relations/submitbutton.js", (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + // add var key + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/admin_view/view.html.php b/admin/views/admin_view/view.html.php index d0692caa9..05c7c3b9e 100644 --- a/admin/views/admin_view/view.html.php +++ b/admin/views/admin_view/view.html.php @@ -202,7 +202,9 @@ class ComponentbuilderViewAdmin_view extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); // add var key - $this->document->addScriptDeclaration("var vastDevMod = '".$this->get('VDM')."';"); + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/component_dashboard/view.html.php b/admin/views/component_dashboard/view.html.php index d379fa1a9..864f51d25 100644 --- a/admin/views/component_dashboard/view.html.php +++ b/admin/views/component_dashboard/view.html.php @@ -187,9 +187,15 @@ class ComponentbuilderViewComponent_dashboard extends JViewLegacy $this->document = JFactory::getDocument(); } $this->document->setTitle(JText::_($isNew ? 'COM_COMPONENTBUILDER_COMPONENT_DASHBOARD_NEW' : 'COM_COMPONENTBUILDER_COMPONENT_DASHBOARD_EDIT')); - $this->document->addStyleSheet(JURI::root() . "administrator/components/com_componentbuilder/assets/css/component_dashboard.css", (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addStyleSheet(JURI::root() . "administrator/components/com_componentbuilder/assets/css/component_dashboard.css", (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + // Add Ajax Token + $this->document->addScriptDeclaration("var token = '".JSession::getFormToken()."';"); $this->document->addScript(JURI::root() . $this->script, (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); - $this->document->addScript(JURI::root() . "administrator/components/com_componentbuilder/views/component_dashboard/submitbutton.js", (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript(JURI::root() . "administrator/components/com_componentbuilder/views/component_dashboard/submitbutton.js", (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + // add var key + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/custom_admin_view/view.html.php b/admin/views/custom_admin_view/view.html.php index 2d200957a..3e151ddde 100644 --- a/admin/views/custom_admin_view/view.html.php +++ b/admin/views/custom_admin_view/view.html.php @@ -202,7 +202,9 @@ class ComponentbuilderViewCustom_admin_view extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); // add var key - $this->document->addScriptDeclaration("var vastDevMod = '".$this->get('VDM')."';"); + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/custom_code/view.html.php b/admin/views/custom_code/view.html.php index 4a95857f1..890218201 100644 --- a/admin/views/custom_code/view.html.php +++ b/admin/views/custom_code/view.html.php @@ -201,6 +201,10 @@ class ComponentbuilderViewCustom_code extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/uikit.min.js' , (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); + // add var key + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); // need to add some language strings JText::script('COM_COMPONENTBUILDER_FUNCTION_NAME_ALREADY_TAKEN_PLEASE_TRY_AGAIN'); JText::script('COM_COMPONENTBUILDER_YOU_MUST_ADD_AN_UNIQUE_FUNCTION_NAME'); diff --git a/admin/views/dynamic_get/view.html.php b/admin/views/dynamic_get/view.html.php index a4a3cfbcc..924b09bb0 100644 --- a/admin/views/dynamic_get/view.html.php +++ b/admin/views/dynamic_get/view.html.php @@ -202,7 +202,9 @@ class ComponentbuilderViewDynamic_get extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); // add var key - $this->document->addScriptDeclaration("var vastDevMod = '".$this->get('VDM')."';"); + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/field/view.html.php b/admin/views/field/view.html.php index 373c742ad..1d6ca2df9 100644 --- a/admin/views/field/view.html.php +++ b/admin/views/field/view.html.php @@ -202,7 +202,9 @@ class ComponentbuilderViewField extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); // add var key - $this->document->addScriptDeclaration("var vastDevMod = '".$this->get('VDM')."';"); + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); // add the libs for subform (since not adding it via xml but ajax) JHtml::_('jquery.ui', array('core', 'sortable')); JHtml::_('script', 'system/subform-repeatable.js', array('version' => 'auto', 'relative' => true)); diff --git a/admin/views/fieldtype/view.html.php b/admin/views/fieldtype/view.html.php index 311f252c1..643dadeaa 100644 --- a/admin/views/fieldtype/view.html.php +++ b/admin/views/fieldtype/view.html.php @@ -191,6 +191,8 @@ class ComponentbuilderViewFieldtype extends JViewLegacy } $this->document->setTitle(JText::_($isNew ? 'COM_COMPONENTBUILDER_FIELDTYPE_NEW' : 'COM_COMPONENTBUILDER_FIELDTYPE_EDIT')); $this->document->addStyleSheet(JURI::root() . "administrator/components/com_componentbuilder/assets/css/fieldtype.css", (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + // Add Ajax Token + $this->document->addScriptDeclaration("var token = '".JSession::getFormToken()."';"); // Add the CSS for Footable $this->document->addStyleSheet('https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css'); @@ -202,7 +204,61 @@ class ComponentbuilderViewFieldtype extends JViewLegacy $this->document->addScriptDeclaration($footable); $this->document->addScript(JURI::root() . $this->script, (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); - $this->document->addScript(JURI::root() . "administrator/components/com_componentbuilder/views/fieldtype/submitbutton.js", (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript(JURI::root() . "administrator/components/com_componentbuilder/views/fieldtype/submitbutton.js", (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + + // get Uikit Version + $this->uikitVersion = $this->params->get('uikit_version', 2); + // Load uikit options. + $uikit = $this->params->get('uikit_load'); + $isAdmin = JFactory::getApplication()->isClient('administrator'); + // Set script size. + $size = $this->params->get('uikit_min'); + // Use Uikit Version 2 + if (2 == $this->uikitVersion && ($isAdmin || $uikit != 2)) + { + // Set css style. + $style = $this->params->get('uikit_style'); + // only load if needed + if ($isAdmin || $uikit != 3) + { + // add the style sheets + $this->document->addStyleSheet( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/css/uikit' . $style . $size . '.css' , (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + } + // add the style sheets + $this->document->addStyleSheet( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/css/components/accordion' . $style . $size . '.css' , (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addStyleSheet( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/css/components/tooltip' . $style . $size . '.css' , (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addStyleSheet( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/css/components/notify' . $style . $size . '.css' , (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addStyleSheet( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/css/components/form-file' . $style . $size . '.css' , (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addStyleSheet( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/css/components/progress' . $style . $size . '.css' , (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addStyleSheet( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/css/components/placeholder' . $style . $size . '.css' , (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addStyleSheet( JURI::root(true) .'/media/com_componentbuilder/uikit-v2//css/components/upload' . $style . $size . '.css' , (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + // only load if needed + if ($isAdmin || $uikit != 3) + { + // add JavaScripts + $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/uikit' . $size . '.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + } + // add JavaScripts + $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/accordion' . $size . '.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/tooltip' . $size . '.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox' . $size . '.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify' . $size . '.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/upload' . $size . '.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + } + // Use Uikit Version 3 + elseif (3 == $this->uikitVersion && ($isAdmin || $uikit != 2)) + { + // add the style sheets + $this->document->addStyleSheet( JURI::root(true) .'/media/com_componentbuilder/uikit-v3/css/uikit'.$size.'.css', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + // add JavaScripts + $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v3/js/uikit'.$size.'.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + // add icons + $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v3/js/uikit-icons'.$size.'.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + } + // add var key + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/joomla_component/view.html.php b/admin/views/joomla_component/view.html.php index 0d697d473..180e4c82c 100644 --- a/admin/views/joomla_component/view.html.php +++ b/admin/views/joomla_component/view.html.php @@ -202,7 +202,9 @@ class ComponentbuilderViewJoomla_component extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); // add var key - $this->document->addScriptDeclaration("var vastDevMod = '".$this->get('VDM')."';"); + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/layout/view.html.php b/admin/views/layout/view.html.php index 9fd913b5d..35e75eced 100644 --- a/admin/views/layout/view.html.php +++ b/admin/views/layout/view.html.php @@ -202,7 +202,9 @@ class ComponentbuilderViewLayout extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); // add var key - $this->document->addScriptDeclaration("var vastDevMod = '".$this->get('VDM')."';"); + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/library/view.html.php b/admin/views/library/view.html.php index b0d54f1dc..59cf47c47 100644 --- a/admin/views/library/view.html.php +++ b/admin/views/library/view.html.php @@ -202,7 +202,9 @@ class ComponentbuilderViewLibrary extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); // add var key - $this->document->addScriptDeclaration("var vastDevMod = '".$this->get('VDM')."';"); + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/site_view/view.html.php b/admin/views/site_view/view.html.php index 1aeca9bf3..3fa3d26c9 100644 --- a/admin/views/site_view/view.html.php +++ b/admin/views/site_view/view.html.php @@ -202,7 +202,9 @@ class ComponentbuilderViewSite_view extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); // add var key - $this->document->addScriptDeclaration("var vastDevMod = '".$this->get('VDM')."';"); + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/template/view.html.php b/admin/views/template/view.html.php index 80aa39113..a52fc408f 100644 --- a/admin/views/template/view.html.php +++ b/admin/views/template/view.html.php @@ -202,7 +202,9 @@ class ComponentbuilderViewTemplate extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); // add var key - $this->document->addScriptDeclaration("var vastDevMod = '".$this->get('VDM')."';"); + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); JText::script('view not acceptable. Error'); } } diff --git a/admin/views/validation_rule/view.html.php b/admin/views/validation_rule/view.html.php index fc4371c8d..047efe9ef 100644 --- a/admin/views/validation_rule/view.html.php +++ b/admin/views/validation_rule/view.html.php @@ -202,7 +202,9 @@ class ComponentbuilderViewValidation_rule extends JViewLegacy $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/lightbox.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); $this->document->addScript( JURI::root(true) .'/media/com_componentbuilder/uikit-v2/js/components/notify.min.js', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (ComponentbuilderHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); // add var key - $this->document->addScriptDeclaration("var vastDevMod = '".$this->get('VDM')."';"); + $this->document->addScriptDeclaration("var vastDevMod = '" . $this->get('VDM') . "';"); + // add return_here + $this->document->addScriptDeclaration("var return_here = '" . urlencode(base64_encode((string) JUri::getInstance())) . "';"); // need to add some language strings JText::script('COM_COMPONENTBUILDER_VALIDATION_RULE_NAME_ALREADY_TAKEN_PLEASE_TRY_AGAIN'); JText::script('COM_COMPONENTBUILDER_YOU_MUST_ADD_AN_UNIQUE_VALIDATION_RULE_NAME'); diff --git a/componentbuilder.xml b/componentbuilder.xml index 7597c7c36..96387964f 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 30th January, 2019 + 31st January, 2019 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index ee743ed2a..a2ba3a50c 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -4050,6 +4050,106 @@ abstract class ComponentbuilderHelper return ''; } + /** + * Get an edit text button + * + * @param string $text The button text + * @param int $item The item to edit + * @param string $view The type of item to edit + * @param string $views The list view controller name + * @param string $ref The return path + * @param string $component The component these views belong to + * @param string $headsup The message to show on click of button + * + * @return string On success the full html link + * + */ + public static function getEditTextButton($text, &$item, $view, $views, $ref = '', $component = 'com_componentbuilder', $jRoute = true, $class = 'uk-button', $headsup = 'COM_COMPONENTBUILDER_ALL_UNSAVED_WORK_ON_THIS_PAGE_WILL_BE_LOST_ARE_YOU_SURE_YOU_WANT_TO_CONTINUE') + { + // make sure we have text + if (!self::checkString($text)) + { + return self::getEditButton($item, $view, $views, $ref, $component, $headsup); + } + // get URL + $url = self::getEditURL($item, $view, $views, $ref, $component, $jRoute); + // check if we found any + if (self::checkString($url)) + { + // get the global settings + if (!self::checkObject(self::$params)) + { + self::$params = JComponentHelper::getParams('com_componentbuilder'); + } + // get UIKIT version + $uikit = self::$params->get('uikit_version', 2); + // check that we have the ID + if (self::checkObject($item) && isset($item->id)) + { + // check if the checked_out is available + if (isset($item->checked_out)) + { + $checked_out = (int) $item->checked_out; + } + } + elseif (self::checkArray($item) && isset($item['id'])) + { + // check if the checked_out is available + if (isset($item['checked_out'])) + { + $checked_out = (int) $item['checked_out']; + } + } + // set the link title + $title = self::safeString(JText::_('COM_COMPONENTBUILDER_EDIT') . ' ' . $view, 'W'); + // check that there is a check message + if (self::checkString($headsup)) + { + if (3 == $uikit) + { + $href = 'onclick="UIkit.modal.confirm(\''.JText::_($headsup).'\').then( function(){ window.location.href = \'' . $url . '\' } )" href="javascript:void(0)"'; + } + else + { + $href = 'onclick="UIkit2.modal.confirm(\''.JText::_($headsup).'\', function(){ window.location.href = \'' . $url . '\' })" href="javascript:void(0)"'; + } + } + else + { + $href = 'href="' . $url . '"'; + } + // return UIKIT version 3 + if (3 == $uikit) + { + // check if it is checked out + if (isset($checked_out) && $checked_out > 0) + { + // is this user the one who checked it out + if ($checked_out == JFactory::getUser()->id) + { + return ' ' . $text . ''; + } + return ' ' . $text . ''; + } + // return normal edit link + return ' ' . $text . ''; + } + // check if it is checked out (return UIKIT version 2) + if (isset($checked_out) && $checked_out > 0) + { + // is this user the one who checked it out + if ($checked_out == JFactory::getUser()->id) + { + return ' ' . $text . ''; + } + return ' ' . $text . ''; + } + // return normal edit link + return ' ' . $text . ''; + } + return ''; + } + /** * Get the edit URL *