MINOR Adjusted CMS JavaScript to new jquery-concrete API: Getters have 'get' prefix, namespaces are defined in blocks, event handlers work consistently. Mostly indentation and structure changes, no logic changes.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92825 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-11-21 03:19:59 +00:00
parent 1036329e86
commit 4d60aa5c83
11 changed files with 651 additions and 725 deletions

View File

@ -16,11 +16,10 @@ var _HANDLER_FORMS = {
};
(function($) {
/**
* Delete selected folders through "batch actions" tab.
*/
$(function() {
$(document).ready(function() {
$('#Form_BatchActionsForm').concrete('ss').register(
// TODO Hardcoding of base URL
'admin/assets/batchactions/delete',
@ -36,32 +35,26 @@ var _HANDLER_FORMS = {
);
});
$('#Form_SyncForm').concrete('ss', function($) {
return {
onmatch: function() {
this.bind('submit', this._onsubmit);
this._super();
},
_onsubmit: function(e) {
$.concrete('ss', function($){
$('#Form_SyncForm').concrete({
onsubmit: function(e) {
var button = jQuery(this).find(':submit:first');
button.addClass('loading');
$.get(
jQuery(this).attr('action'),
function() {
button.removeClass('loading');
// reload current
var currNode = $('#sitetree')[0].firstSelected();
if(currNode) {
var url = $(currNode).find('a').attr('href');
$('#Form_EditForm').concrete('ss').loadForm(url);
$('#Form_EditForm').loadForm(url);
}
}
);
return false;
}
};
});
});
}(jQuery));

View File

@ -1,28 +1,23 @@
(function($) {
$.concrete('ss', function($){
/**
* Alert the user on change of page-type - this might have implications
* on the available form fields etc.
* @name ss.EditFormClassName
*/
$('#Form_EditForm :input[name=ClassName]').concrete('ss', function($){
return/** @lends ss.EditFormClassName */{
$('#Form_EditForm :input[name=ClassName]').concrete(/** @lends ss.EditFormClassName */{
onchange: function() {
alert(ss.i18n._t('CMSMAIN.ALERTCLASSNAME'));
}
};
});
/**
* @class Input validation on the URLSegment field
* @name ss.EditForm.URLSegment
*/
$('#Form_EditForm input[name=URLSegment]').concrete('ss', function($){
return/** @lends ss.EditForm.URLSegment */{
$('#Form_EditForm input[name=URLSegment]').concrete(/** @lends ss.EditForm.URLSegment */{
FilterRegex: /[^A-Za-z0-9-]+/,
ValidationMessage: ss.i18n._t('CMSMAIN.URLSEGMENTVALIDATION'),
MaxLength: 50,
onmatch : function() {
@ -31,11 +26,13 @@
// intercept change event, do our own writing
this.bind('change', function(e) {
if(!self.validate()) {
jQuery.noticeAdd(self.ValidationMessage());
jQuery.noticeAdd(self.getValidationMessage());
}
self.val(self.suggestValue(e.target.value));
return false;
});
this._super();
},
/**
@ -46,25 +43,22 @@
*/
suggestValue: function(val) {
// TODO Do we want to enforce lowercasing in URLs?
return val.substr(0, this.MaxLength()).replace(this.FilterRegex(), '').toLowerCase();
return val.substr(0, this.getMaxLength()).replace(this.getFilterRegex(), '').toLowerCase();
},
validate: function() {
return (
this.val().length > this.MaxLength()
|| this.val().match(this.FilterRegex())
this.val().length > this.getMaxLength()
|| this.val().match(this.getFilterRegex())
);
}
};
});
/**
* @class Input validation on the Title field
* @name ss.EditForm.Title
*/
$('#Form_EditForm input[name=Title]').concrete('ss', function($){
return/** @lends ss.EditForm.Title */{
$('#Form_EditForm input[name=Title]').concrete(/** @lends ss.EditForm.Title */{
onmatch : function() {
var self = this;
@ -73,6 +67,8 @@
// TODO We should really user-confirm these changes
self.parents('form').find('input[name=MetaTitle], input[name=MenuTitle]').val(self.val());
});
this._super();
},
updateURLSegment: function(field) {
@ -97,7 +93,6 @@
field.val(suggestion);
}
}
};
});
/**
@ -105,14 +100,13 @@
* the two radiobuttons and setting the hidden "ParentID" field
* @name ss.EditForm.parentTypeSelector
*/
$('#Form_EditForm .parentTypeSelector').concrete('ss', function($){
return/** @lends ss.EditForm.parentTypeSelector */{
$('#Form_EditForm .parentTypeSelector').concrete(/** @lends ss.EditForm.parentTypeSelector */{
onmatch : function() {
var self = this;
this.find(':input[name=ParentType]').bind('click', function(e) {self._toggleSelection(e);});
this._toggleSelection();
this._super();
},
_toggleSelection: function(e) {
@ -122,7 +116,6 @@
// toggle tree dropdown based on selection
this.find('#ParentID').toggle(selected != 'root');
}
};
});
/**
@ -130,8 +123,7 @@
* based on selection of radiobuttons.
* @name ss.Form_EditForm.Access
*/
$('#Form_EditForm #CanViewType, #Form_EditForm #CanEditType').concrete('ss', function($){
return/** @lends ss.Form_EditForm.Access */{
$('#Form_EditForm #CanViewType, #Form_EditForm #CanEditType').concrete(/** @lends ss.Form_EditForm.Access */{
onmatch: function() {
// TODO Decouple
var dropdown;
@ -145,8 +137,9 @@
// initial state
var currentVal = this.find('input[name=' + this.attr('id') + ']:checked').val();
dropdown.toggle(currentVal == 'OnlyTheseUsers');
this._super();
}
};
});
/**
@ -154,8 +147,7 @@
* Visible on readonly older versions of a specific page at the moment.
* @name ss.Form_EditForm_action_email
*/
$('#Form_EditForm .Actions #Form_EditForm_action_email').concrete('ss', function($){
return/** @lends ss.Form_EditForm_action_email */{
$('#Form_EditForm .Actions #Form_EditForm_action_email').concrete(/** @lends ss.Form_EditForm_action_email */{
onclick: function(e) {
window.open(
'mailto:?subject='
@ -167,7 +159,6 @@
return false;
}
};
});
/**
@ -175,8 +166,7 @@
* Used for readonly older versions of a specific page.
* @name ss.Form_EditForm_action_print
*/
$('#Form_EditForm .Actions #Form_EditForm_action_print').concrete('ss', function($){
return/** @lends ss.Form_EditForm_action_print */{
$('#Form_EditForm .Actions #Form_EditForm_action_print').concrete(/** @lends ss.Form_EditForm_action_print */{
onclick: function(e) {
var printURL = $(this[0].form).attr('action').replace(/\?.*$/,'')
+ '/printable/'
@ -187,19 +177,17 @@
return false;
}
};
});
/**
* @class A "rollback" to a specific version needs user confirmation.
* @name ss.Form_EditForm_action_rollback
*/
$('#Form_EditForm .Actions #Form_EditForm_action_rollback').concrete('ss', function($){
return/** @lends ss.Form_EditForm_action_rollback */{
$('#Form_EditForm .Actions #Form_EditForm_action_rollback').concrete(/** @lends ss.Form_EditForm_action_rollback */{
onclick: function(e) {
// @todo i18n
return confirm("Do you really want to copy the published content to the stage site?");
}
};
});
});
}(jQuery));

View File

@ -1,11 +1,11 @@
(function($) {
$.concrete('ss', function($){
/**
* @class Dropdown with languages above CMS tree, causing a redirect upon translation
* @name ss.CMSMain.LangSelector
*/
$('.CMSMain #Form_LangForm').concrete('ss', function($){
return/** @lends ss.CMSMain.LangSelector */{
$('.CMSMain #Form_LangForm').concrete(/** @lends ss.CMSMain.LangSelector */{
onmatch: function() {
var self = this;
@ -24,8 +24,9 @@
document.location = url;
return false;
});
this._super();
}
};
});
/**
@ -37,8 +38,7 @@
* @name ss.CMSMain.createtranslation
* @requires jquery.metadata
*/
$('.CMSMain .createTranslation').concrete('ss', function($){
return/** @lends ss.CMSMain.createtranslation */{
$('.CMSMain .createTranslation').concrete(/** @lends ss.CMSMain.createtranslation */{
onmatch: function() {
var self = this;
@ -55,8 +55,9 @@
return false;
});
}
};
});
this._super();
}
});
});
}(jQuery));

View File

@ -1,11 +1,11 @@
(function($) {
$.concrete('ss', function($){
/**
* @class All forms in the right content panel should have closeable jQuery UI style titles.
* @name ss.contentPanel.form
*/
$('#contentPanel form').concrete('ss', function($){
return/** @lends ss.contentPanel.form */{
$('#contentPanel form').concrete(/** @lends ss.contentPanel.form */{
onmatch: function() {
// Style as title bar
this.find(':header:first').titlebar({
@ -14,11 +14,11 @@
// The close button should close the east panel of the layout
this.find(':header:first .ui-dialog-titlebar-close').bind('click', function(e) {
$('body.CMSMain').concrete('ss').MainLayout().close('east');
return false;
});
this._super();
}
};
});
/**
@ -27,9 +27,7 @@
* similar to "Smart Search" criteria in iTunes.
* @name ss.Form_SeachTreeForm
*/
$('#Form_SearchTreeForm').concrete('ss', function($) {
return/** @lends ss.Form_SeachTreeForm */{
$('#Form_SearchTreeForm').concrete(/** @lends ss.Form_SeachTreeForm */{
/**
* @type DOMElement
*/
@ -38,10 +36,6 @@
onmatch: function() {
var self = this;
// TODO Cant bind to onsubmit/onreset directly because of IE6
this.bind('submit', function(e) {return self._submitForm(e);});
this.bind('reset', function(e) {return self._resetForm(e);});
// only the first field should be visible by default
this.find('.field').not(':first').hide();
@ -53,21 +47,22 @@
this._setOptions();
this._super();
},
_setOptions: function() {
var self = this;
// reset existing elements
self.SelectEl().find('option').remove();
self.getSelectEl().find('option').remove();
// add default option
// TODO i18n
jQuery('<option value="0">Add Criteria</option>').appendTo(self.SelectEl());
jQuery('<option value="0">Add Criteria</option>').appendTo(self.getSelectEl());
// populate dropdown values from existing fields
this.find('.field').each(function() {
$('<option />').appendTo(self.SelectEl())
$('<option />').appendTo(self.getSelectEl())
.val(this.id)
.text($(this).find('label').text());
});
@ -76,7 +71,7 @@
/**
* Filter tree based on selected criteria.
*/
_submitForm: function(e) {
onsubmit: function(e) {
var self = this;
var data = [];
@ -103,7 +98,7 @@
return false;
},
_resetForm: function(e) {
onreset: function(e) {
this.find('.field').clearFields().not(':first').hide();
// Reset URL to default
@ -150,7 +145,6 @@
}
});
}
};
});
/**
@ -158,16 +152,12 @@
* which creates a new page through #Form_EditForm and adds a new tree node.
* @name ss.reports_holder
*/
$('#Form_ReportForm').concrete(function($) {
return/** @lends ss.reports_holder */{
$('#Form_ReportForm').concrete(/** @lends ss.reports_holder */{
onmatch: function() {
var self = this;
this.bind('submit', function(e) {
return self._submit(e);
});
// integrate with sitetree selection changes
// TODO Only trigger when report is visible
jQuery('#sitetree').bind('selectionchanged', function(e, data) {
self.find(':input[name=ID]').val(data.node.getIdx());
self.trigger('submit');
@ -188,9 +178,11 @@
);
return false;
});
this._super();
},
_submit: function(e) {
onsubmit: function(e) {
var self = this;
// dont process if no report is selected
@ -215,7 +207,6 @@
return false;
}
};
});
/**
@ -223,20 +214,19 @@
* @name ss.Form_VersionsForm
* @requires ss.i18n
*/
$('#Form_VersionsForm').concrete(function($) {
return/** @lends ss.Form_VersionsForm */{
$('#Form_VersionsForm').concrete(/** @lends ss.Form_VersionsForm */{
onmatch: function() {
var self = this;
this.bind('submit', function(e) {
return self._submit(e);
});
// set button to be available in form submit event later on
this.find(':submit').bind('click', function(e) {
self.data('_clickedButton', this);
});
this.bind('submit', function(e) {
return self._submit();
});
// integrate with sitetree selection changes
jQuery('#sitetree').bind('selectionchanged', function(e, data) {
self.find(':input[name=ID]').val(data.node.getIdx());
@ -291,17 +281,19 @@
// overloaded submission: refresh the right form instead
self.data('_clickedButton', this);
self._submit(e, true);
self._submit(true);
return false;
})
});
this._super();
},
/**
* @param {boolean} loadEditForm Determines if responses should show in current panel,
* or in the edit form (in the case of 'compare versions').
*/
_submit: function(e, loadEditForm) {
_submit: function(loadEditForm) {
var self = this;
// Don't submit with empty ID
@ -335,9 +327,8 @@
});
}
return false;
}
};
});
});
})(jQuery);

View File

@ -1,4 +1,5 @@
(function($) {
$.concrete('ss', function($){
/**
* @class Simple form with a page type dropdown
* which creates a new page through #Form_EditForm and adds a new tree node.
@ -6,8 +7,7 @@
* @requires ss.i18n
* @requires ss.Form_EditForm
*/
$('#Form_AddForm').concrete(function($) {
return/** @lends ss.Form_AddForm */{
$('#Form_AddForm').concrete(/** @lends ss.Form_AddForm */{
/**
* @type DOMElement
*/
@ -16,15 +16,11 @@
/**
* @type Array Internal counter to create unique page identifiers prior to ajax saving
*/
_NewPages: [],
NewPages: [],
onmatch: function() {
var self = this;
this.bind('submit', function(e) {
return self._submit(e);
});
Observable.applyTo(this[0]);
var tree = jQuery('#sitetree')[0];
@ -32,11 +28,13 @@
jQuery(tree).bind('selectionchanged', function(e, data) {self.treeSelectionChanged(e, data);});
this.find(':input[name=PageType]').bind('change', this.typeDropdownChanged);
this._super();
},
_submit: function(e) {
var newPages = this._NewPages();
var tree = this.Tree();
onsubmit: function(e) {
var newPages = this.getNewPages();
var tree = this.getTree();
var parentID = (tree.firstSelected()) ? tree.getIdxOf(tree.firstSelected()) : 0;
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
@ -68,7 +66,7 @@
{type: 'POST', data: data}
);
this.set_NewPages(newPages);
this.setNewPages(newPages);
return false;
},
@ -80,12 +78,12 @@
this.find(':input[name=PageType]').val(selectedNode.hints.defaultChild);
}
var parentID = this.Tree().getIdxOf(selectedNode);
var parentID = this.getTree().getIdxOf(selectedNode);
this.find(':input[name=ParentID]').val(parentID ? parentID : 0);
},
typeDropdownChanged : function() {
var tree = this.Tree();
var tree = this.getTree();
// Don't do anything if we're already on an appropriate node
var sel = tree.firstSelected();
@ -102,6 +100,6 @@
if(newNode) tree.changeCurrentTo(newNode);
}
}
};
});
});
}(jQuery));

View File

@ -1,4 +1,5 @@
(function($) {
$.concrete('ss', function($){
/**
* @class Batch actions which take a bunch of selected pages,
@ -11,8 +12,7 @@
* - register: Called before an action is added.
* - unregister: Called before an action is removed.
*/
$('#Form_BatchActionsForm').concrete('ss', function($){
return/** @lends ss.Form_BatchActionsForm */{
$('#Form_BatchActionsForm').concrete(/** @lends ss.Form_BatchActionsForm */{
/**
* @type {DOMElement}
@ -31,7 +31,7 @@
this.setTree($('#sitetree')[0]);
$(this.Tree()).bind('selectionchanged', function(e, data) {
$(this.getTree()).bind('selectionchanged', function(e, data) {
self._treeSelectionChanged(data.node);
});
@ -42,14 +42,14 @@
// if the panel is visible (meaning about to be closed),
// disable tree selection and reset any values. Otherwise enable it.
if($(ui.panel).is(':visible')) {
$(self.Tree()).removeClass('multiselect');
$(self.getTree()).removeClass('multiselect');
} else {
self._multiselectTransform();
}
});
this.bind('submit', function(e) {return self._submit(e);});
this._super();
},
/**
@ -58,8 +58,7 @@
*/
register: function(type, callback) {
this.trigger('register', {type: type, callback: callback});
var actions = this.Actions();
var actions = this.getActions();
actions[type] = callback;
this.setActions(actions);
},
@ -72,7 +71,7 @@
unregister: function(type) {
this.trigger('unregister', {type: type});
var actions = this.Actions();
var actions = this.getActions();
if(actions[type]) delete actions[type];
this.setActions(actions);
},
@ -87,9 +86,9 @@
return $('#TreeActions-batchactions').is(':visible');
},
_submit: function(e) {
onsubmit: function(e) {
var ids = [];
var tree = this.Tree();
var tree = this.getTree();
// find all explicitly selected IDs
$(tree).find('li.selected').each(function() {
ids.push(tree.getIdxOf(this));
@ -107,13 +106,11 @@
// apply callback, which might modify the IDs
var type = this.find(':input[name=Action]').val();
if(this.Actions()[type]) ids = this.Actions()[type].apply(this, [ids]);
if(this.getActions()[type]) ids = this.getActions()[type].apply(this, [ids]);
// if no IDs are selected, stop here. This is an implict way for the
// callback to cancel the actions
if(!ids || !ids.length) {
return false;
}
if(!ids || !ids.length) return false;
// write IDs to the hidden field
this.find(':input[name=csvIDs]').val(ids.join(','));
@ -181,10 +178,10 @@
*/
_multiselectTransform : function() {
// make tree selectable
jQuery(this.Tree()).addClass('multiselect');
jQuery(this.getTree()).addClass('multiselect');
// auto-select the current node
var node = this.Tree().firstSelected();
var node = this.getTree().firstSelected();
if(node){
node.removeNodeClass('current');
node.addNodeClass('selected');
@ -226,7 +223,7 @@
});
}
}
};
});
});
$(document).ready(function() {

View File

@ -1,4 +1,5 @@
(function($) {
$.concrete('ss', function($){
/**
* @class Base edit form, provides ajaxified saving
@ -13,9 +14,7 @@
* - removeform: A form is about to be removed from the DOM
* - load: Form is about to be loaded through ajax
*/
$('#Form_EditForm').concrete('ss',function($){
return/** @lends ss.Form_EditForm */{
$('#Form_EditForm').concrete(/** @lends ss.Form_EditForm */{
/**
* @type String HTML text to show when no form content is chosen.
* Will show inside the <form> tag.
@ -32,10 +31,6 @@
this._setupChangeTracker();
this.bind('submit', function(e) {
return self._submit(e);
});
// Can't bind this through jQuery
window.onbeforeunload = function(e) {return self._checkChangeTracker(false);};
@ -45,7 +40,7 @@
_setupChangeTracker: function() {
// Don't bind any events here, as we dont replace the
// full <form> tag by any ajax updates they won't automatically reapply
this.changetracker(this.ChangeTrackerOptions());
this.changetracker(this.getChangeTrackerOptions());
},
/**
@ -79,8 +74,9 @@
*
* @param {Event} e
*/
_submit: function(e) {
onsubmit: function(e) {
this.ajaxSubmit();
return false;
},
@ -201,15 +197,11 @@
* Falls back to the default RemoveText() option (Optional)
*/
removeForm: function(placeholderHtml) {
if(!placeholderHtml) placeholderHtml = this.PlaceholderHtml();
if(!placeholderHtml) placeholderHtml = this.getPlaceholderHtml();
// Alert when unsaved changes are present
if(this._checkChangeTracker(true) == false) return false;
if(this._checkChangeTracker(true) == false) return;
this.trigger('removeform');
this.html(placeholderHtml);
// TODO This should be using the plugin API
this.removeClass('changed');
},
@ -294,7 +286,6 @@
statusMessage(_statusMessage, (xmlhttp.status >= 400) ? 'bad' : 'good');
}
}
};
});
/**
@ -303,36 +294,28 @@
* clicked button from a form.onsubmit event.
* @name ss.Form_EditForm.Actions.submit
*/
$('#Form_EditForm .Actions :submit').concrete('ss', function($){
return/** @lends ss.Form_EditForm.Actions.submit */{
onmatch: function() {
this.bind('click', this._onclick);
this._super();
},
_onclick: function() {
$('#Form_EditForm .Actions :submit').concrete(/** @lends ss.Form_EditForm.Actions.submit */{
onclick: function(e) {
jQuery('#Form_EditForm').concrete('ss').ajaxSubmit(this);
return false;
}
};
});
/**
* @class Add tinymce to HtmlEditorFields within the CMS.
* @name ss.Form_EditForm.textarea.htmleditor
*/
$('#Form_EditForm textarea.htmleditor').concrete('ss', function($){
return/** @lends ss.Form_EditForm.Actions.submit */{
$('#Form_EditForm textarea.htmleditor').concrete(/** @lends ss.Form_EditForm.Actions.submit */{
onmatch : function() {
tinyMCE.execCommand("mceAddControl", true, this.attr('id'));
this.isChanged = function() {
return tinyMCE.getInstanceById(this.attr('id')).isDirty();
}
};
this.resetChanged = function() {
var inst = tinyMCE.getInstanceById(this.attr('id'));
if (inst) inst.startContent = tinymce.trim(inst.getContent({format : 'raw', no_events : 1}));
}
}
};
}
});
});
}(jQuery));

View File

@ -5,6 +5,7 @@
var ss_MainLayout;
(function($) {
$.concrete('ss', function($){
// setup jquery.concrete
$.concrete.warningLevel = $.concrete.WARN_LEVEL_BESTPRACTISE;
@ -28,9 +29,7 @@ var ss_MainLayout;
* panel and an edit form.
* @name ss.LeftAndMain
*/
$('.LeftAndMain').concrete('ss', function($){
return/** @lends ss.EditMemberProfile */ {
$('.LeftAndMain').concrete(/** @lends ss.EditMemberProfile */{
/**
* Reference to jQuery.layout element
* @type Object
@ -174,12 +173,13 @@ var ss_MainLayout;
global: false,
complete: onSessionLost
});
}, this.PingIntervalSeconds() * 1000);
}, this.getPingIntervalSeconds() * 1000);
},
/**
* Resize elements in center panel
* to fit the boundary box provided by the layout manager
* to fit the boundary box provided by the layout manager.
* TODO Replace with automated less ugly parent/sibling traversal
*/
_resizeChildren: function() {
$("#treepanes", this).accordion("resize");
@ -196,7 +196,6 @@ var ss_MainLayout;
$('#Form_EditForm fieldset > .ss-tabset > .tab > .ss-tabset', this).fitHeightToParent();
$('#Form_EditForm fieldset > .ss-tabset > .tab > .ss-tabset > .tab', this).fitHeightToParent();
}
};
});
/**
@ -206,8 +205,7 @@ var ss_MainLayout;
*
* @name ss.LeftAndMain.Buttons
*/
$('.LeftAndMain :submit, .LeftAndMain button, .LeftAndMain :reset').concrete('ss', function($){
return/** @lends ss.LeftAndMain.Buttons */{
$('.LeftAndMain :submit, .LeftAndMain button, .LeftAndMain :reset').concrete(/** @lends ss.LeftAndMain.Buttons */{
onmatch: function() {
this.addClass(
'ui-state-default ' +
@ -238,16 +236,13 @@ var ss_MainLayout;
this._super();
}
};
});
/**
* @class Container for tree actions like "create", "search", etc.
* @name ss.TreeActions
*/
$('#TreeActions').concrete('ss', function($){
return/** @lends ss.TreeActions */{
$('#TreeActions').concrete(/** @lends ss.TreeActions */{
/**
* Setup "create", "search", "batch actions" layers above tree.
* All tab contents are closed by default.
@ -259,7 +254,6 @@ var ss_MainLayout;
cookie: { expires: 30, path: '/', name: 'ui-tabs-TreeActions' }
});
}
};
});
/**
@ -267,9 +261,7 @@ var ss_MainLayout;
* through a modal dialog.
* @name ss.EditMemberProfile
*/
$('a#EditMemberProfile').concrete('ss', function($){
return/** @lends ss.EditMemberProfile */{
$('a#EditMemberProfile').concrete(/** @lends ss.EditMemberProfile */{
onmatch: function() {
var self = this;
@ -350,7 +342,6 @@ var ss_MainLayout;
);
}
}
};
});
/**
@ -360,10 +351,7 @@ var ss_MainLayout;
* @name ss.switchViewLinks
* @requires jquery.metadata
*/
$('#switchView a').concrete('ss', function($){
return/** @lends ss.switchViewLinks */{
$('#switchView a').concrete(/** @lends ss.switchViewLinks */{
/**
* @type DOMElement
*/
@ -383,9 +371,9 @@ var ss_MainLayout;
*/
refresh: function() {
// TODO Compatible with nested urls?
var urlSegment = this.Form().find(':input[name=URLSegment]').val();
var urlSegment = this.getForm().find(':input[name=URLSegment]').val();
if(urlSegment) {
var locale = this.Form().find(':input[name=Locale]').val();
var locale = this.getForm().find(':input[name=Locale]').val();
var url = urlSegment;
if(this.metadata().params) url += '?' + this.metadata().params;
if(locale) url += ((url.indexOf('?') > 0) ? '&' : '?') + "locale=" + locale;
@ -401,9 +389,8 @@ var ss_MainLayout;
window.open($(e.target).attr('href'));
return false;
}
};
});
});
}(jQuery));
// Backwards compatibility

View File

@ -1,5 +1,5 @@
(function($) {
$.concrete('ss', function($){
/**
* A simple ajax browser history implementation tailored towards
* navigating through search results and different forms loaded into
@ -20,11 +20,8 @@
*
* @name ss.ModelAdmin
*/
$('.ModelAdmin').concrete('ss', function($){
return/** @lends ss.ModelAdmin */ {
$('.ModelAdmin').concrete(/** @lends ss.ModelAdmin */ {
History: [],
Future: [],
onmatch: function() {
@ -52,8 +49,8 @@
},
redraw: function() {
this.find('.historyNav .forward').toggle(Boolean(this.Future().length > 0));
this.find('.historyNav .back').toggle(Boolean(this.History().length > 1));
this.find('.historyNav .forward').toggle(Boolean(this.getFuture().length > 0));
this.find('.historyNav .back').toggle(Boolean(this.getHistory().length > 1));
},
startHistory: function(url, data) {
@ -74,10 +71,8 @@
if(url.indexOf('?') == -1) url += '?' + $.param(data);
else url += '&' + $.param(data);
}
// Add to history
this.History().push(url);
this.getHistory().push(url);
// Reset future
this.setFuture([]);
@ -85,72 +80,67 @@
},
goBack: function() {
if(this.History() && this.History().length) {
if(this.Future() == null) this.setFuture([]);
if(this.getHistory() && this.getHistory().length) {
if(this.getFuture() == null) this.setFuture([]);
var currentPage = this.History().pop();
var previousPage = this.History()[this.History().length-1];
var currentPage = this.getHistory().pop();
var previousPage = this.getHistory()[this.getHistory().length-1];
this.Future().push(currentPage);
this.getFuture().push(currentPage);
this.trigger('historyGoBack', {url:previousPage});
// load new location
$('#Form_EditForm').concrete('ss').loadForm(previousPage);
$('#Form_EditForm').loadForm(previousPage);
this.redraw();
}
},
goForward: function() {
if(this.Future() && this.Future().length) {
if(this.Future() == null) this.setFuture([]);
if(this.getFuture() && this.getFuture().length) {
if(this.getFuture() == null) this.setFuture([]);
var nextPage = this.Future().pop();
var nextPage = this.getFuture().pop();
this.History().push(nextPage);
this.getHistory().push(nextPage);
this.trigger('historyGoForward', {url:nextPage});
// load new location
$('#Form_EditForm').concrete('ss').loadForm(nextPage);
$('#Form_EditForm').loadForm(nextPage);
this.redraw();
}
}
};
});
/**
* A search action will cause the history to be reset.
*/
$('#SearchForm_holder form').concrete('ss', function($) {
return{
$('#SearchForm_holder form').concrete({
onmatch: function() {
var self = this;
this.bind('beforeSubmit', function(e) {
$('.ModelAdmin').concrete('ss').startHistory(
$('.ModelAdmin').startHistory(
self.attr('action'),
self.serializeArray()
);
});
this._super();
}
};
});
/**
* We have to apply this to the result table buttons instead of the
* more generic form loading.
*/
$('form[name=Form_ResultsForm] tbody td a').concrete('ss', function($) {
return{
onmatch: function() {
var self = this;
this.bind('click', function(e) {
$('.ModelAdmin').addHistory(self.attr('href'));
});
$('form[name=Form_ResultsForm] tbody td a').concrete({
onclick: function(e) {
$('.ModelAdmin').addHistory(this.attr('href'));
}
};
});
});
})(jQuery);

View File

@ -9,6 +9,7 @@
* @todo alias the $ function instead of literal jQuery
*/
(function($) {
$.concrete('ss', function($){
//////////////////////////////////////////////////////////////////
// Search form
@ -19,18 +20,21 @@
*/
$('#ModelClassSelector select').concrete({
onmatch: function() {
var self = this;
// Set up an onchange function to show the applicable form and hide all others
this.bind('change', function(e) {
self.find('option').each(function() {
var $form = $('#'+$(this).val());
if(self.val() == $(this).val()) $form.show();
else $form.hide();
});
});
// Initialise the form by calling this onchange event straight away
this.change();
this._super();
},
/**
* Set up an onchange function to show the applicable form and hide all others
*/
onchange: function(e) {
this.find('option').each(function() {
var $form = $('#'+this.val());
if(this.val() == this.val()) $form.show();
else $form.hide();
});
}
});
/**
@ -41,28 +45,24 @@
* Note: This is used for Form_CreateForm and all Form_SearchForm_* variations
*/
$('#SearchForm_holder form').concrete({
onmatch: function() {
var self = this;
this.bind('submit', function(e) {
onsubmit: function(e) {
// Import forms are processed without ajax
if(self.is('#Form_ImportForm')) return true;
if(this.is('#Form_ImportForm')) return true;
self.trigger('beforeSubmit');
this.trigger('beforeSubmit');
var btn = $(self[0].clickedButton);
var btn = $(this[0].clickedButton);
btn.addClass('loading');
$('#Form_EditForm').concrete('ss').loadForm(
self.attr('action'),
$('#Form_EditForm').loadForm(
this.attr('action'),
function() {
btn.removeClass('loading');
},
{data: self.serialize()}
{data: this.serialize()}
);
return false;
});
}
});
@ -97,14 +97,11 @@
* Table record handler for search result record
*/
$('.resultsTable tbody td').concrete({
onmatch: function() {
// TODO Replace with concrete event handler
this.bind('click', function(e) {
var firstLink = $(this).find('a[href]');
onclick: function(e) {
var firstLink = this.find('a[href]');
if(!firstLink) return;
$('#Form_EditForm').concrete('ss').loadForm(firstLink.attr('href'));
$('#Form_EditForm').loadForm(firstLink.attr('href'));
return false;
});
}
});
@ -112,20 +109,19 @@
* Add object button
*/
$('#Form_ManagedModelsSelect').concrete({
onmatch: function() {
this.bind('submit', function(){
onsubmit: function(e) {
className = $('select option:selected', this).val();
requestPath = $(this).attr('action').replace('ManagedModelsSelect', className + '/add');
requestPath = this.attr('action').replace('ManagedModelsSelect', className + '/add');
var $button = $(':submit', this);
$('#Form_EditForm').concrete('ss').loadForm(
$('#Form_EditForm').loadForm(
requestPath,
function() {
$button.removeClass('loading');
$button = null;
}
);
return false;
});
}
});
@ -133,14 +129,11 @@
* RHS panel Delete button
*/
$('#Form_EditForm input[name=action_doDelete]').concrete({
onmatch: function() {
this.bind('click', function() {
var confirmed = confirm(ss.i18n._t('ModelAdmin.REALLYDELETE', 'Really delete?'));
if(!confirmed) {
$(this).removeClass('loading');
onclick: function(e) {
if(!confirm(ss.i18n._t('ModelAdmin.REALLYDELETE', 'Really delete?'))) {
this.removeClass('loading');
return false;
}
});
}
});
@ -154,7 +147,10 @@
$('#' + $(this).attr('href').replace(/.*#/,'')).toggle();
return false;
});
this._super();
}
});
});
})(jQuery);

View File

@ -1,15 +1,17 @@
jQuery(function($) {
(function($) {
$.concrete('ss', function($){
/**
* @class Tree panel.
* @name ss.sitetree
*/
$('#sitetree').concrete('ss', function($){
return/** @lends ss.sitetree */{
$('#sitetree').concrete(/** @lends ss.sitetree */{
onmatch: function() {
// make sure current ID of loaded form is actually selected in tree
var id = $('#Form_EditForm :input[name=ID]').val();
if (id) this[0].setCurrentByIdx(id);
this._super();
}
};
});
});
}(jQuery));