View | Details | Raw Unified | Return to bug 11559
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/resources.js (+27 lines)
Line 0 Link Here
1
define( [ 'module', 'xslt' ], function( module, XSLT ) {
2
    var _allResources = [];
3
4
    var Resources = {
5
        GetAll: function() {
6
            return $.when.call( null, _allResources );
7
        }
8
    };
9
10
    function _res( name, deferred ) {
11
        Resources[name] = deferred;
12
        _allResources.push(deferred);
13
    }
14
15
    $.each( module.config().xslt_result_stylesheets, function( syntax, url ) {
16
        _res( 'xslt/result/' + syntax, XSLT.Get( url ) );
17
    } );
18
19
    $.each( module.config().xslt_detail_stylesheets, function( syntax, url ) {
20
        _res( 'xslt/detail/' + syntax, XSLT.Get( url ) );
21
    } );
22
23
    _res( 'marc21/xml/006', $.get( module.config().themelang + '/data/marc21_field_006.xml' ) );
24
    _res( 'marc21/xml/008', $.get( module.config().themelang + '/data/marc21_field_008.xml' ) );
25
26
    return Resources;
27
} );
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js (-33 / +150 lines)
Lines 1-5 Link Here
1
define( function() {
1
define( [ 'resources' ], function( Resources ) {
2
    var _widgets = {};
3
2
    var Widget = {
4
    var Widget = {
5
        Register: function( tagfield, widget ) {
6
            _widgets[tagfield] = widget;
7
        },
8
9
        PadNum: function( number, length ) {
10
            var result = number.toString();
11
12
            while ( result.length < length ) result = '0' + result;
13
14
            return result;
15
        },
16
17
        PadString: function( result, length ) {
18
            while ( result.length < length ) result = ' ' + result;
19
20
            return result;
21
        },
22
23
        PadStringRight: function( result, length ) {
24
            result = '' + result;
25
            while ( result.length < length ) result += ' ';
26
27
            return result;
28
        },
29
3
        Base: {
30
        Base: {
4
            // Marker utils
31
            // Marker utils
5
            clearToText: function() {
32
            clearToText: function() {
Lines 17-25 define( function() { Link Here
17
                var $node = $( this.node ).find( sel );
44
                var $node = $( this.node ).find( sel );
18
                $node.val( this.getFixed( start, end ) );
45
                $node.val( this.getFixed( start, end ) );
19
46
20
                $node.change( $.proxy( function() {
47
                var widget = this;
21
                    this.setFixed( start, end, $node.val(), '+input' );
48
                var $collapsed = $( '<span class="fixed-collapsed" title="' + $node.attr('title') + '">' + $node.val() + '</span>' ).insertAfter( $node );
22
                }, this ) );
49
50
                function show() {
51
                    $collapsed.hide();
52
                    $node.val( widget.getFixed( start, end ).replace(/\s+$/, '') );
53
                    $node.show();
54
                    $node[0].focus();
55
                }
56
57
                function hide() {
58
                    $node.hide();
59
                    $collapsed.text( Widget.PadStringRight( $node.val(), end - start ) ).show();
60
                }
61
62
                $node.on( 'change keyup', function() {
63
                    widget.setFixed( start, end, $node.val(), '+input' );
64
                } ).focus( show ).blur( hide );
65
66
                hide();
67
68
                $collapsed.click( show );
23
            },
69
            },
24
70
25
            getFixed: function( start, end ) {
71
            getFixed: function( start, end ) {
Lines 27-33 define( function() { Link Here
27
            },
73
            },
28
74
29
            setFixed: function( start, end, value, source ) {
75
            setFixed: function( start, end, value, source ) {
30
                this.setText( this.text.substring( 0, start ) + this.padString( value.toString().substr( 0, end - start ), end - start ) + this.text.substring( end ), source );
76
                this.setText( this.text.substring( 0, start ) + Widget.PadStringRight( value.toString().substr( 0, end - start ), end - start ) + this.text.substring( end ), source );
31
            },
77
            },
32
78
33
            setText: function( text, source ) {
79
            setText: function( text, source ) {
Lines 36-41 define( function() { Link Here
36
                this.editor.startNotify();
82
                this.editor.startNotify();
37
            },
83
            },
38
84
85
            createFromXML: function( resourceId ) {
86
                var widget = this;
87
88
                Resources[resourceId].done( function( xml ) {
89
                    $(widget.node).find('.widget-loading').remove();
90
                    var $matSelect = $('<select class="material-select"></select>').appendTo(widget.node);
91
                    var $contents = $('<span class="material-contents"/>').appendTo(widget.node);
92
                    var materialInfo = {};
93
94
                    $('Tagfield', xml).children('Material').each( function() {
95
                        $matSelect.append( '<option value="' + $(this).attr('id') + '">' + $(this).attr('id') + ' - ' + $(this).children('name').text() + '</option>' );
96
97
                        materialInfo[ $(this).attr('id') ] = this;
98
                    } );
99
100
                    $matSelect.change( function() {
101
                        widget.loadXMLMaterial( materialInfo[ $matSelect.val() ] );
102
                    } ).change();
103
                } );
104
            },
105
106
            loadXMLMaterial: function( materialInfo ) {
107
                var $contents = $(this.node).children('.material-contents');
108
                $contents.empty();
109
110
                var widget = this;
111
112
                $(materialInfo).children('Position').each( function() {
113
                    var match = $(this).attr('pos').match(/(\d+)(?:-(\d+))?/);
114
                    if (!match) return;
115
116
                    var start = parseInt(match[1]);
117
                    var end = ( match[2] ? parseInt(match[2]) : start ) + 1;
118
                    var $input;
119
                    var $values = $(this).children('Value');
120
121
                    if ($values.length == 0) {
122
                        $contents.append( '<span title="' + $(this).children('name').text() + '">' + widget.getFixed(start, end) + '</span>' );
123
                        return;
124
                    }
125
126
                    if ( match[2] ) {
127
                        $input = $( '<input name="f' + Widget.PadNum(start, 2) + '" title="' + $(this).children('name').text() + '" maxlength="' + (end - start) + '" />' );
128
                    } else {
129
                        $input = $( '<select name="f' + Widget.PadNum(start, 2) + '" title="' + $(this).children('name').text() + '"></select>' );
130
131
                        $values.each( function() {
132
                            $input.append( '<option value="' + $(this).attr('code') + '">' + $(this).attr('code') + ' - ' + $(this).children('description').text() + '</option>' );
133
                        } );
134
                    }
135
136
                    $contents.append( $input );
137
                    widget.bindFixed( $input, start, end );
138
                } );
139
            },
140
141
            nodeChanged: function() {
142
                this.mark.changed();
143
                var widget = this;
144
145
                var $inputs = $(this.node).find('input, select');
146
                if ( !$inputs.length ) return;
147
148
                $inputs.off('keydown.marc-tab');
149
                var editor = widget.editor;
150
151
                $inputs.each( function( i ) {
152
                    $(this).on( 'keydown.marc-tab', function( e ) {
153
                        if ( e.which != 9 ) return; // Tab
154
155
                        var span = widget.mark.find();
156
                        var cur = editor.cm.getCursor();
157
158
                        if ( e.shiftKey ) {
159
                            if ( i > 0 ) {
160
                                $inputs.eq(i - 1).trigger( 'focus' );
161
                            } else {
162
                                editor.cm.setCursor( span.from );
163
                                // FIXME: ugly hack
164
                                editor.cm.options.extraKeys['Shift-Tab']( editor.cm );
165
                                editor.focus();
166
                            }
167
                        } else {
168
                            if ( i < $inputs.length - 1 ) {
169
                                $inputs.eq(i + 1).trigger( 'focus' );
170
                            } else {
171
                                editor.cm.setCursor( span.to );
172
                                editor.focus();
173
                            }
174
                        }
175
176
                        return false;
177
                    } );
178
                } );
179
            },
180
39
            // Template utils
181
            // Template utils
40
            insertTemplate: function( sel ) {
182
            insertTemplate: function( sel ) {
41
                var wsOnly = /^\s*$/;
183
                var wsOnly = /^\s*$/;
Lines 45-64 define( function() { Link Here
45
                    }
187
                    }
46
                } ).appendTo( this.node );
188
                } ).appendTo( this.node );
47
            },
189
            },
48
49
            padNum: function( number, length ) {
50
                var result = number.toString();
51
52
                while ( result.length < length ) result = '0' + result;
53
54
                return result;
55
            },
56
57
            padString: function( result, length ) {
58
                while ( result.length < length ) result = ' ' + result;
59
60
                return result;
61
            }
62
        },
190
        },
63
191
64
        ActivateAt: function( editor, cur, idx ) {
192
        ActivateAt: function( editor, cur, idx ) {
Lines 119-126 define( function() { Link Here
119
                    }
247
                    }
120
                }
248
                }
121
249
122
                if ( !editorWidgets[id] ) return;
250
                if ( !_widgets[id] ) return;
123
                var fullBase = $.extend( Object.create( Widget.Base ), editorWidgets[id] );
251
                var fullBase = $.extend( Object.create( Widget.Base ), _widgets[id] );
124
                var widget = Object.create( fullBase );
252
                var widget = Object.create( fullBase );
125
253
126
                if ( subfield.from == subfield.to ) {
254
                if ( subfield.from == subfield.to ) {
Lines 148-167 define( function() { Link Here
148
276
149
                if ( widget.postCreate ) {
277
                if ( widget.postCreate ) {
150
                    widget.postCreate();
278
                    widget.postCreate();
151
                    mark.changed();
152
                }
279
                }
153
280
154
                var $lastInput = $(widget.node).find('input, select').eq(-1);
281
                widget.nodeChanged();
155
                if ( $lastInput.length ) {
156
                    $lastInput.bind( 'keypress', 'tab', function() {
157
                        var cur = editor.cm.getCursor();
158
                        editor.cm.setCursor( { line: cur.line } );
159
                        // FIXME: ugly hack
160
                        editor.cm.options.extraKeys.Tab( editor.cm );
161
                        editor.focus();
162
                        return false;
163
                    } );
164
                }
165
            } );
282
            } );
166
        },
283
        },
167
    };
284
    };
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/cateditor.css (-2 / +18 lines)
Lines 118-136 body { Link Here
118
    padding: 4px;
118
    padding: 4px;
119
}
119
}
120
120
121
#editor .subfield-widget select {
121
#editor .subfield-widget select, #editor .subfield-widget input {
122
    height: 1.5em;
122
    height: 1.5em;
123
    vertical-align: middle;
123
    vertical-align: middle;
124
}
124
}
125
125
126
#editor .subfield-widget select:focus {
126
#editor .subfield-widget select:focus {
127
    outline: 1px #83A230 solid;
127
    outline: 2px #83A230 solid;
128
}
129
130
#editor .fixed-widget input {
131
    width: 4em;
