Owen Leonard
8bf7c342bf
This patch moves strings defined for translation in letter.tt into letter.js for translation using the new double-underscore i81n function. Note, the "MSG_NO_NOTICE_FOUND" usage has been removed because it didn't work. To test, apply the patch and go to Tools -> Notices & Slips. - Use the "Copy" dropdown to copy an existing notice to a specific library. - Save the copied notice. - Return to the "All libraries" view on the Notices & Slips page. - Repeat the same process above: Copy the same notice to the same library. - When you click save on the "Add notice" page you should get an error message, "A letter with the code 'ACCTDETAILS' already exists for <library>" - From the "All libraries" view on the Notices & Slips page, copy the text in the "Code" column of an existing notice. - Click "New notice" and choose the module of the notice you copied from. - On the "Add notice" page, paste the code into the "Code" field and enter a name in the "Name" field. - Click "Save" without making any other changes. You should get an error message, "Please fill at least one template." - Enter some data into one of the message body fields but not message subject, and click "Save" again. - You should get an error, "Please specify title and content for <notice>" - Enter data in the message subject field and click "Save" again. - You should get an error, "A default letter with the code <CODE> already exists." TESTING TRANSLATABILITY - Update a translation, e.g. fr-FR: > cd misc/translator > perl translate update fr-FR - Open the corresponding .po file for JavaScript strings, e.g. misc/translator/po/fr-FR-messages-js.po - Locate strings pulled from koha-tmpl/intranet-tmpl/prog/js/letter.js for translation, e.g.: msgid "Please fill at least one template." msgstr "" - Edit the "msgstr" string however you want (it's just for testing). - Install the updated translation: > perl translate install fr-FR - Switch to your newly translated language in the staff client and repeat the test plan above. The translated strings should appear. Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
204 lines
7 KiB
JavaScript
204 lines
7 KiB
JavaScript
/* Variables defined in letter.tt: */
|
|
/* global _ module add_form copy_form no_op_set code interface theme KohaTable columns_settings */
|
|
|
|
var modal_loading = "<div id=\"loading\"><img src=\"" + interface + "/" + theme + "/img/spinner-small.gif\" alt=\"\" /> "+ __('Loading...') +"</div>";
|
|
|
|
var editing = 0;
|
|
if( add_form == 1 && code !== '' ){
|
|
editing = 1;
|
|
}
|
|
|
|
function checkCodes( new_lettercode, new_branchcode ){
|
|
$(".spinner").show();
|
|
return $.ajax({
|
|
data: { code: new_lettercode, branchcode: new_branchcode },
|
|
type: 'GET',
|
|
url: '/cgi-bin/koha/svc/letters/get/',
|
|
async: !1,
|
|
success: function (data) {
|
|
if ( data.letters.length > 0 ) {
|
|
if( new_branchcode === '' ) {
|
|
alert(__("A default letter with the code '%s' already exists.").format(new_lettercode));
|
|
} else {
|
|
alert(__("A letter with the code '%s' already exists for '%s'.").format(new_lettercode, new_branchcode));
|
|
}
|
|
$(".spinner").hide();
|
|
} else {
|
|
$(".spinner").hide();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
var Sticky;
|
|
|
|
$(document).ready(function() {
|
|
if( add_form || copy_form ){
|
|
Sticky = $("#toolbar");
|
|
Sticky.hcSticky({
|
|
stickTo: ".main",
|
|
stickyClass: "floating"
|
|
});
|
|
}
|
|
|
|
var ntable = KohaTable("lettert", {
|
|
"autoWidth": false,
|
|
"paging": false,
|
|
"aaSorting": [[ 3, "asc" ]],
|
|
"columnDefs": [
|
|
{ "bSortable": false, "aTargets": [ "nosort" ] },
|
|
{ "sType": "title-string", "aTargets" : [ "title-string"] }
|
|
],
|
|
"exportColumns": [0,1,2,3],
|
|
}, columns_settings);
|
|
|
|
if( no_op_set ){
|
|
$('#branch').change(function() {
|
|
$('#op').val("");
|
|
$('#selectlibrary').submit();
|
|
});
|
|
$('#newnotice').click(function() {
|
|
$('#op').val("add_form");
|
|
return true;
|
|
});
|
|
}
|
|
|
|
$("#newmodule").on("change",function(){
|
|
var branchcode;
|
|
if( $("#branch").val() === ""){
|
|
branchcode = "*";
|
|
} else {
|
|
branchcode = $("#branch").val();
|
|
}
|
|
window.location.href = "/cgi-bin/koha/tools/letter.pl?op=add_form&module=" + $(this).val() + "&branchcode=" + branchcode;
|
|
});
|
|
|
|
$("#submit_form").on("click",function(){
|
|
$("#add_notice").submit();
|
|
});
|
|
|
|
$("#add_notice").validate({
|
|
submitHandler: function(form){
|
|
var at_least_one_exists = 0;
|
|
var are_valid = 1;
|
|
$("fieldset.mtt").each( function(){
|
|
var title = $(this).find('input[name="title"]').val();
|
|
var content = $(this).find('textarea[name="content"]').val();
|
|
if (
|
|
( title.length === 0 && content.length > 0 ) || ( title.length > 0 && content.length === 0 )
|
|
) {
|
|
var mtt = $(this).find('input[name="message_transport_type"]').val();
|
|
at_least_one_exists = 1; // Only one template has to be filled in for form to be valid
|
|
alert(__("Please specify title and content for %s").format(mtt));
|
|
are_valid = 0;
|
|
} else if ( title.length > 0 && content.length > 0 ) {
|
|
at_least_one_exists = 1;
|
|
}
|
|
});
|
|
|
|
if ( ! at_least_one_exists ) {
|
|
// No templates were filled out
|
|
alert( __("Please fill at least one template.") );
|
|
return false;
|
|
}
|
|
|
|
if ( ! are_valid ){
|
|
return false;
|
|
}
|
|
|
|
// Test if code already exists in DB
|
|
if( editing == 1 ){ // This is an edit operation
|
|
// We don't need to check for an existing Code
|
|
} else {
|
|
var new_lettercode = $("#code").val();
|
|
var new_branchcode = $("#branch").val();
|
|
var code_check = checkCodes( new_lettercode, new_branchcode );
|
|
if( code_check.responseJSON.letters.length > 0 ){
|
|
return false;
|
|
}
|
|
}
|
|
form.submit();
|
|
}
|
|
});
|
|
|
|
var sms_limit = 160;
|
|
$(".content_sms").on("keyup", function(){
|
|
var length = $(this).val().length;
|
|
var sms_counter = ("#sms_counter_" + $(this).data('lang'));
|
|
$(sms_counter).html(length + "/" + sms_limit + _(" characters"));
|
|
if ( length > sms_limit ) {
|
|
$(sms_counter).css("color", "red");
|
|
} else {
|
|
$(sms_counter).css("color", "black");
|
|
}
|
|
});
|
|
|
|
$( ".transport-types" ).accordion({
|
|
collapsible: true,
|
|
active: parseInt( $("#section").val(), 10),
|
|
animate: 200,
|
|
activate: function() {
|
|
var active = $( ".transport-types" ).accordion( "option", "active" );
|
|
if( active === false ){
|
|
$("#section").val("");
|
|
} else {
|
|
$("#section").val( active );
|
|
}
|
|
}
|
|
});
|
|
|
|
$(".insert").on("click",function(){
|
|
var containerid = $(this).data("containerid");
|
|
insertValueQuery( containerid );
|
|
});
|
|
|
|
$("#saveandcontinue").on("click",function(e){
|
|
e.preventDefault();
|
|
$("#redirect").val("just_save");
|
|
$("#submit_form").click();
|
|
});
|
|
|
|
$("#tabs").tabs();
|
|
|
|
$("body").on("click", ".preview_template", function(e){
|
|
e.preventDefault();
|
|
var mtt = $(this).data("mtt");
|
|
var lang = $(this).data("lang");
|
|
|
|
var code = $("#code").val();
|
|
var content = $("#content_"+mtt+"_"+lang).val();
|
|
var title = $("#title_"+mtt+"_"+lang).val();
|
|
|
|
var is_html = $("#is_html_"+mtt+"_"+lang).val();
|
|
var page = $(this).attr("href");
|
|
var data_preview = $("#data_preview").val();
|
|
page += '?code='+encodeURIComponent(code);
|
|
page += '&title='+encodeURIComponent(title);
|
|
page += '&content='+encodeURIComponent(content);
|
|
page += '&data_preview='+encodeURIComponent(data_preview);
|
|
page += '&is_html='+encodeURIComponent(is_html);
|
|
$("#preview_template .modal-body").load(page + " .main");
|
|
$('#preview_template').modal('show');
|
|
$("#preview_template_button").attr("href", "/cgi-bin/koha/svc/letters/convert?module="+module+"&code="+code+"&mtt="+mtt+"&lang="+lang);
|
|
});
|
|
|
|
$("#preview_template").on("hidden.bs.modal", function(){
|
|
$("#preview_template_label").html("");
|
|
$("#preview_template .modal-body").html( modal_loading );
|
|
});
|
|
|
|
function insertValueQuery(containerid) {
|
|
var fieldset = $("#" + containerid);
|
|
var myQuery = $(fieldset).find('textarea[name="content"]');
|
|
var myListBox = $(fieldset).find('select[name="SQLfieldname"]');
|
|
|
|
if($(myListBox).find('option').length > 0) {
|
|
$(myListBox).find('option').each( function (){
|
|
if ( $(this).attr('selected') && $(this).val().length > 0 ) {
|
|
$(myQuery).insertAtCaret("<<" + $(this).val() + ">>");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
});
|