Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR Moved AddForm javascript logic to new LeftAndMain.AddForm.js fi…

…le 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
  • Loading branch information...
commit 175ceaf890fd63818250b8bb6e91404b4af2e7d2 1 parent 2e7f100
@chillu chillu authored
View
1  code/LeftAndMain.php
@@ -228,6 +228,7 @@ function init() {
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');
View
72 javascript/AssetAdmin.js
@@ -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() {
View
105 javascript/CMSMain.js
@@ -156,111 +156,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.
* @name ss.reports_holder
*/
$('#Form_ReportForm').concrete(function($) {
View
107 javascript/LeftAndMain.AddForm.js
@@ -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));
Please sign in to comment.
Something went wrong with that request. Please try again.