mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
Merge pull request #209 from chillu/pulls/subsites-dropdown
BUG Subsites selection on SubsitesVirtualPage (fixes #45 and #47)
This commit is contained in:
commit
e9678221fc
@ -22,15 +22,13 @@ class SubsitesVirtualPage extends VirtualPage {
|
|||||||
|
|
||||||
$subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0)));
|
$subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0)));
|
||||||
|
|
||||||
$subsiteSelectionField = new DropdownField(
|
|
||||||
"CopyContentFromID_SubsiteID",
|
|
||||||
_t('SubsitesVirtualPage.SubsiteField',"Subsite"),
|
|
||||||
$subsites->map('ID', 'Title'),
|
|
||||||
($this->CopyContentFromID) ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID')
|
|
||||||
);
|
|
||||||
$fields->addFieldToTab(
|
$fields->addFieldToTab(
|
||||||
'Root.Main',
|
'Root.Main',
|
||||||
$subsiteSelectionField,
|
DropdownField::create(
|
||||||
|
"CopyContentFromID_SubsiteID",
|
||||||
|
_t('SubsitesVirtualPage.SubsiteField',"Subsite"),
|
||||||
|
$subsites->map('ID', 'Title')
|
||||||
|
)->addExtraClass('subsitestreedropdownfield-chooser no-change-track'),
|
||||||
'CopyContentFromID'
|
'CopyContentFromID'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -44,7 +42,7 @@ class SubsitesVirtualPage extends VirtualPage {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if(Controller::has_curr() && Controller::curr()->getRequest()) {
|
if(Controller::has_curr() && Controller::curr()->getRequest()) {
|
||||||
$subsiteID = Controller::curr()->getRequest()->postVar('CopyContentFromID_SubsiteID');
|
$subsiteID = Controller::curr()->getRequest()->requestVar('CopyContentFromID_SubsiteID');
|
||||||
$pageSelectionField->setSubsiteID($subsiteID);
|
$pageSelectionField->setSubsiteID($subsiteID);
|
||||||
}
|
}
|
||||||
$fields->replaceField('CopyContentFromID', $pageSelectionField);
|
$fields->replaceField('CopyContentFromID', $pageSelectionField);
|
||||||
@ -112,6 +110,10 @@ class SubsitesVirtualPage extends VirtualPage {
|
|||||||
return $labels;
|
return $labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCopyContentFromID_SubsiteID() {
|
||||||
|
return ($this->CopyContentFromID) ? (int)$this->CopyContentFrom()->SubsiteID : (int)Session::get('SubsiteID');
|
||||||
|
}
|
||||||
|
|
||||||
public function getVirtualFields() {
|
public function getVirtualFields() {
|
||||||
$fields = parent::getVirtualFields();
|
$fields = parent::getVirtualFields();
|
||||||
foreach($fields as $k => $v) {
|
foreach($fields as $k => $v) {
|
||||||
|
@ -1,24 +1,30 @@
|
|||||||
(function($) {
|
(function($) {
|
||||||
$.entwine('ss', function($) {
|
$.entwine('ss', function($) {
|
||||||
$('.TreeDropdownField').entwine({
|
/**
|
||||||
subsiteID: function() {
|
* Choose a subsite from which to select pages.
|
||||||
var subsiteSel = $('#CopyContentFromID_SubsiteID select')[0];
|
* Needs to clear tree dropdowns in case selection is changed.
|
||||||
if(!subsiteSel) return;
|
*/
|
||||||
|
$('.subsitestreedropdownfield-chooser').entwine({
|
||||||
subsiteSel.onchange = (function() {
|
onchange: function() {
|
||||||
this.createTreeNode(true);
|
// TODO Data binding between two fields
|
||||||
this.ajaxGetTree((function(response) {
|
// TODO create resetField method on API instead
|
||||||
this.newTreeReady(response, true);
|
var fields = $('.SubsitesTreeDropdownField');
|
||||||
this.updateTreeLabel();
|
fields.setValue(null);
|
||||||
}).bind(this));
|
fields.setTitle(null);
|
||||||
}).bind(this);
|
fields.find('.tree-holder').empty();
|
||||||
return subsiteSel.options[subsiteSel.selectedIndex].value;
|
}
|
||||||
},
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add selected subsite from separate dropdown to the request parameters
|
||||||
|
* before asking for the tree.
|
||||||
|
*/
|
||||||
|
$('.TreeDropdownField.SubsitesTreeDropdownField').entwine({
|
||||||
getRequestParams: function() {
|
getRequestParams: function() {
|
||||||
var name = this.find(':input:hidden').attr('name'), obj = {};
|
var name = this.find(':input[type=hidden]:first').attr('name') + '_SubsiteID',
|
||||||
obj[name + '_SubsiteID'] = parseInt(this.subsiteID());
|
source = $('[name=' + name + ']'), params = {};
|
||||||
return obj;
|
params[name] = source.length ? source.val() : null;
|
||||||
|
return params;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user