|
Lines 113-168
require( [ 'koha-backend', 'widget' ], function( KohaBackend, Widget ) {
Link Here
|
| 113 |
}, |
113 |
}, |
| 114 |
} ); |
114 |
} ); |
| 115 |
|
115 |
|
| 116 |
Widget.Register( '001@', { |
116 |
/* Check to see if there are any Control Number entries |
| 117 |
init: function() { |
117 |
* in the authorised values table. |
| 118 |
var $result = $( |
118 |
* If not, let's not show the widget |
| 119 |
'<span class="subfield-widget">' |
119 |
*/ |
| 120 |
+ _("Control number: ") |
120 |
var reg001 = KohaBackend.GetAuthorisedValues( 'CONTROL_NUM_SEQUENCE'); |
| 121 |
+ '<span class="control-number-widget-contents"></span>' |
121 |
if(reg001) { |
| 122 |
+ '<button class="control-number-widget-assign">' + _("Assign next") + '</button>' |
122 |
|
| 123 |
+ '<select class="control-number-widget-sequence"></select>' |
123 |
Widget.Register( '001@', { |
| 124 |
+ '<button class="control-number-widget-override">Override</button>' |
124 |
init: function() { |
| 125 |
+ '</span>' |
125 |
var $result = $( |
| 126 |
); |
126 |
'<span class="subfield-widget">' |
|
|
127 |
+ _("Control number: ") |
| 128 |
+ '<span class="control-number-widget-contents"></span>' |
| 129 |
+ '<button class="control-number-widget-assign">' + _("Assign next") + '</button>' |
| 130 |
+ '<select class="control-number-widget-sequence"></select>' |
| 131 |
+ '<button class="control-number-widget-override">Override</button>' |
| 132 |
+ '</span>' |
| 133 |
); |
| 127 |
|
134 |
|
| 128 |
return $result[0]; |
135 |
return $result[0]; |
| 129 |
}, |
136 |
}, |
| 130 |
setControlNumber: function( text ) { |
137 |
setControlNumber: function( text ) { |
| 131 |
if ( text ) this.setText( text ); |
138 |
if ( text ) this.setText( text ); |
| 132 |
$( this.node ).find('.control-number-widget-contents') |
139 |
$( this.node ).find('.control-number-widget-contents') |
| 133 |
.html( text == '<empty>' ? ( '<span class="hint">' + _("unset") + '</span>' ) : text ); |
140 |
.html( text == '<empty>' ? ( '<span class="hint">' + _("unset") + '</span>' ) : text ); |
| 134 |
this.mark.changed(); |
141 |
this.mark.changed(); |
| 135 |
}, |
142 |
}, |
| 136 |
postCreate: function( node, mark ) { |
143 |
postCreate: function( node, mark ) { |
| 137 |
var widget = this; |
144 |
var widget = this; |
| 138 |
this.setControlNumber( this.text ); |
145 |
this.setControlNumber( this.text ); |
| 139 |
$( this.node ) |
146 |
$( this.node ) |
| 140 |
.find('.control-number-widget-assign').click( function() { |
147 |
.find('.control-number-widget-assign').click( function() { |
| 141 |
var sequence = $( widget.node ).find('.control-number-widget-sequence').val(); |
148 |
var sequence = $( widget.node ).find('.control-number-widget-sequence').val(); |
| 142 |
$.post( |
149 |
$.post( |
| 143 |
'/cgi-bin/koha/svc/cataloguing/control_num_sequences/' + sequence |
150 |
'/cgi-bin/koha/svc/cataloguing/control_num_sequences/' + sequence |
| 144 |
).done( function( result ) { |
151 |
).done( function( result ) { |
| 145 |
if ( result.next_value ) widget.setControlNumber( result.next_value ); |
152 |
if ( result.next_value ) widget.setControlNumber( result.next_value ); |
| 146 |
} ); |
153 |
} ); |
| 147 |
} ).end() |
154 |
} ).end() |
| 148 |
.find('.control-number-widget-override').click( function() { |
155 |
.find('.control-number-widget-override').click( function() { |
| 149 |
var result = prompt( _("Enter new control number") ); |
156 |
var result = prompt( _("Enter new control number") ); |
| 150 |
|
157 |
|
| 151 |
if ( result ) widget.setControlNumber( result ); |
158 |
if ( result ) widget.setControlNumber( result ); |
| 152 |
} ).end(); |
159 |
} ).end(); |
| 153 |
|
160 |
|
| 154 |
var sequence_list = $.map( KohaBackend.GetAuthorisedValues( 'CONTROL_NUM_SEQUENCE' ), function( authval ) { |
161 |
var sequence_list = $.map( KohaBackend.GetAuthorisedValues( 'CONTROL_NUM_SEQUENCE' ), function( authval ) { |
| 155 |
return authval.lib; |
162 |
return authval.lib; |
| 156 |
} ); |
163 |
} ); |
| 157 |
sequence_list.sort(); |
164 |
sequence_list.sort(); |
| 158 |
|
165 |
|
| 159 |
$.each( sequence_list, function( undef, sequence ) { |
166 |
$.each( sequence_list, function( undef, sequence ) { |
| 160 |
$( widget.node ).find('.control-number-widget-sequence').append( '<option>' + sequence + '</option>' ); |
167 |
$( widget.node ).find('.control-number-widget-sequence').append( '<option>' + sequence + '</option>' ); |
| 161 |
} ); |
168 |
} ); |
| 162 |
|
169 |
|
| 163 |
// TODO: Make Enter on select click "Assign" |
170 |
// TODO: Make Enter on select click "Assign" |
| 164 |
} |
171 |
} |
| 165 |
} ); |
172 |
} ); |
|
|
173 |
}; |
| 166 |
|
174 |
|
| 167 |
Widget.Register( '005@', { |
175 |
Widget.Register( '005@', { |
| 168 |
init: function() { |
176 |
init: function() { |
| 169 |
- |
|
|