elofgren: BUGFIX: If there are no Newsletter types, and 'Add new draft' is chosen, create a Newsletter type to prevent errors. This makes either drop-down option work.

(merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@42060 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-16 02:31:41 +00:00
parent e63c16fcff
commit a1fcfa6271
2 changed files with 19 additions and 4 deletions

View File

@ -689,9 +689,19 @@ JS;
private function newDraft( $parentID ) {
if(!$parentID || !is_numeric( $parentID)) {
$parent = DataObject::get_one("NewsletterType");
$parentID = $parent->ID;
if ($parent) {
$parentID = $parent->ID;
} else {
// BUGFIX: It could be that no Newsletter types have been created, if so add one to prevent errors.
$parentID = $this->newNewsletterType();
}
}
if( $parentID && is_numeric( $parentID ) ) {
$parent = DataObject::get_by_id("NewsletterType", $parentID);
// BUGFIX: It could be that no Newsletter types have been created, if so add one to prevent errors.
if(!$parent) {
$parentID = $this->newNewsletterType();
}
$newsletter = new Newsletter();
$newsletter->Status = 'Draft';
$newsletter->Title = $newsletter->Subject = 'New draft newsletter';

View File

@ -46,6 +46,14 @@ SiteTree.prototype = {
},
addDraftNode: function( title, parentID, draftID ) {
var st = $('sitetree');
// BUGFIX: If there is nothing in the left tree we need to add a Newsletter type first to prevent errors
if(typeof st.lastTreeNode() == 'undefined') {
$('sitetree').addTypeNode('New newsletter type', $('Form_EditForm_ID').value );
}
// BUGFIX: If no selection is made in the left tree, and a draft is added, parentID won't be set,
// so we need to use the value from the Draft edit form.
parentID = $('Form_EditForm_ParentID').value;
var draftNode = this.createTreeNode( 'draft_' + parentID + '_' + draftID, title, 'Draft', parentID );
this.getTreeNodeByIdx('drafts_' + parentID).appendTreeNode( draftNode );
this.changeCurrentTo( draftNode );
@ -300,9 +308,6 @@ AddForm.prototype = {
// create a new node and add it to the site tree
if( type == 'draft' ) {
// BUGFIX: If no selection is made in the left tree, and a draft is added, parentID won't be set,
// so we need to use the value from the Draft edit form.
parentID = $('Form_EditForm_ParentID').value;
$('sitetree').addDraftNode('New draft newsletter', parentID, $('Form_EditForm_ID').value );
} else {
$('sitetree').addTypeNode('New newsletter type', $('Form_EditForm_ID').value );