2011-03-22 09:50:26 +01:00
|
|
|
/**
|
|
|
|
* File: CMSMain.Translatable.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
$.entwine('ss', function($){
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: .CMSMain #Form_LangForm
|
|
|
|
*
|
|
|
|
* Dropdown with languages above CMS tree, causing a redirect upon translation
|
|
|
|
*/
|
|
|
|
$('.CMSMain #Form_LangForm').entwine({
|
|
|
|
/**
|
|
|
|
* Constructor: onmatch
|
|
|
|
*/
|
|
|
|
onmatch: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
// monitor form loading for any locale changes
|
|
|
|
$('#Form_EditForm').bind('loadnewpage', function(e) {
|
|
|
|
var newLocale = $(this).find(':input[name=Locale]').val();
|
|
|
|
if(newLocale) self.val(newLocale);
|
|
|
|
});
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
2012-05-15 17:50:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* whenever a new value is selected, reload the whole CMS in the new locale
|
|
|
|
*/
|
|
|
|
$('.CMSMain #Form_LangForm :input[name=Locale]').entwine({
|
2012-09-03 09:16:41 +02:00
|
|
|
onmatch: function() {
|
|
|
|
// make sure this element is shown, since it might be hidden by chosen before the panel is cached
|
|
|
|
$(this).show();
|
|
|
|
this._super();
|
|
|
|
},
|
2012-05-15 17:50:04 +02:00
|
|
|
onchange: function(e) {
|
2013-03-21 04:01:03 +01:00
|
|
|
// Get new locale code
|
2015-06-01 10:52:07 +02:00
|
|
|
var locale = {Locale: $(e.target).val()};
|
2013-03-21 04:01:03 +01:00
|
|
|
|
|
|
|
// Check existing url
|
2015-06-01 10:52:07 +02:00
|
|
|
search = /Locale=[^&]*/;
|
2013-03-21 04:01:03 +01:00
|
|
|
url = document.location.href;
|
|
|
|
if(url.match(search)) {
|
|
|
|
// Replace locale code
|
|
|
|
url = url.replace(search, $.param(locale));
|
|
|
|
} else {
|
|
|
|
// Add locale code
|
|
|
|
url = $.path.addSearchParams(url, locale);
|
|
|
|
}
|
2012-05-15 17:50:04 +02:00
|
|
|
$('.cms-container').loadPanel(url);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2011-03-22 09:50:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: .CMSMain .createTranslation
|
|
|
|
*
|
|
|
|
* Loads /admin/createtranslation, which will create the new record,
|
|
|
|
* and redirect to an edit form.
|
|
|
|
*
|
|
|
|
* Dropdown in "Translation" tab in CMS forms, with button to
|
|
|
|
* trigger translating the currently loaded record.
|
|
|
|
*
|
|
|
|
* Requires:
|
|
|
|
* jquery.metadata
|
|
|
|
*/
|
2016-03-23 22:55:35 +01:00
|
|
|
$(':input[name=action_createtranslation]').entwine({
|
2011-03-22 09:50:26 +01:00
|
|
|
|
2012-07-16 23:36:15 +02:00
|
|
|
onclick: function(e) {
|
2012-05-15 17:50:04 +02:00
|
|
|
this.parents('form').trigger('submit', [this]);
|
|
|
|
e.preventDefault();
|
2011-03-22 22:15:49 +01:00
|
|
|
return false;
|
2011-03-22 09:50:26 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2016-03-23 22:55:35 +01:00
|
|
|
}(jQuery));
|