-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added better visual feedback on required languages
In settings panel. This, again, is a port of code from multilingual text box. Fixes #5
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(function ($, undefined) { | ||
|
||
'use strict'; | ||
|
||
if (!!Symphony.Extensions.MultilingualUploadField) { | ||
return; | ||
} | ||
Symphony.Extensions.MultilingualUploadField = true; | ||
|
||
// from backend.views.js | ||
var change = function (e) { | ||
var selectbox = $(this); | ||
var parent = selectbox.parents('.instance'); | ||
var headline = parent.find('.frame-header h4'); | ||
var values = selectbox.find(':selected'); | ||
var span = headline.find('.required'); | ||
|
||
if(!!values.length) { | ||
var langs = []; | ||
values.each(function (index, elem) { | ||
var text = $(this).text(); | ||
langs.push(text.split(' ||')[0]); | ||
if (index < values.length - 2) { | ||
langs.push(', '); | ||
} else if (index < values.length - 1) { | ||
langs.push(' and '); | ||
} | ||
}); | ||
|
||
if (!span.length) { | ||
span = $('<span />', { | ||
class: 'required' | ||
}).appendTo(headline); | ||
} | ||
|
||
span.text( | ||
'— ' + langs.join('') + ' ' + | ||
Symphony.Language.get(langs.length > 1 ? 'are' : 'is') + ' ' + | ||
Symphony.Language.get('required') | ||
); | ||
} | ||
|
||
// Is not required | ||
else { | ||
headline.find('.required').remove(); | ||
} | ||
}; | ||
|
||
$(function () { | ||
$('.field-multilingual_upload.instance select[name*="[required_languages]"]') | ||
.on('change', change) | ||
.trigger('change'); | ||
}); | ||
|
||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters