mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
MINOR Moved AddForm javascript logic to new LeftAndMain.AddForm.js file which is shared by CMSMain and AssetAdmin
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92810 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
2e7f100a1c
commit
175ceaf890
@ -228,6 +228,7 @@ class LeftAndMain extends Controller {
|
||||
Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.js');
|
||||
Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.Tree.js');
|
||||
Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.EditForm.js');
|
||||
Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.AddForm.js');
|
||||
Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.BatchActions.js');
|
||||
|
||||
Requirements::themedCSS('typography');
|
||||
|
@ -44,78 +44,6 @@ var _HANDLER_FORMS = {
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* @class Simple form with a page type dropdown
|
||||
* which creates a new page through #Form_EditForm and adds a new tree node.
|
||||
* @name ss.Form_AddForm
|
||||
* @requires ss.i18n
|
||||
* @requires ss.Form_EditForm
|
||||
*/
|
||||
$('#Form_AddForm').concrete(function($) {
|
||||
return/** @lends ss.Form_AddForm */{
|
||||
/**
|
||||
* @type DOMElement
|
||||
*/
|
||||
Tree: null,
|
||||
|
||||
/**
|
||||
* @type Array Internal counter to create unique page identifiers prior to ajax saving
|
||||
*/
|
||||
_NewPages: [],
|
||||
|
||||
onmatch: function() {
|
||||
var self = this;
|
||||
|
||||
this.bind('submit', function(e) {
|
||||
return self._submit(e);
|
||||
});
|
||||
|
||||
Observable.applyTo(this[0]);
|
||||
|
||||
var tree = jQuery('#sitetree')[0];
|
||||
this.setTree(tree);
|
||||
},
|
||||
|
||||
_submit: function(e) {
|
||||
var newPages = this._NewPages();
|
||||
var tree = this.Tree();
|
||||
var parentID = (tree.firstSelected()) ? tree.getIdxOf(tree.firstSelected()) : 0;
|
||||
|
||||
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
|
||||
if(parentID && parentID.substr(0,3) == 'new') {
|
||||
alert(ss.i18n._t('CMSMAIN.WARNINGSAVEPAGESBEFOREADDING'));
|
||||
}
|
||||
|
||||
if(tree.firstSelected() && jQuery(tree.firstSelected()).hasClass("nochildren")) {
|
||||
alert(ss.i18n._t('CMSMAIN.CANTADDCHILDREN') );
|
||||
}
|
||||
|
||||
// Optionally initalize the new pages tracker
|
||||
if(!newPages[parentID] ) newPages[parentID] = 1;
|
||||
|
||||
// default to first button
|
||||
var button = jQuery(this).find(':submit:first');
|
||||
button.addClass('loading');
|
||||
|
||||
// collect data and submit the form
|
||||
var data = jQuery(this).serializeArray();
|
||||
data.push({name:'Suffix',value:newPages[parentID]++});
|
||||
data.push({name:button.attr('name'),value:button.val()});
|
||||
jQuery('#Form_EditForm').concrete('ss').loadForm(
|
||||
jQuery(this).attr('action'),
|
||||
function() {
|
||||
button.removeClass('loading');
|
||||
},
|
||||
{type: 'POST', data: data}
|
||||
);
|
||||
|
||||
this.set_NewPages(newPages);
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
$('#Form_SyncForm').concrete('ss', function($) {
|
||||
return {
|
||||
onmatch: function() {
|
||||
|
@ -153,111 +153,6 @@
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* @class Simple form with a page type dropdown
|
||||
* which creates a new page through #Form_EditForm and adds a new tree node.
|
||||
* @name ss.Form_AddForm
|
||||
* @requires ss.i18n
|
||||
* @requires ss.Form_EditForm
|
||||
*/
|
||||
$('#Form_AddForm').concrete(function($) {
|
||||
return/** @lends ss.Form_AddForm */{
|
||||
/**
|
||||
* @type DOMElement
|
||||
*/
|
||||
Tree: null,
|
||||
|
||||
/**
|
||||
* @type Array Internal counter to create unique page identifiers prior to ajax saving
|
||||
*/
|
||||
_NewPages: [],
|
||||
|
||||
onmatch: function() {
|
||||
var self = this;
|
||||
|
||||
this.bind('submit', function(e) {
|
||||
return self._submit(e);
|
||||
});
|
||||
|
||||
Observable.applyTo(this[0]);
|
||||
|
||||
var tree = jQuery('#sitetree')[0];
|
||||
this.setTree(tree);
|
||||
jQuery(tree).bind('selectionchanged', function(e, data) {self.treeSelectionChanged(e, data);});
|
||||
|
||||
this.find(':input[name=PageType]').bind('change', this.typeDropdownChanged);
|
||||
},
|
||||
|
||||
_submit: function(e) {
|
||||
var newPages = this._NewPages();
|
||||
var tree = this.Tree();
|
||||
var parentID = (tree.firstSelected()) ? tree.getIdxOf(tree.firstSelected()) : 0;
|
||||
|
||||
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
|
||||
if(parentID && parentID.substr(0,3) == 'new') {
|
||||
alert(ss.i18n._t('CMSMAIN.WARNINGSAVEPAGESBEFOREADDING'));
|
||||
}
|
||||
|
||||
if(tree.firstSelected() && jQuery(tree.firstSelected()).hasClass("nochildren")) {
|
||||
alert(ss.i18n._t('CMSMAIN.CANTADDCHILDREN') );
|
||||
}
|
||||
|
||||
// Optionally initalize the new pages tracker
|
||||
if(!newPages[parentID] ) newPages[parentID] = 1;
|
||||
|
||||
// default to first button
|
||||
var button = jQuery(this).find(':submit:first');
|
||||
button.addClass('loading');
|
||||
|
||||
// collect data and submit the form
|
||||
var data = jQuery(this).serializeArray();
|
||||
data.push({name:'Suffix',value:newPages[parentID]++});
|
||||
data.push({name:button.attr('name'),value:button.val()});
|
||||
jQuery('#Form_EditForm').concrete('ss').loadForm(
|
||||
jQuery(this).attr('action'),
|
||||
function() {
|
||||
button.removeClass('loading');
|
||||
},
|
||||
{type: 'POST', data: data}
|
||||
);
|
||||
|
||||
this.set_NewPages(newPages);
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
treeSelectionChanged : function(e, data) {
|
||||
var selectedNode = data.node;
|
||||
|
||||
if(selectedNode.hints && selectedNode.hints.defaultChild) {
|
||||
this.find(':input[name=PageType]').val(selectedNode.hints.defaultChild);
|
||||
}
|
||||
|
||||
var parentID = this.Tree().getIdxOf(selectedNode);
|
||||
this.find(':input[name=ParentID]').val(parentID ? parentID : 0);
|
||||
},
|
||||
|
||||
typeDropdownChanged : function() {
|
||||
var tree = this.Tree();
|
||||
|
||||
// Don't do anything if we're already on an appropriate node
|
||||
var sel = tree.firstSelected();
|
||||
if(sel && sel.hints && sel.hints.allowedChildren) {
|
||||
var allowed = sel.hints.allowedChildren;
|
||||
for(i=0;i<allowed.length;i++) {
|
||||
if(allowed[i] == this.value) return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise move to the default parent for that.
|
||||
if(siteTreeHints && siteTreeHints[this.value] ) {
|
||||
var newNode = tree.getTreeNodeByIdx(siteTreeHints[this.value].defaultParent);
|
||||
if(newNode) tree.changeCurrentTo(newNode);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* @class Simple form with a page type dropdown
|
||||
* which creates a new page through #Form_EditForm and adds a new tree node.
|
||||
|
107
javascript/LeftAndMain.AddForm.js
Normal file
107
javascript/LeftAndMain.AddForm.js
Normal file
@ -0,0 +1,107 @@
|
||||
(function($) {
|
||||
/**
|
||||
* @class Simple form with a page type dropdown
|
||||
* which creates a new page through #Form_EditForm and adds a new tree node.
|
||||
* @name ss.Form_AddForm
|
||||
* @requires ss.i18n
|
||||
* @requires ss.Form_EditForm
|
||||
*/
|
||||
$('#Form_AddForm').concrete(function($) {
|
||||
return/** @lends ss.Form_AddForm */{
|
||||
/**
|
||||
* @type DOMElement
|
||||
*/
|
||||
Tree: null,
|
||||
|
||||
/**
|
||||
* @type Array Internal counter to create unique page identifiers prior to ajax saving
|
||||
*/
|
||||
_NewPages: [],
|
||||
|
||||
onmatch: function() {
|
||||
var self = this;
|
||||
|
||||
this.bind('submit', function(e) {
|
||||
return self._submit(e);
|
||||
});
|
||||
|
||||
Observable.applyTo(this[0]);
|
||||
|
||||
var tree = jQuery('#sitetree')[0];
|
||||
this.setTree(tree);
|
||||
jQuery(tree).bind('selectionchanged', function(e, data) {self.treeSelectionChanged(e, data);});
|
||||
|
||||
this.find(':input[name=PageType]').bind('change', this.typeDropdownChanged);
|
||||
},
|
||||
|
||||
_submit: function(e) {
|
||||
var newPages = this._NewPages();
|
||||
var tree = this.Tree();
|
||||
var parentID = (tree.firstSelected()) ? tree.getIdxOf(tree.firstSelected()) : 0;
|
||||
|
||||
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
|
||||
if(parentID && parentID.substr(0,3) == 'new') {
|
||||
alert(ss.i18n._t('CMSMAIN.WARNINGSAVEPAGESBEFOREADDING'));
|
||||
}
|
||||
|
||||
if(tree.firstSelected() && jQuery(tree.firstSelected()).hasClass("nochildren")) {
|
||||
alert(ss.i18n._t('CMSMAIN.CANTADDCHILDREN') );
|
||||
}
|
||||
|
||||
// Optionally initalize the new pages tracker
|
||||
if(!newPages[parentID] ) newPages[parentID] = 1;
|
||||
|
||||
// default to first button
|
||||
var button = jQuery(this).find(':submit:first');
|
||||
button.addClass('loading');
|
||||
|
||||
// collect data and submit the form
|
||||
var data = jQuery(this).serializeArray();
|
||||
data.push({name:'Suffix',value:newPages[parentID]++});
|
||||
data.push({name:button.attr('name'),value:button.val()});
|
||||
// TODO Should be set by hiddenfield already
|
||||
jQuery('#Form_EditForm').concrete('ss').loadForm(
|
||||
jQuery(this).attr('action'),
|
||||
function() {
|
||||
button.removeClass('loading');
|
||||
},
|
||||
{type: 'POST', data: data}
|
||||
);
|
||||
|
||||
this.set_NewPages(newPages);
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
treeSelectionChanged : function(e, data) {
|
||||
var selectedNode = data.node;
|
||||
|
||||
if(selectedNode.hints && selectedNode.hints.defaultChild) {
|
||||
this.find(':input[name=PageType]').val(selectedNode.hints.defaultChild);
|
||||
}
|
||||
|
||||
var parentID = this.Tree().getIdxOf(selectedNode);
|
||||
this.find(':input[name=ParentID]').val(parentID ? parentID : 0);
|
||||
},
|
||||
|
||||
typeDropdownChanged : function() {
|
||||
var tree = this.Tree();
|
||||
|
||||
// Don't do anything if we're already on an appropriate node
|
||||
var sel = tree.firstSelected();
|
||||
if(sel && sel.hints && sel.hints.allowedChildren) {
|
||||
var allowed = sel.hints.allowedChildren;
|
||||
for(i=0;i<allowed.length;i++) {
|
||||
if(allowed[i] == this.value) return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise move to the default parent for that.
|
||||
if(siteTreeHints && siteTreeHints[this.value] ) {
|
||||
var newNode = tree.getTreeNodeByIdx(siteTreeHints[this.value].defaultParent);
|
||||
if(newNode) tree.changeCurrentTo(newNode);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}(jQuery));
|
Loading…
Reference in New Issue
Block a user