Lines 79-84
require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
Link Here
|
79 |
|
79 |
|
80 |
var editor; |
80 |
var editor; |
81 |
var macroEditor; |
81 |
var macroEditor; |
|
|
82 |
var exportRecordEditor; |
82 |
|
83 |
|
83 |
function makeAuthorisedValueWidgets( frameworkCode ) { |
84 |
function makeAuthorisedValueWidgets( frameworkCode ) { |
84 |
$.each( KohaBackend.GetAllTagsInfo( frameworkCode ), function( tag, tagInfo ) { |
85 |
$.each( KohaBackend.GetAllTagsInfo( frameworkCode ), function( tag, tagInfo ) { |
Lines 639-644
require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
Link Here
|
639 |
case 'macros': |
640 |
case 'macros': |
640 |
// Macros loaded on first show of modal |
641 |
// Macros loaded on first show of modal |
641 |
break; |
642 |
break; |
|
|
643 |
case 'exportRecords': |
644 |
// Export Records loaded on first show of modal |
645 |
break; |
642 |
case 'selected_search_targets': |
646 |
case 'selected_search_targets': |
643 |
$.each( z3950Servers, function( server_id, server ) { |
647 |
$.each( z3950Servers, function( server_id, server ) { |
644 |
var saved_val = Preferences.user.selected_search_targets[server_id]; |
648 |
var saved_val = Preferences.user.selected_search_targets[server_id]; |
Lines 720-725
require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
Link Here
|
720 |
Preferences.Save( [% logged_in_user.borrowernumber | html %] ); |
724 |
Preferences.Save( [% logged_in_user.borrowernumber | html %] ); |
721 |
} |
725 |
} |
722 |
|
726 |
|
|
|
727 |
function loadExportRecord( name ) { |
728 |
$( '#export-list li' ).removeClass( 'active' ); |
729 |
exportRecordEditor.activeExportRecord = name; |
730 |
|
731 |
if ( !name ) { |
732 |
exportRecordEditor.setValue( '' ); |
733 |
return; |
734 |
} |
735 |
|
736 |
$( '#export-list li[data-name="' + name + '"]' ).addClass( 'active' ); |
737 |
var exportRecord = Preferences.user.exportRecords[name]; |
738 |
exportRecord.contents = dedupeString(exportRecord.contents); |
739 |
exportRecordEditor.setValue( exportRecord.contents ); |
740 |
exportRecordEditor.setOption( 'readOnly', false ); |
741 |
if ( exportRecord.history ) exportRecordEditor.setHistory( exportRecord.history ); |
742 |
} |
743 |
|
744 |
function dedupeString( strg ) { |
745 |
|
746 |
var pieces = strg.split("\n"); |
747 |
var output = []; //Output array |
748 |
|
749 |
for (var i = 0; i < pieces.length; i++) { |
750 |
if (output.indexOf(pieces[i]) < 0) { |
751 |
output.push(pieces[i]); |
752 |
} |
753 |
} |
754 |
|
755 |
return output.join("\n"); |
756 |
} |
757 |
|
758 |
function storeExportRecord( name, exportRecord ) { |
759 |
if ( exportRecord ) { |
760 |
Preferences.user.exportRecords[name] = exportRecord; |
761 |
} else { |
762 |
delete Preferences.user.exportRecords[name]; |
763 |
} |
764 |
|
765 |
Preferences.Save( [% logged_in_user.borrowernumber | html %] ); |
766 |
} |
767 |
|
768 |
function showSavedExportRecords( exportRecords ) { |
769 |
var scrollTop = $('#export-list').scrollTop(); |
770 |
$( '#export-list').empty(); |
771 |
var export_list = $.map (Preferences.user.exportRecords, function (exportRecord, name) { |
772 |
return $.extend( { name: name}, exportRecord ); |
773 |
} ); |
774 |
export_list.sort ( function ( a, b ) { |
775 |
return a.name.localeCompare(b.name); |
776 |
} ); |
777 |
$.each ( export_list, function ( undef, exportRecord ) { |
778 |
var $li = $( '<li data-name="' + exportRecord.name + '"><a href"#">' + exportRecord.name + '</a><ol class="exportRecord-info"><ol></li>' ); |
779 |
$li.click ( function() { |
780 |
loadExportRecord(exportRecord.name); |
781 |
return false; |
782 |
} ); |
783 |
if ( exportRecord.name == exportRecordEditor.activeExportRecord ) $li.addClass ( 'active' ); |
784 |
var modified = exportRecord.modified && new Date(exportRecord.modified); |
785 |
$('#export-list').append($li); |
786 |
}); |
787 |
var $new_li = $( '<li class="new-exportRecord"><a href="#">' + _("New Export File...") + '</a></li>' ); |
788 |
$new_li.click( function() { |
789 |
var name = prompt(_("Please enter the name for the new export record:")); |
790 |
if (!name) return; |
791 |
|
792 |
if ( !Preferences.user.exportRecords[name] ) storeExportRecord( name, { contents: "" } ); |
793 |
showSavedExportRecords(); |
794 |
loadExportRecord( name ); |
795 |
} ); |
796 |
$('#export-list').append($new_li); |
797 |
$('#export-list').scrollTop(scrollTop); |
798 |
} |
799 |
|
800 |
function saveExportRecord() { |
801 |
var name = exportRecordEditor.activeExportRecord; |
802 |
|
803 |
if ( !name || exportRecordEditor.savedGeneration == exportRecordEditor.changeGeneration() ) return; |
804 |
|
805 |
exportRecordEditor.savedGeneration = exportRecordEditor.changeGeneration(); |
806 |
storeExportRecord( name, { contents: exportRecordEditor.getValue(), modified: (new Date()).valueOf(), history: exportRecordEditor.getHistory() } ); |
807 |
} |
808 |
|
723 |
function showSavedMacros( macros ) { |
809 |
function showSavedMacros( macros ) { |
724 |
var scrollTop = $('#macro-list').scrollTop(); |
810 |
var scrollTop = $('#macro-list').scrollTop(); |
725 |
$( '#macro-list' ).empty(); |
811 |
$( '#macro-list' ).empty(); |
Lines 819-824
require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
Link Here
|
819 |
}, 100); |
905 |
}, 100); |
820 |
} |
906 |
} |
821 |
|
907 |
|
|
|
908 |
$( '#exporter-ui' ).on( 'shown.bs.modal', function() { |
909 |
if ( exportRecordEditor ) return; |
910 |
|
911 |
exportRecordEditor = CodeMirror( |
912 |
$('#export-editor')[0], |
913 |
{ |
914 |
mode: 'null', |
915 |
lineNumbers: true, |
916 |
readOnly: true, |
917 |
} |
918 |
); |
919 |
var saveTimeout; |
920 |
exportRecordEditor.on( 'change', function( cm, change ) { |
921 |
$('#export-save-message').empty(); |
922 |
if ( change.origin == 'setValue' ) return; |
923 |
|
924 |
if ( saveTimeout ) clearTimeout( saveTimeout ); |
925 |
saveTimeout = setTimeout( function() { |
926 |
saveExportRecord(); |
927 |
saveTimeout = null; |
928 |
}, 500 ); |
929 |
} ); |
930 |
|
931 |
showSavedExportRecords(); |
932 |
} ); |
933 |
|
822 |
$( '#macro-ui' ).on( 'shown.bs.modal', function() { |
934 |
$( '#macro-ui' ).on( 'shown.bs.modal', function() { |
823 |
if ( macroEditor ) return; |
935 |
if ( macroEditor ) return; |
824 |
|
936 |
|
Lines 935-940
require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
Link Here
|
935 |
saveRecord( backend + '/', editor, finishCb ); |
1047 |
saveRecord( backend + '/', editor, finishCb ); |
936 |
} |
1048 |
} |
937 |
|
1049 |
|
|
|
1050 |
//Add the record to the exportRecords list if there is one |
1051 |
if(Preferences.user.exportRecords) { |
1052 |
var export_list = $.map (Preferences.user.exportRecords, function (exportRecord, name) { |
1053 |
return $.extend( { name: name}, exportRecord ); |
1054 |
}); |
1055 |
$.each ( export_list, function ( undef, exportRecord ) { |
1056 |
exportRecord.contents += "\n" + state.recordID; |
1057 |
storeExportRecord( exportRecord.name, { contents: exportRecord.contents} ); |
1058 |
} ); |
1059 |
} |
938 |
return false; |
1060 |
return false; |
939 |
} ); |
1061 |
} ); |
940 |
|
1062 |
|
Lines 1027-1032
require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
Link Here
|
1027 |
} |
1149 |
} |
1028 |
} ); |
1150 |
} ); |
1029 |
|
1151 |
|
|
|
1152 |
$('#open-exporter').click( function() { |
1153 |
$('#exporter-ui').modal('show'); |
1154 |
|
1155 |
return false; |
1156 |
} ); |
1157 |
|
1158 |
$('#generate-file').click (function() { |
1159 |
var bibs = exportRecordEditor.getValue(); |
1160 |
bibs = bibs.replace(/\r?\n/g, ",") + ","; |
1161 |
$.post("/cgi-bin/koha/tools/export.pl", {"record_type":"bibs", "export_bibs":bibs, "filename":"test.mrc", "op":"export" }, function (data) { |
1162 |
var blob = new Blob([data], { 'type': 'application/octet-stream;charset=utf-8'}); |
1163 |
saveAs(blob, exportRecordEditor.activeExportRecord + ".mrc" ); |
1164 |
}); |
1165 |
}); |
1166 |
|
1167 |
$('#delete-export-file').click( function() { |
1168 |
if ( !exportRecordEditor.activeExportRecord || !confirm( _("Are you sure you want to delete this Export File?") ) ) return; |
1169 |
|
1170 |
storeExportRecord( exportRecordEditor.activeExportRecord, undefined ); |
1171 |
showSavedExportRecords(); |
1172 |
loadExportRecord( undefined ); |
1173 |
|
1174 |
return false; |
1175 |
} ); |
1176 |
|
1030 |
$( '#show-advanced-search' ).click( function() { |
1177 |
$( '#show-advanced-search' ).click( function() { |
1031 |
showAdvancedSearch(); |
1178 |
showAdvancedSearch(); |
1032 |
|
1179 |
|
Lines 1078-1084
require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
Link Here
|
1078 |
bindGlobalKeys(); |
1225 |
bindGlobalKeys(); |
1079 |
|
1226 |
|
1080 |
// Setup UI |
1227 |
// Setup UI |
1081 |
$("#advanced-search-ui, #search-results-ui, #macro-ui").each( function() { |
1228 |
$("#advanced-search-ui, #search-results-ui, #macro-ui", "#exporter-ui").each( function() { |
1082 |
$(this).modal({ show: false }); |
1229 |
$(this).modal({ show: false }); |
1083 |
} ); |
1230 |
} ); |
1084 |
|
1231 |
|