128
}
132
}
129
133
130
#editor .fixed-widget select {
134
#editor .fixed-widget select {
131
    width: 3em;
135
    width: 3em;
132
}
136
}
133
137
138
#editor .fixed-widget .material-select {
139
    width: 4.5em;
140
    margin-right: .5em;
141
}
142
143
#editor .fixed-collapsed {
144
    display: inline-block;
145
    margin: 0 .25em;
146
    text-align: center;
147
    text-decoration: underline;
148
}
149
134
#editor .hidden-widget {
150
#editor .hidden-widget {
135
    color: #999999;
151
    color: #999999;
136
    border: solid 2px #AAAAAA;
152
    border: solid 2px #AAAAAA;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc (-20 / +23 lines)
Lines 5-10 Link Here
5
<script>
5
<script>
6
require.config( {
6
require.config( {
7
    baseUrl: '/intranet-tmpl/lib/koha/cateditor/',
7
    baseUrl: '/intranet-tmpl/lib/koha/cateditor/',
8
    config: {
9
        resources: {
10
            xslt_detail_stylesheets: {
11
                [% FOREACH stylesheet IN xslt_detail_stylesheets %]
12
                '[% stylesheet.syntax %]': '[% stylesheet.url %]',
13
                [% END %]
14
            },
15
            xslt_result_stylesheets: {
16
                [% FOREACH stylesheet IN xslt_result_stylesheets %]
17
                '[% stylesheet.syntax %]': '[% stylesheet.url %]',
18
                [% END %]
19
            },
20
            themelang: '[% themelang %]',
21
        },
22
    },
8
    paths: {
23
    paths: {
9
        pz2: '../../pz2',
24
        pz2: '../../pz2',
10
    },
25
    },
Lines 21-39 require.config( { Link Here
21
[% END %]
36
[% END %]
22
37
23
<script>
38
<script>
24
require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'preferences', 'text-marc', 'widget', 'xslt' ], function( KohaBackend, Search, Macros, MARCEditor, MARC, Preferences, TextMARC, Widget, XSLT ) {
39
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 ) {
25
    var xsltResultStylesheets = {
26
        [% FOREACH stylesheet IN xslt_result_stylesheets %]
27
        '[% stylesheet.syntax %]': XSLT.Get( '[% stylesheet.url %]' ),
28
        [% END %]
29
    };
30
31
    var xsltDetailStylesheets = {
32
        [% FOREACH stylesheet IN xslt_detail_stylesheets %]
33
        '[% stylesheet.syntax %]': XSLT.Get( '[% stylesheet.url %]' ),
34
        [% END %]
35
    };
36
37
    var z3950Targets = {
40
    var z3950Targets = {
38
        [% FOREACH target = z3950_targets %]
41
        [% FOREACH target = z3950_targets %]
39
            '[% target.host %]:[% target.port %]/[% target.db %]': {
42
            '[% target.host %]:[% target.port %]/[% target.db %]': {
Lines 78-84 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
78
81
79
                var defaultvalue = subfield.defaultvalue || authvals[0].value;
82
                var defaultvalue = subfield.defaultvalue || authvals[0].value;
80
83
81
                var authorisedWidget = {
84
                Widget.Register( tag + subfield, {
82
                    init: function() {
85
                    init: function() {
83
                        var $result = $( '<span class="subfield-widget"></span>' );
86
                        var $result = $( '<span class="subfield-widget"></span>' );
84
87
Lines 101-109 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
101
                    makeTemplate: function() {
104
                    makeTemplate: function() {
102
                        return defaultvalue;
105
                        return defaultvalue;
103
                    },
106
                    },
104
                };
107
                } );
105
106
                editorWidgets[ tag + subfield ] = authorisedWidget;
107
            } );
108
            } );
108
        } );
109
        } );
109
    }
110
    }
Lines 338-344 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
338
        Search.GetDetailedRecord( hit.recid, function( record ) {
339
        Search.GetDetailedRecord( hit.recid, function( record ) {
339
            if ( fetchOnly ) return;
340
            if ( fetchOnly ) return;
340
341
341
            xsltResultStylesheets[ z3950Targets[ hit.location[0]['@id'] ].kohasyntax ].done( function( xslDoc ) {
342
            Resources[ 'xslt/detail/' + z3950Targets[ hit.location[0]['@id'] ].kohasyntax ].done( function( xslDoc ) {
342
                $tr.find( '.results-info' ).html( XSLT.TransformToFragment( record.xmlSource, xslDoc ) );
343
                $tr.find( '.results-info' ).html( XSLT.TransformToFragment( record.xmlSource, xslDoc ) );
343
            } );
344
            } );
344
        } );
345
        } );
Lines 837-844 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
837
        } );
