Skip to content

Commit

Permalink
Fixed: autofill on autocomplete db join element, timing changes to js…
Browse files Browse the repository at this point in the history
… code to get things to run in the correct order

Fixed: add new element to group which also was a joined group, elements not copied into joined group
  • Loading branch information
pollen8 committed Feb 20, 2012
1 parent 5b88ac3 commit f9c8e86
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
21 changes: 18 additions & 3 deletions administrator/components/com_fabrik/models/element.php
Expand Up @@ -672,7 +672,6 @@ function save($data)
// to each of those tables' groups // to each of those tables' groups


if ($new) { if ($new) {

$this->addElementToOtherDbTables($elementModel, $row); $this->addElementToOtherDbTables($elementModel, $row);
} }


Expand All @@ -691,27 +690,43 @@ private function addElementToOtherDbTables($elementModel, $row)
$db = FabrikWorker::getDbo(true); $db = FabrikWorker::getDbo(true);
$list = $elementModel->getListModel()->getTable(); $list = $elementModel->getListModel()->getTable();
$origElid = $row->id; $origElid = $row->id;
$tmpgroupModel =& $elementModel->getGroup(); $tmpgroupModel = $elementModel->getGroup();
if ($tmpgroupModel->isJoin()) { if ($tmpgroupModel->isJoin()) {
$dbname = $tmpgroupModel->getJoinModel()->getJoin()->table_join; $dbname = $tmpgroupModel->getJoinModel()->getJoin()->table_join;
} else { } else {
$dbname = $list->db_table_name; $dbname = $list->db_table_name;
} }


$query = $db->getQuery(true); $query = $db->getQuery(true);
$query->select("DISTINCT(l.id), db_table_name, l.id, l.label, l.form_id, l.label AS form_label, g.id AS group_id"); $query->select("DISTINCT(l.id) AS id, db_table_name, l.label, l.form_id, l.label AS form_label, g.id AS group_id");
$query->from("#__{package}_lists AS l"); $query->from("#__{package}_lists AS l");
$query->join('INNER', '#__{package}_forms AS f ON l.form_id = f.id'); $query->join('INNER', '#__{package}_forms AS f ON l.form_id = f.id');
$query->join('LEFT', '#__{package}_formgroup AS fg ON f.id = fg.form_id'); $query->join('LEFT', '#__{package}_formgroup AS fg ON f.id = fg.form_id');
$query->join('LEFT', '#__{package}_groups AS g ON fg.group_id = g.id'); $query->join('LEFT', '#__{package}_groups AS g ON fg.group_id = g.id');
$query->where("db_table_name = ".$db->Quote($dbname)." AND l.id !=".(int)$list->id." AND is_join = 0"); $query->where("db_table_name = ".$db->Quote($dbname)." AND l.id !=".(int)$list->id." AND is_join = 0");


$db->setQuery($query); $db->setQuery($query);

// $$$ rob load keyed on table id to avoid creating element in every one of the table's group // $$$ rob load keyed on table id to avoid creating element in every one of the table's group
$othertables = $db->loadObjectList('id'); $othertables = $db->loadObjectList('id');
if ($db->getErrorNum() != 0) { if ($db->getErrorNum() != 0) {
JError::raiseError(500, $db->getErrorMsg()); JError::raiseError(500, $db->getErrorMsg());
} }

// $$$ rob 20/02/2012 if you have 2 lists, countres, regions and then you join regions to countries to get a new group "countries - [regions]"
// Then add elements to the regions list, the above query wont find the group "countries - [regions]" to add the elements into

$query = $db->getQuery(true);
$query->select('DISTINCT(l.id) AS id, l.db_table_name, l.label, l.form_id, l.label AS form_label, fg.group_id AS group_id')
->from('#__{package}_joins AS j')
->join('LEFT', '#__{package}_formgroup AS fg ON fg.group_id = j.group_id')
->join('LEFT', '#__{package}_forms AS f ON fg.form_id = f.id')
->join('LEFT', '#__{package}_lists AS l ON l.form_id = f.id')
->where('j.table_join = ' . $db->Quote($dbname) . ' AND j.list_id <> 0 AND list_id <> ' . (int)$list->id);
$db->setQuery($query);
$joinedLists = $db->loadObjectList('id');
$othertables = array_merge($joinedLists, $othertables);

if (!empty($othertables)) { if (!empty($othertables)) {
// $$$ hugh - we use $row after this, so we need to work on a copy, otherwise // $$$ hugh - we use $row after this, so we need to work on a copy, otherwise
// (for instance) we redirect to the wrong copy of the element // (for instance) we redirect to the wrong copy of the element
Expand Down
2 changes: 1 addition & 1 deletion media/com_fabrik/js/autocomplete-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions media/com_fabrik/js/autocomplete.js
Expand Up @@ -137,10 +137,10 @@ var FbAutocomplete = new Class({
this.getInputElement().value = li.get('text'); this.getInputElement().value = li.get('text');
this.element.value = li.getProperty('data-value'); this.element.value = li.getProperty('data-value');
this.closeMenu(); this.closeMenu();
this.fireEvent('selection', [this, this.element.value]);
// $$$ hugh - need to fire change event, in case it's something like a join element // $$$ hugh - need to fire change event, in case it's something like a join element
// with a CDD that watches it. // with a CDD that watches it.
this.element.fireEvent('change', new Event.Mock(this.element, 'change')); this.element.fireEvent('change', new Event.Mock(this.element, 'change'), 700);
this.fireEvent('selection', [this, this.element.value]);
}, },


closeMenu: function () { closeMenu: function () {
Expand Down

0 comments on commit f9c8e86

Please sign in to comment.