Bugzilla – Attachment 27760 Details for
Bug 11559
Professional cataloger's interface
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11559 followup - Add support for XML-based fixed field widgets
Bug-11559-followup---Add-support-for-XML-based-fix.patch (text/plain), 17.83 KB, created by
Jesse Weaver
on 2014-04-29 08:52:42 UTC
(
hide
)
Description:
Bug 11559 followup - Add support for XML-based fixed field widgets
Filename:
MIME Type:
Creator:
Jesse Weaver
Created:
2014-04-29 08:52:42 UTC
Size:
17.83 KB
patch
obsolete
>From 9b580dcbe3dd9760e79dbe59660cea4c8fbff6c1 Mon Sep 17 00:00:00 2001 >From: Jesse Weaver <pianohacker@gmail.com> >Date: Tue, 8 Apr 2014 17:42:01 -0600 >Subject: [PATCH] Bug 11559 followup - Add support for XML-based fixed field > widgets > >--- > .../intranet-tmpl/lib/koha/cateditor/resources.js | 27 +++ > .../intranet-tmpl/lib/koha/cateditor/widget.js | 183 +++++++++++++++++---- > koha-tmpl/intranet-tmpl/prog/en/css/cateditor.css | 20 ++- > .../prog/en/includes/cateditor-ui.inc | 43 ++--- > .../prog/en/includes/cateditor-widgets-marc21.inc | 23 +-- > 5 files changed, 231 insertions(+), 65 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/lib/koha/cateditor/resources.js > >diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/resources.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/resources.js >new file mode 100644 >index 0000000..365f03d >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/resources.js >@@ -0,0 +1,27 @@ >+define( [ 'module', 'xslt' ], function( module, XSLT ) { >+ var _allResources = []; >+ >+ var Resources = { >+ GetAll: function() { >+ return $.when.call( null, _allResources ); >+ } >+ }; >+ >+ function _res( name, deferred ) { >+ Resources[name] = deferred; >+ _allResources.push(deferred); >+ } >+ >+ $.each( module.config().xslt_result_stylesheets, function( syntax, url ) { >+ _res( 'xslt/result/' + syntax, XSLT.Get( url ) ); >+ } ); >+ >+ $.each( module.config().xslt_detail_stylesheets, function( syntax, url ) { >+ _res( 'xslt/detail/' + syntax, XSLT.Get( url ) ); >+ } ); >+ >+ _res( 'marc21/xml/006', $.get( module.config().themelang + '/data/marc21_field_006.xml' ) ); >+ _res( 'marc21/xml/008', $.get( module.config().themelang + '/data/marc21_field_008.xml' ) ); >+ >+ return Resources; >+} ); >diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js >index 93f53e4..5e7bb48 100644 >--- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js >+++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js >@@ -1,5 +1,32 @@ >-define( function() { >+define( [ 'resources' ], function( Resources ) { >+ var _widgets = {}; >+ > var Widget = { >+ Register: function( tagfield, widget ) { >+ _widgets[tagfield] = widget; >+ }, >+ >+ PadNum: function( number, length ) { >+ var result = number.toString(); >+ >+ while ( result.length < length ) result = '0' + result; >+ >+ return result; >+ }, >+ >+ PadString: function( result, length ) { >+ while ( result.length < length ) result = ' ' + result; >+ >+ return result; >+ }, >+ >+ PadStringRight: function( result, length ) { >+ result = '' + result; >+ while ( result.length < length ) result += ' '; >+ >+ return result; >+ }, >+ > Base: { > // Marker utils > clearToText: function() { >@@ -17,9 +44,28 @@ define( function() { > var $node = $( this.node ).find( sel ); > $node.val( this.getFixed( start, end ) ); > >- $node.change( $.proxy( function() { >- this.setFixed( start, end, $node.val(), '+input' ); >- }, this ) ); >+ var widget = this; >+ var $collapsed = $( '<span class="fixed-collapsed" title="' + $node.attr('title') + '">' + $node.val() + '</span>' ).insertAfter( $node ); >+ >+ function show() { >+ $collapsed.hide(); >+ $node.val( widget.getFixed( start, end ).replace(/\s+$/, '') ); >+ $node.show(); >+ $node[0].focus(); >+ } >+ >+ function hide() { >+ $node.hide(); >+ $collapsed.text( Widget.PadStringRight( $node.val(), end - start ) ).show(); >+ } >+ >+ $node.on( 'change keyup', function() { >+ widget.setFixed( start, end, $node.val(), '+input' ); >+ } ).focus( show ).blur( hide ); >+ >+ hide(); >+ >+ $collapsed.click( show ); > }, > > getFixed: function( start, end ) { >@@ -27,7 +73,7 @@ define( function() { > }, > > setFixed: function( start, end, value, source ) { >- this.setText( this.text.substring( 0, start ) + this.padString( value.toString().substr( 0, end - start ), end - start ) + this.text.substring( end ), source ); >+ this.setText( this.text.substring( 0, start ) + Widget.PadStringRight( value.toString().substr( 0, end - start ), end - start ) + this.text.substring( end ), source ); > }, > > setText: function( text, source ) { >@@ -36,6 +82,102 @@ define( function() { > this.editor.startNotify(); > }, > >+ createFromXML: function( resourceId ) { >+ var widget = this; >+ >+ Resources[resourceId].done( function( xml ) { >+ $(widget.node).find('.widget-loading').remove(); >+ var $matSelect = $('<select class="material-select"></select>').appendTo(widget.node); >+ var $contents = $('<span class="material-contents"/>').appendTo(widget.node); >+ var materialInfo = {}; >+ >+ $('Tagfield', xml).children('Material').each( function() { >+ $matSelect.append( '<option value="' + $(this).attr('id') + '">' + $(this).attr('id') + ' - ' + $(this).children('name').text() + '</option>' ); >+ >+ materialInfo[ $(this).attr('id') ] = this; >+ } ); >+ >+ $matSelect.change( function() { >+ widget.loadXMLMaterial( materialInfo[ $matSelect.val() ] ); >+ } ).change(); >+ } ); >+ }, >+ >+ loadXMLMaterial: function( materialInfo ) { >+ var $contents = $(this.node).children('.material-contents'); >+ $contents.empty(); >+ >+ var widget = this; >+ >+ $(materialInfo).children('Position').each( function() { >+ var match = $(this).attr('pos').match(/(\d+)(?:-(\d+))?/); >+ if (!match) return; >+ >+ var start = parseInt(match[1]); >+ var end = ( match[2] ? parseInt(match[2]) : start ) + 1; >+ var $input; >+ var $values = $(this).children('Value'); >+ >+ if ($values.length == 0) { >+ $contents.append( '<span title="' + $(this).children('name').text() + '">' + widget.getFixed(start, end) + '</span>' ); >+ return; >+ } >+ >+ if ( match[2] ) { >+ $input = $( '<input name="f' + Widget.PadNum(start, 2) + '" title="' + $(this).children('name').text() + '" maxlength="' + (end - start) + '" />' ); >+ } else { >+ $input = $( '<select name="f' + Widget.PadNum(start, 2) + '" title="' + $(this).children('name').text() + '"></select>' ); >+ >+ $values.each( function() { >+ $input.append( '<option value="' + $(this).attr('code') + '">' + $(this).attr('code') + ' - ' + $(this).children('description').text() + '</option>' ); >+ } ); >+ } >+ >+ $contents.append( $input ); >+ widget.bindFixed( $input, start, end ); >+ } ); >+ }, >+ >+ nodeChanged: function() { >+ this.mark.changed(); >+ var widget = this; >+ >+ var $inputs = $(this.node).find('input, select'); >+ if ( !$inputs.length ) return; >+ >+ $inputs.off('keydown.marc-tab'); >+ var editor = widget.editor; >+ >+ $inputs.each( function( i ) { >+ $(this).on( 'keydown.marc-tab', function( e ) { >+ if ( e.which != 9 ) return; // Tab >+ >+ var span = widget.mark.find(); >+ var cur = editor.cm.getCursor(); >+ >+ if ( e.shiftKey ) { >+ if ( i > 0 ) { >+ $inputs.eq(i - 1).trigger( 'focus' ); >+ } else { >+ editor.cm.setCursor( span.from ); >+ // FIXME: ugly hack >+ editor.cm.options.extraKeys['Shift-Tab']( editor.cm ); >+ editor.focus(); >+ } >+ } else { >+ if ( i < $inputs.length - 1 ) { >+ $inputs.eq(i + 1).trigger( 'focus' ); >+ } else { >+ editor.cm.setCursor( span.to ); >+ editor.focus(); >+ } >+ } >+ >+ return false; >+ } ); >+ } ); >+ }, >+ > // Template utils > insertTemplate: function( sel ) { > var wsOnly = /^\s*$/; >@@ -45,20 +187,6 @@ define( function() { > } > } ).appendTo( this.node ); > }, >- >- padNum: function( number, length ) { >- var result = number.toString(); >- >- while ( result.length < length ) result = '0' + result; >- >- return result; >- }, >- >- padString: function( result, length ) { >- while ( result.length < length ) result = ' ' + result; >- >- return result; >- } > }, > > ActivateAt: function( editor, cur, idx ) { >@@ -119,8 +247,8 @@ define( function() { > } > } > >- if ( !editorWidgets[id] ) return; >- var fullBase = $.extend( Object.create( Widget.Base ), editorWidgets[id] ); >+ if ( !_widgets[id] ) return; >+ var fullBase = $.extend( Object.create( Widget.Base ), _widgets[id] ); > var widget = Object.create( fullBase ); > > if ( subfield.from == subfield.to ) { >@@ -148,20 +276,9 @@ define( function() { > > if ( widget.postCreate ) { > widget.postCreate(); >- mark.changed(); > } > >- var $lastInput = $(widget.node).find('input, select').eq(-1); >- if ( $lastInput.length ) { >- $lastInput.bind( 'keypress', 'tab', function() { >- var cur = editor.cm.getCursor(); >- editor.cm.setCursor( { line: cur.line } ); >- // FIXME: ugly hack >- editor.cm.options.extraKeys.Tab( editor.cm ); >- editor.focus(); >- return false; >- } ); >- } >+ widget.nodeChanged(); > } ); > }, > }; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/cateditor.css b/koha-tmpl/intranet-tmpl/prog/en/css/cateditor.css >index d046385..8dd7c06 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/css/cateditor.css >+++ b/koha-tmpl/intranet-tmpl/prog/en/css/cateditor.css >@@ -118,19 +118,35 @@ body { > padding: 4px; > } > >-#editor .subfield-widget select { >+#editor .subfield-widget select, #editor .subfield-widget input { > height: 1.5em; > vertical-align: middle; > } > > #editor .subfield-widget select:focus { >- outline: 1px #83A230 solid; >+ outline: 2px #83A230 solid; >+} >+ >+#editor .fixed-widget input { >+ width: 4em; > } > > #editor .fixed-widget select { > width: 3em; > } > >+#editor .fixed-widget .material-select { >+ width: 4.5em; >+ margin-right: .5em; >+} >+ >+#editor .fixed-collapsed { >+ display: inline-block; >+ margin: 0 .25em; >+ text-align: center; >+ text-decoration: underline; >+} >+ > #editor .hidden-widget { > color: #999999; > border: solid 2px #AAAAAA; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc >index 15bb328..ba2813b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc >@@ -5,6 +5,21 @@ > <script> > require.config( { > baseUrl: '/intranet-tmpl/lib/koha/cateditor/', >+ config: { >+ resources: { >+ xslt_detail_stylesheets: { >+ [% FOREACH stylesheet IN xslt_detail_stylesheets %] >+ '[% stylesheet.syntax %]': '[% stylesheet.url %]', >+ [% END %] >+ }, >+ xslt_result_stylesheets: { >+ [% FOREACH stylesheet IN xslt_result_stylesheets %] >+ '[% stylesheet.syntax %]': '[% stylesheet.url %]', >+ [% END %] >+ }, >+ themelang: '[% themelang %]', >+ }, >+ }, > paths: { > pz2: '../../pz2', > }, >@@ -21,19 +36,7 @@ require.config( { > [% END %] > > <script> >-require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'preferences', 'text-marc', 'widget', 'xslt' ], function( KohaBackend, Search, Macros, MARCEditor, MARC, Preferences, TextMARC, Widget, XSLT ) { >- var xsltResultStylesheets = { >- [% FOREACH stylesheet IN xslt_result_stylesheets %] >- '[% stylesheet.syntax %]': XSLT.Get( '[% stylesheet.url %]' ), >- [% END %] >- }; >- >- var xsltDetailStylesheets = { >- [% FOREACH stylesheet IN xslt_detail_stylesheets %] >- '[% stylesheet.syntax %]': XSLT.Get( '[% stylesheet.url %]' ), >- [% END %] >- }; >- >+require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'preferences', 'resources', 'text-marc', 'widget', 'xslt' ], function( KohaBackend, Search, Macros, MARCEditor, MARC, Preferences, Resources, TextMARC, Widget, XSLT ) { > var z3950Targets = { > [% FOREACH target = z3950_targets %] > '[% target.host %]:[% target.port %]/[% target.db %]': { >@@ -78,7 +81,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr > > var defaultvalue = subfield.defaultvalue || authvals[0].value; > >- var authorisedWidget = { >+ Widget.Register( tag + subfield, { > init: function() { > var $result = $( '<span class="subfield-widget"></span>' ); > >@@ -101,9 +104,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr > makeTemplate: function() { > return defaultvalue; > }, >- }; >- >- editorWidgets[ tag + subfield ] = authorisedWidget; >+ } ); > } ); > } ); > } >@@ -338,7 +339,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr > Search.GetDetailedRecord( hit.recid, function( record ) { > if ( fetchOnly ) return; > >- xsltResultStylesheets[ z3950Targets[ hit.location[0]['@id'] ].kohasyntax ].done( function( xslDoc ) { >+ Resources[ 'xslt/detail/' + z3950Targets[ hit.location[0]['@id'] ].kohasyntax ].done( function( xslDoc ) { > $tr.find( '.results-info' ).html( XSLT.TransformToFragment( record.xmlSource, xslDoc ) ); > } ); > } ); >@@ -837,8 +838,10 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr > } ); > > function finishCb() { >- $("#loading").hide(); >- editor.focus(); >+ Resources.GetAll().done( function() { >+ $("#loading").hide(); >+ editor.focus(); >+ } ); > } > > if ( "[% auth_forwarded_hash %]" ) { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc >index ef6035d..bfba1ba 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc >@@ -84,8 +84,8 @@ > * single subfield, '@'. > */ > >-var editorWidgets = { >- '000@': { >+require( [ 'widget' ], function( Widget ) { >+ Widget.Register( '000@', { > makeTemplate: function() { > return ' nam a22 7a 4500'; > }, >@@ -110,8 +110,9 @@ var editorWidgets = { > this.bindFixed( '[name=f18]', 18, 19 ); > this.bindFixed( '[name=f19]', 19, 20 ); > }, >- }, >- '005@': { >+ } ); >+ >+ Widget.Register( '005@', { > init: function() { > var $result = $( '<span class="subfield-widget fixed-widget">Updated: </span>' ); > >@@ -136,20 +137,22 @@ var editorWidgets = { > $( this.node ).append( '<span class="hint">unset</span>' ); > } > } >- }, >- '008@': { >+ } ); >+ >+ Widget.Register( '008@', { > makeTemplate: function() { > var now = new Date(); >- return this.padNum( now.getYear() % 100, 2 ) + this.padNum( now.getMonth() + 1, 2 ) + this.padNum( now.getDate(), 2 ) + "b xxu||||| |||| 00| 0 [% DefaultLanguageField008 %] d"; >+ return Widget.PadNum( now.getYear() % 100, 2 ) + Widget.PadNum( now.getMonth() + 1, 2 ) + Widget.PadNum( now.getDate(), 2 ) + "b xxu||||| |||| 00| 0 [% DefaultLanguageField008 %] d"; > }, > init: function() { >- var $result = $( '<span class="subfield-widget fixed-widget">Fixed data: <span class="hint">under construction</span></span>' ); >+ var $result = $( '<span class="subfield-widget fixed-widget">Fixed data:<span class="hint widget-loading">Loading...</span></span>' ); > > return $result[0]; > }, > postCreate: function( node, mark ) { >+ this.createFromXML( 'marc21/xml/008' ); > } >- } >-}; >+ } ); >+} ); > > </script> >-- >1.9.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11559
:
26069
|
26070
|
26071
|
26104
|
26653
|
26654
|
27140
|
27141
|
27142
|
27757
|
27758
|
27759
|
27760
|
27761
|
27900
|
27901
|
27902
|
27993
|
27995
|
34458
|
34459
|
34460
|
34461
|
34462
|
34463
|
36243
|
36244
|
36245
|
36246
|
36247
|
36248
|
36455
|
38533
|
38534
|
38535
|
38536
|
38537
|
38538
|
38539
|
40153
|
40154
|
40155
|
40543
|
40555
|
40556
|
40557
|
40558
|
40811
|
40812
|
40813
|
40814
|
40815
|
41425
|
41453
|
41476
|
42373
|
43261
|
43547
|
43614
|
43615
|
43616
|
43617
|
43618
|
43619
|
43620
|
43621
|
43622
|
43623
|
43703
|
43704
|
43705
|
43706
|
43707
|
43708
|
43709
|
43710
|
43711
|
43712
|
43713
|
43772
|
43790
|
43883
|
43969
|
44016
|
44018
|
44022
|
44023
|
44024
|
44025
|
44026
|
44027
|
44028
|
44029
|
44030
|
44031
|
44032
|
44033
|
44034
|
44035
|
44036