838
        } );
838
839
839
        function finishCb() {
840
        function finishCb() {
840
            $("#loading").hide();
841
            Resources.GetAll().done( function() {
841
            editor.focus();
842
                $("#loading").hide();
843
                editor.focus();
844
            } );
842
        }
845
        }
843
846
844
        if ( "[% auth_forwarded_hash %]" ) {
847
        if ( "[% auth_forwarded_hash %]" ) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc (-11 / +13 lines)
Lines 84-91 Link Here
84
 * single subfield, '@'.
84
 * single subfield, '@'.
85
 */
85
 */
86
86
87
var editorWidgets = {
87
require( [ 'widget' ], function( Widget ) {
88
    '000@': {
88
    Widget.Register( '000@', {
89
        makeTemplate: function() {
89
        makeTemplate: function() {
90
            return '     nam a22     7a 4500';
90
            return '     nam a22     7a 4500';
91
        },
91
        },
Lines 110-117 var editorWidgets = { Link Here
110
            this.bindFixed( '[name=f18]', 18, 19 );
110
            this.bindFixed( '[name=f18]', 18, 19 );
111
            this.bindFixed( '[name=f19]', 19, 20 );
111
            this.bindFixed( '[name=f19]', 19, 20 );
112
        },
112
        },
113
    },
113
    } );
114
    '005@': {
114
115
    Widget.Register( '005@', {
115
        init: function() {
116
        init: function() {
116
            var $result = $( '<span class="subfield-widget fixed-widget">Updated: </span>' );
117
            var $result = $( '<span class="subfield-widget fixed-widget">Updated: </span>' );
117
118
Lines 136-155 var editorWidgets = { Link Here
136
                $( this.node ).append( '<span class="hint">unset</span>' );
137
                $( this.node ).append( '<span class="hint">unset</span>' );
137
            }
138
            }
138
        }
139
        }
139
    },
140
    } );
140
    '008@': {
141
142
    Widget.Register( '008@', {
141
        makeTemplate: function() {
143
        makeTemplate: function() {
142
            var now = new Date();
144
            var now = new Date();
143
            return this.padNum( now.getYear() % 100, 2 ) + this.padNum( now.getMonth() + 1, 2 ) + this.padNum( now.getDate(), 2 ) + "b        xxu||||| |||| 00| 0 [% DefaultLanguageField008 %] d";
145
            return Widget.PadNum( now.getYear() % 100, 2 ) + Widget.PadNum( now.getMonth() + 1, 2 ) + Widget.PadNum( now.getDate(), 2 ) + "b        xxu||||| |||| 00| 0 [% DefaultLanguageField008 %] d";
144
        },
146
        },
145
        init: function() {
147
        init: function() {
146
            var $result = $( '<span class="subfield-widget fixed-widget">Fixed data: <span class="hint">under construction</span></span>' );
148
            var $result = $( '<span class="subfield-widget fixed-widget">Fixed data:<span class="hint widget-loading">Loading...</span></span>' );
147
149
148
            return $result[0];
150
            return $result[0];
149
        },
151
        },
150
        postCreate: function( node, mark ) {
152
        postCreate: function( node, mark ) {
153
            this.createFromXML( 'marc21/xml/008' );
151
        }
154
        }
152
    }
155
    } );
153
};
156
} );
154
157
155
</script>
158
</script>
156
- 

Return to bug 11559