1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- jQuery(document).ready(function() {
-
- Admin.add_pretty_errors(document);
- Admin.add_collapsed_toggle();
- });
-
-
- var Admin = {
-
- /**
- * render log message
- * @param mixed
- */
- log: function() {
- var msg = '[Sonata.Admin] ' + Array.prototype.join.call(arguments,', ');
- if (window.console && window.console.log) {
- window.console.log(msg);
- }
- else if (window.opera && window.opera.postError) {
- window.opera.postError(msg);
- }
- },
-
- /**
- * display related errors messages
- *
- * @param subject
- */
- add_pretty_errors: function(subject) {
- jQuery('div.sonata-ba-field-error', subject).each(function(index, element) {
- var input = jQuery('input, textarea', element);
-
- var message = jQuery('div.sonata-ba-field-error-messages', element).html();
- jQuery('div.sonata-ba-field-error-messages', element).html('');
- if (!message) {
- message = '';
- }
-
- if (message.length == 0) {
- return;
- }
-
- input.qtip({
- content: message,
- show: 'focusin',
- hide: 'focusout',
- position: {
- corner: {
- target: 'rightMiddle',
- tooltip: 'leftMiddle'
- }
- },
- style: {
- name: 'red',
- border: {
- radius: 2
- },
- tip: 'leftMiddle'
- }
- })
- });
- },
-
- /**
- * Add the collapsed toggle option to the admin
- *
- * @param subject
- */
- add_collapsed_toggle: function(subject) {
- jQuery('fieldset legend a.sonata-ba-collapsed', subject).live('click', function(event) {
- event.preventDefault();
-
- var fieldset = jQuery(this).closest('fieldset');
-
- jQuery('div.sonata-ba-collapsed-fields', fieldset).toggle();
- fieldset.toggleClass('sonata-ba-collapsed-fields-close');
- }).click();
- },
-
- stopEvent: function(event) {
- // https://github.com/sonata-project/SonataAdminBundle/issues/151
- //if it is a standard browser use preventDefault otherwise it is IE then return false
- if(event.preventDefault) {
- event.preventDefault();
- } else {
- event.returnValue = false;
- }
-
- //if it is a standard browser get target otherwise it is IE then adapt syntax and get target
- if (typeof event.target != 'undefined') {
- targetElement = event.target;
- } else {
- targetElement = event.srcElement;
- }
-
- return targetElement;
- }
- }
|