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

(-)a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js (-459 / +1 lines)
Lines 55-519 function isNum(v,maybenull) { Link Here
55
    return true;
55
    return true;
56
}
56
}
57
57
58
//=======================================================================
59
60
//=======================================================================
61
// Functions for drag-and-drop functionality
62
63
if( typeof(YAHOO) === "object"){
64
    (function() {
65
66
    var Dom = YAHOO.util.Dom;
67
    var Event = YAHOO.util.Event;
68
    var DDM = YAHOO.util.DragDropMgr;
69
70
    DDApp = {
71
        init: function() {
72
        var uls = document.getElementsByTagName('ul');
73
        var i,j;
74
        var ddtarget;
75
        for (i=0; i<uls.length;i=i+1) {
76
            if (uls[i].className == "draglist" || uls[i].className == "draglist_alt") {
77
                ddtarget = YAHOO.util.DragDropMgr.getDDById(uls[i].id);
78
    // The yahoo drag and drop is written (broken or not) in such a way, that if an element is subscribed as a target multiple times,
79
    // it has to be unlinked multiple times, so we need to test whether it is allready a target, otherwise we'll have a problem when closing the group
80
                if( ! ddtarget ) {
81
                    new YAHOO.util.DDTarget(uls[i].id);
82
                }
83
                var children = uls[i].getElementsByTagName('li');
84
                for( j=0; j<children.length; j=j+1) {
85
    // The yahoo drag and drop is (broken or not) in such a way, that if an element is subscribed as a target multiple times,
86
    // it has to be unlinked multiple times, so we need to test whether it is allready a target, otherwise we'll have a problem when closing the group
87
                    ddtarget = YAHOO.util.DragDropMgr.getDDById(children[j].id);
88
                    if( ! ddtarget ) {
89
                        new DDList(children[j].id);
90
                    }
91
                }
92
            }
93
        }
94
        }
95
    };
96
97
98
    // drag and drop implementation
99
100
    DDList = function(id, sGroup, config) {
101
102
        DDList.superclass.constructor.call(this, id, sGroup, config);
103
104
        this.logger = this.logger || YAHOO;
105
        var el = this.getDragEl();
106
        Dom.setStyle(el, "opacity", 0.67); // The proxy is slightly transparent
107
108
        this.goingUp = false;
109
        this.lastY = 0;
110
    };
111
112
    YAHOO.extend(DDList, YAHOO.util.DDProxy, {
113
114
        startDrag: function(x, y) {
115
            this.logger.log(this.id + " startDrag");
116
117
            // make the proxy look like the source element
118
            var dragEl = this.getDragEl();
119
            var clickEl = this.getEl();
120
            Dom.setStyle(clickEl, "visibility", "hidden");
121
122
            dragEl.innerHTML = clickEl.innerHTML;
123
124
            Dom.setStyle(dragEl, "color", Dom.getStyle(clickEl, "color"));
125
            Dom.setStyle(dragEl, "backgroundColor", Dom.getStyle(clickEl, "backgroundColor"));
126
            Dom.setStyle(dragEl, "border", "2px solid gray");
127
        },
128
129
        endDrag: function(e) {
130
131
            var srcEl = this.getEl();
132
            var proxy = this.getDragEl();
133
134
            // Show the proxy element and animate it to the src element's location
135
            Dom.setStyle(proxy, "visibility", "");
136
            var a = new YAHOO.util.Motion(
137
                proxy, {
138
                    points: {
139
                        to: Dom.getXY(srcEl)
140
                    }
141
                },
142
                0.2,
143
                YAHOO.util.Easing.easeOut
144
            )
145
            var proxyid = proxy.id;
146
            var thisid = this.id;
147
148
            // Hide the proxy and show the source element when finished with the animation
149
            a.onComplete.subscribe(function() {
150
                    Dom.setStyle(proxyid, "visibility", "hidden");
151
                    Dom.setStyle(thisid, "visibility", "");
152
                });
153
            a.animate();
154
    // if we are in basketgrouping page, when finished moving, edit the basket's info to reflect new status
155
            if(typeof(basketgroups) != 'undefined') {
156
                a.onComplete.subscribe(function() {
157
                    var reg = new RegExp("[-]+", "g");
158
    // add a changed input to each moved basket, so we know which baskets to modify,
159
    // and so we don't need to modify each and every basket and basketgroup each time the page is loaded
160
    // FIXME: we shouldn't use getElementsByTagName, it's not explicit enough :-(
161
                    srcEl.getElementsByTagName('input')[1].value = "1";
162
                    if ( srcEl.parentNode.parentNode.className == "workarea" ) {
163
                        var dstbgroupid = srcEl.parentNode.parentNode.getElementsByTagName('input')[srcEl.parentNode.parentNode.getElementsByTagName('input').length-2].name.split(reg)[1];
164
                        srcEl.className="grouped";
165
                        srcEl.getElementsByTagName('input')[0].value = dstbgroupid;
166
    //FIXME: again, we shouldn't be using getElementsByTagName!!
167
                        srcEl.parentNode.parentNode.getElementsByTagName('input')[srcEl.parentNode.parentNode.getElementsByTagName('input').length-1].value = 1;
168
                    }
169
                    else if ( srcEl.parentNode.parentNode.className == "workarea_alt" ){
170
                            srcEl.className="ungrouped";
171
                            srcEl.getElementsByTagName('input')[0].value = "0";
172
                    }
173
                });
174
            }
175
        },
176
177
        onDragDrop: function(e, id) {
178
179
            // If there is one drop interaction, the li was dropped either on the list,
180
            // or it was dropped on the current location of the source element.
181
            if (DDM.interactionInfo.drop.length === 1) {
182
183
                // The position of the cursor at the time of the drop (YAHOO.util.Point)
184
                var pt = DDM.interactionInfo.point;
185
186
                // The region occupied by the source element at the time of the drop
187
                var region = DDM.interactionInfo.sourceRegion;
188
189
                // Check to see if we are over the source element's location.  We will
190
                // append to the bottom of the list once we are sure it was a drop in
191
                // the negative space (the area of the list without any list items)
192
                if (!region.intersect(pt)) {
193
                    var destEl = Dom.get(id);
194
                    var destDD = DDM.getDDById(id);
195
                    destEl.appendChild(this.getEl());
196
                    destDD.isEmpty = false;
197
                    DDM.refreshCache();
198
                }
199
            }
200
        },
201
202
        onDrag: function(e) {
203
204
            // Keep track of the direction of the drag for use during onDragOver
205
            var y = Event.getPageY(e);
206
207
            if (y < this.lastY) {
208
                this.goingUp = true;
209
            } else if (y > this.lastY) {
210
                this.goingUp = false;
211
            }
212
            this.lastY = y;
213
        },
214
215
        onDragOver: function(e, id) {
216
217
            var srcEl = this.getEl();
218
            var destEl = Dom.get(id);
219
220
            // We are only concerned with list items, we ignore the dragover
221
            // notifications for the list.
222
            if (destEl.nodeName.toLowerCase() == "li") {
223
                var orig_p = srcEl.parentNode;
224
                var p = destEl.parentNode;
225
226
                if (this.goingUp) {
227
                    p.insertBefore(srcEl, destEl); // insert above
228
                } else {
229
                    p.insertBefore(srcEl, destEl.nextSibling); // insert below
230
                }
231
232
                DDM.refreshCache();
233
            }
234
        }
235
    });
236
    })();
237
}
238
239
240
241
//creates new group, parameter is the group's name
242
function newGroup(event, name) {
243
    if (name == ''){
244
        return 0;
245
    }
246
    if (!enterpressed(event) && event != "button"){
247
        return false;
248
    }
249
    var pardiv = document.getElementById('groups');
250
    var newdiv = document.createElement('div');
251
    var newh3 = document.createElement('h3');
252
    var newul = document.createElement('ul');
253
    var newclose = document.createElement('a');
254
    var newrename = document.createElement('a');
255
    var newbasketgroupname = document.createElement('input');
256
    var nbgclosed = document.createElement('input');
257
    var newp = document.createElement('p');
258
    var reg=new RegExp("[-]+", "g");
259
    var i = 0;
260
    var maxid = 0;
261
    while( i < pardiv.getElementsByTagName('input').length ){
262
        if (! isNaN(parseInt(pardiv.getElementsByTagName('input')[i].name.split(reg)[1])) && parseInt(pardiv.getElementsByTagName('input')[i].name.split(reg)[1]) > maxid){
263
            maxid = parseInt(pardiv.getElementsByTagName('input')[i].name.split(reg)[1]);
264
        }
265
        ++i;
266
    }
267
// var bgid = parseInt(pardiv.getElementsByTagName('input')[pardiv.getElementsByTagName('input').length-2].name.split(reg)[1]) + 1;
268
    var bgid = maxid + 1;
269
    var newchanged = document.createElement('input');
270
271
    newul.id="bg-"+bgid;
272
    newul.className='draglist';
273
274
    newh3.innerHTML=name;
275
//    newh3.style.display="inline";
276
277
    newclose.innerHTML="close";
278
    newclose.href="javascript: closebasketgroup('"+bgid+"', 'bg-"+bgid+"');";
279
280
    newrename.href="javascript:" + "renameinit("+bgid+");";
281
    newrename.innerHTML="rename";
282
283
//    newp.style.display="inline";
284
    newp.innerHTML=" [ ";
285
    newp.appendChild(newrename);
286
    newp.innerHTML+=" / ";
287
    newp.appendChild(newclose);
288
    newp.innerHTML+=" ]";
289
290
    newbasketgroupname.type="hidden";
291
    newbasketgroupname.name="basketgroup-" + bgid + "-name";
292
    newbasketgroupname.id = "basketgroup-" + bgid + "-name";
293
    newbasketgroupname.value=name;
294
295
    nbgclosed.type="hidden";
296
    nbgclosed.name="basketgroup-" + bgid + "-closed";
297
    nbgclosed.value="0";
298
    nbgclosed.id=nbgclosed.name;
299
300
    newchanged.type="hidden";
301
    newchanged.id="basketgroup-"+bgid+"-changed";
302
    newchanged.name=newchanged.id;
303
    newchanged.value="1";
304
305
    newdiv.style.backgroundColor='red';
306
    newdiv.appendChild(newh3);
307
    newdiv.appendChild(newp);
308
    newdiv.appendChild(newul);
309
    newdiv.appendChild(newbasketgroupname);
310
    newdiv.appendChild(nbgclosed);
311
    newdiv.appendChild(newchanged);
312
    newdiv.className='workarea';
313
    pardiv.appendChild(newdiv);
314
315
    YAHOO.util.Event.onDOMReady(DDApp.init, DDApp, true);
316
}
317
318
//this traps enters in input fields
319
function enterpressed(event){
320
    var keycode;
321
    if (window.event) keycode = window.event.keyCode;
322
    else if (event) keycode = event.which;
323
    else return false;
324
325
    if (keycode == 13)
326
    {
327
        return true;
328
    }
329
    else return false;
330
}
331
332
333
58
334
335
336
//Closes a basketgroup
337
function closebasketgroup(bgid) {
338
    var answer=confirm(_("Are you sure you want to close this basketgroup?"));
339
    if(! answer){
340
        return;
341
    }
342
    ulid = 'bg-'+bgid;
343
    var i = 0;
344
    tagname='basketgroup-'+bgid+'-closed';
345
    var ddtarget;
346
    var closeinput = document.getElementById(tagname);
347
    closeinput.value = 1;
348
    var changed = document.getElementById("basketgroup-"+bgid+"-changed");
349
    changed.value=1;
350
351
    var div = document.getElementById(tagname).parentNode;
352
    var stufftoremove = div.getElementsByTagName('p')[0];
353
    var ul = document.getElementById(ulid);
354
    var lis = ul.getElementsByTagName('li');
355
    if (lis.length == 0 ) {
356
        alert(_("Why close an empty basket?"));
357
        return;
358
    }
359
    var cantprint = document.createElement('p');
360
361
    div.className = "closed";
362
    ul.className="closed";
363
364
    for(i=0; i<lis.length; ++i) {
365
        ddtarget = YAHOO.util.DragDropMgr.getDDById(lis[i].id);
366
        ddtarget.unreg();
367
    }
368
    ddtarget = YAHOO.util.DragDropMgr.getDDById(ul.id);
369
    ddtarget.unreg();
370
    div.removeChild(stufftoremove);
371
// the print button is disabled because the page's content might (or is probably) not in sync with what the database contains
372
    cantprint.innerHTML=_("You need to save the page before printing");
373
    cantprint.id = 'cantprint-' + bgid;
374
    var unclosegroup = document.createElement('a');
375
    unclosegroup.href='javascript:unclosegroup('+bgid+');';
376
    unclosegroup.innerHTML=_("reopen basketgroup");
377
    unclosegroup.id = 'unclose-' + bgid;
378
379
    div.appendChild(cantprint);
380
    div.appendChild(unclosegroup);
381
}
382
383
function closeandprint(bg){
384
	if(document.location = '/cgi-bin/koha/acqui/basketgroup.pl?op=closeandprint&amp;basketgroupid=' + bg ){
385
		setTimeout("window.location.reload();",3000);
386
	}else{
387
		alert(_("Error downloading the file"));
388
	}
389
}
390
391
//function that lets the user unclose a basketgroup as long as he hasn't submitted the changes to the page.
392
function unclosegroup(bgid){
393
    var div = document.getElementById('basketgroup-'+bgid+'-closed').parentNode;
394
    var divtodel = document.getElementById('unclose-' + bgid);
395
    if (divtodel){
396
        div.removeChild(divtodel);
397
    }
398
    divtodel = document.getElementById('unclose-' + bgid);
399
    if (divtodel){
400
        div.removeChild(divtodel);
401
    }
402
    var closeinput = document.getElementById('basketgroup-'+bgid+'-closed');
403
    var ul = document.getElementById('bg-'+bgid);
404
405
    var newclose = document.createElement('a');
406
    var newrename = document.createElement('a');
407
    var newp = document.createElement('p');
408
409
    newclose.innerHTML="close";
410
    newclose.href="javascript: closebasketgroup('"+bgid+"', 'bg-"+bgid+"');";
411
412
    newrename.href="javascript:" + "renameinit("+bgid+");";
413
    newrename.innerHTML="rename";
414
    
415
    var todel = div.getElementsByTagName('p')[0];
416
    div.removeChild(todel);
417
    
418
    var changed = document.getElementById("basketgroup-"+bgid+"-changed");
419
    changed.value=1;
420
421
    newp.innerHTML=" [ ";
422
    newp.appendChild(newrename);
423
    newp.innerHTML+=" / ";
424
    newp.appendChild(newclose);
425
    newp.innerHTML+=" ]";
426
427
    div.insertBefore(newp, ul);
428
    closeinput.value="0";
429
    div.className = "workarea";
430
    ul.className="draglist";
431
432
//rescan draglists, we have a new target (again :-)
433
    YAHOO.util.Event.onDOMReady(DDApp.init, DDApp, true);
434
}
435
436
//a function to filter basketgroups using a regex (javascript regex)
437
function filterGroups(event, searchstring ){
438
    if (!enterpressed(event) && event != "button"){
439
        return false;
440
    }
441
    var reg = new RegExp(searchstring, "g");
442
    var Dom = YAHOO.util.Dom;
443
    var divs = Dom.getElementsByClassName("workarea", "div");
444
445
    for (var i = 0; i < divs.length; ++i){
446
        if (! reg.exec(divs[i].innerHTML)){
447
            divs[i].style.display='none';
448
        }
449
        else {
450
            divs[i].style.display='';
451
        }
452
    }
453
    divs = Dom.getElementsByClassName("closed", "div");
454
    for (var i = 0; i < divs.length; ++i){
455
        if (! reg.exec(divs[i].innerHTML)){
456
            divs[i].style.display='none';
457
        }
458
        else {
459
            divs[i].style.display='';
460
        }
461
    }
462
}
463
464
//function to hide (or show) closed baskets (if show is true, it shows all the closed baskets)
465
function showhideclosegroups(show){
466
    var Dom = YAHOO.util.Dom;
467
    var divs = Dom.getElementsByClassName("closed", "div");
468
    var display;
469
    if (show){
470
        display = '';
471
    }
472
    else display = 'none';
473
    for(var i = 0; i < divs.length; ++i){
474
        divs[i].style.display=display;
475
    }
476
}
477
478
function renameinit(bgid){
479
    var ul = document.getElementById('bg-'+bgid);
480
    var div = ul.parentNode;
481
    var nameelm = div.getElementsByTagName('h3')[0];
482
    var p = div.getElementsByTagName('p')[0];
483
484
485
    var nameinput = document.createElement("input");
486
    nameinput.type = "text";
487
    nameinput.id="rename-"+bgid;
488
    nameinput.value = nameelm.innerHTML;
489
    nameinput.onkeypress = function(e){rename(e, bgid, document.getElementById('rename-'+bgid).value); };
490
//    nameinput.setAttribute('onkeypress', 'rename(event, bgid, document.getElementById(rename-'+bgid+').value);');
491
492
    div.removeChild(nameelm);
493
    div.insertBefore(nameinput, p);
494
}
495
496
function rename(event, bgid, name){
497
    if (!enterpressed(event)){
498
        return false;
499
    }
500
    var ul = document.getElementById('bg-'+bgid);
501
    var div = ul.parentNode;
502
    var p = div.getElementsByTagName('p')[0];
503
    var nameinput = document.getElementById("rename-"+bgid);
504
    var changedinput = document.getElementById("basketgroup-"+bgid+"-changed");
505
    var newh3 = document.createElement("h3");
506
    var hiddenname = document.getElementById("basketgroup-"+bgid+"-name");
507
508
    div.removeChild(nameinput);
509
510
    newh3.innerHTML=name;
511
    hiddenname.value=name;
512
    changedinput.value = 1;
513
    div.insertBefore(newh3, p);
514
}
515
516
//=======================================================================
517
//a logging function (a bit buggy, might open millions of log pages when initializing, but works fine after...
59
//a logging function (a bit buggy, might open millions of log pages when initializing, but works fine after...
518
function log(message) {
60
function log(message) {
519
    if (!log.window_ || log.window_.closed) {
61
    if (!log.window_ || log.window_.closed) {
Lines 891-894 function hideAllColumns(){ Link Here
891
    $("#selections span").removeClass("selected");
433
    $("#selections span").removeClass("selected");
892
    $("#plan td:nth-child(2),#plan th:nth-child(2)").nextUntil("th:nth-child("+(allCols-1)+"),td:nth-child("+(allCols-1)+")").hide(); // hide all but the last two columns
434
    $("#plan td:nth-child(2),#plan th:nth-child(2)").nextUntil("th:nth-child("+(allCols-1)+"),td:nth-child("+(allCols-1)+")").hide(); // hide all but the last two columns
893
    $("#hideall").attr("checked","checked").parent().addClass("selected");
435
    $("#hideall").attr("checked","checked").parent().addClass("selected");
894
}
436
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/basketgroup.js (+329 lines)
Line 0 Link Here
1
// Functions for drag-and-drop functionality
2
3
var Dom = YAHOO.util.Dom;
4
var Event = YAHOO.util.Event;
5
var DDM = YAHOO.util.DragDropMgr;
6
7
DDApp = {
8
    init: function() {
9
    var uls = document.getElementsByTagName('ul');
10
    var i,j;
11
    var ddtarget;
12
    for (i=0; i<uls.length;i=i+1) {
13
        if (uls[i].className == "draglist" || uls[i].className == "draglist_alt") {
14
            ddtarget = YAHOO.util.DragDropMgr.getDDById(uls[i].id);
15
// The yahoo drag and drop is written (broken or not) in such a way, that if an element is subscribed as a target multiple times,
16
// it has to be unlinked multiple times, so we need to test whether it is allready a target, otherwise we'll have a problem when closing the group
17
            if( ! ddtarget ) {
18
                new YAHOO.util.DDTarget(uls[i].id);
19
            }
20
            var children = uls[i].getElementsByTagName('li');
21
            for( j=0; j<children.length; j=j+1) {
22
// The yahoo drag and drop is (broken or not) in such a way, that if an element is subscribed as a target multiple times,
23
// it has to be unlinked multiple times, so we need to test whether it is allready a target, otherwise we'll have a problem when closing the group
24
                ddtarget = YAHOO.util.DragDropMgr.getDDById(children[j].id);
25
                if( ! ddtarget ) {
26
                    new DDList(children[j].id);
27
                }
28
            }
29
        }
30
    }
31
    }
32
};
33
34
35
// drag and drop implementation
36
37
DDList = function(id, sGroup, config) {
38
39
    DDList.superclass.constructor.call(this, id, sGroup, config);
40
41
    this.logger = this.logger || YAHOO;
42
    var el = this.getDragEl();
43
    Dom.setStyle(el, "opacity", 0.67); // The proxy is slightly transparent
44
45
    this.goingUp = false;
46
    this.lastY = 0;
47
};
48
49
YAHOO.extend(DDList, YAHOO.util.DDProxy, {
50
51
    startDrag: function(x, y) {
52
        this.logger.log(this.id + " startDrag");
53
54
        // make the proxy look like the source element
55
        var dragEl = this.getDragEl();
56
        var clickEl = this.getEl();
57
        Dom.setStyle(clickEl, "visibility", "hidden");
58
59
        dragEl.innerHTML = clickEl.innerHTML;
60
61
        Dom.setStyle(dragEl, "color", Dom.getStyle(clickEl, "color"));
62
        Dom.setStyle(dragEl, "backgroundColor", Dom.getStyle(clickEl, "backgroundColor"));
63
        Dom.setStyle(dragEl, "border", "2px solid gray");
64
    },
65
66
    endDrag: function(e) {
67
68
        var srcEl = this.getEl();
69
        var proxy = this.getDragEl();
70
71
        // Show the proxy element and animate it to the src element's location
72
        Dom.setStyle(proxy, "visibility", "");
73
        var a = new YAHOO.util.Motion(
74
            proxy, {
75
                points: {
76
                    to: Dom.getXY(srcEl)
77
                }
78
            },
79
            0.2,
80
            YAHOO.util.Easing.easeOut
81
        )
82
        var proxyid = proxy.id;
83
        var thisid = this.id;
84
85
        // Hide the proxy and show the source element when finished with the animation
86
        a.onComplete.subscribe(function() {
87
                Dom.setStyle(proxyid, "visibility", "hidden");
88
                Dom.setStyle(thisid, "visibility", "");
89
            });
90
        a.animate();
91
// if we are in basketgrouping page, when finished moving, edit the basket's info to reflect new status
92
        if(typeof(basketgroups) != 'undefined') {
93
            a.onComplete.subscribe(function() {
94
                var reg = new RegExp("[-]+", "g");
95
// add a changed input to each moved basket, so we know which baskets to modify,
96
// and so we don't need to modify each and every basket and basketgroup each time the page is loaded
97
// FIXME: we shouldn't use getElementsByTagName, it's not explicit enough :-(
98
                srcEl.getElementsByTagName('input')[1].value = "1";
99
                if ( srcEl.parentNode.parentNode.className == "workarea" ) {
100
                    var dstbgroupid = srcEl.parentNode.parentNode.getElementsByTagName('input')[srcEl.parentNode.parentNode.getElementsByTagName('input').length-2].name.split(reg)[1];
101
                    srcEl.className="grouped";
102
                    srcEl.getElementsByTagName('input')[0].value = dstbgroupid;
103
//FIXME: again, we shouldn't be using getElementsByTagName!!
104
                    srcEl.parentNode.parentNode.getElementsByTagName('input')[srcEl.parentNode.parentNode.getElementsByTagName('input').length-1].value = 1;
105
                }
106
                else if ( srcEl.parentNode.parentNode.className == "workarea_alt" ){
107
                        srcEl.className="ungrouped";
108
                        srcEl.getElementsByTagName('input')[0].value = "0";
109
                }
110
            });
111
        }
112
    },
113
114
    onDragDrop: function(e, id) {
115
116
        // If there is one drop interaction, the li was dropped either on the list,
117
        // or it was dropped on the current location of the source element.
118
        if (DDM.interactionInfo.drop.length === 1) {
119
120
            // The position of the cursor at the time of the drop (YAHOO.util.Point)
121
            var pt = DDM.interactionInfo.point;
122
123
            // The region occupied by the source element at the time of the drop
124
            var region = DDM.interactionInfo.sourceRegion;
125
126
            // Check to see if we are over the source element's location.  We will
127
            // append to the bottom of the list once we are sure it was a drop in
128
            // the negative space (the area of the list without any list items)
129
            if (!region.intersect(pt)) {
130
                var destEl = Dom.get(id);
131
                var destDD = DDM.getDDById(id);
132
                destEl.appendChild(this.getEl());
133
                destDD.isEmpty = false;
134
                DDM.refreshCache();
135
            }
136
        }
137
    },
138
139
    onDrag: function(e) {
140
141
        // Keep track of the direction of the drag for use during onDragOver
142
        var y = Event.getPageY(e);
143
144
        if (y < this.lastY) {
145
            this.goingUp = true;
146
        } else if (y > this.lastY) {
147
            this.goingUp = false;
148
        }
149
        this.lastY = y;
150
    },
151
152
    onDragOver: function(e, id) {
153
154
        var srcEl = this.getEl();
155
        var destEl = Dom.get(id);
156
157
        // We are only concerned with list items, we ignore the dragover
158
        // notifications for the list.
159
        if (destEl.nodeName.toLowerCase() == "li") {
160
            var orig_p = srcEl.parentNode;
161
            var p = destEl.parentNode;
162
163
            if (this.goingUp) {
164
                p.insertBefore(srcEl, destEl); // insert above
165
            } else {
166
                p.insertBefore(srcEl, destEl.nextSibling); // insert below
167
            }
168
169
            DDM.refreshCache();
170
        }
171
    }
172
});
173
174
//this traps enters in input fields
175
function enterpressed(event){
176
    var keycode;
177
    if (window.event) keycode = window.event.keyCode;
178
    else if (event) keycode = event.which;
179
    else return false;
180
181
    if (keycode == 13)
182
    {
183
        return true;
184
    }
185
    else return false;
186
}
187
188
189
//Closes a basketgroup
190
function closebasketgroup(bgid) {
191
    var answer=confirm(_("Are you sure you want to close this basketgroup?"));
192
    if(! answer){
193
        return;
194
    }
195
    ulid = 'bg-'+bgid;
196
    var i = 0;
197
    tagname='basketgroup-'+bgid+'-closed';
198
    var ddtarget;
199
    var closeinput = document.getElementById(tagname);
200
    closeinput.value = 1;
201
    var changed = document.getElementById("basketgroup-"+bgid+"-changed");
202
    changed.value=1;
203
204
    var div = document.getElementById(tagname).parentNode;
205
    var stufftoremove = div.getElementsByTagName('p')[0];
206
    var ul = document.getElementById(ulid);
207
    var lis = ul.getElementsByTagName('li');
208
    if (lis.length == 0 ) {
209
        alert(_("Why close an empty basket?"));
210
        return;
211
    }
212
    var cantprint = document.createElement('p');
213
214
    div.className = "closed";
215
    ul.className="closed";
216
217
    for(i=0; i<lis.length; ++i) {
218
        ddtarget = YAHOO.util.DragDropMgr.getDDById(lis[i].id);
219
        ddtarget.unreg();
220
    }
221
    ddtarget = YAHOO.util.DragDropMgr.getDDById(ul.id);
222
    ddtarget.unreg();
223
    div.removeChild(stufftoremove);
224
// the print button is disabled because the page's content might (or is probably) not in sync with what the database contains
225
    cantprint.innerHTML=_("You need to save the page before printing");
226
    cantprint.id = 'cantprint-' + bgid;
227
    var unclosegroup = document.createElement('a');
228
    unclosegroup.href='javascript:unclosegroup('+bgid+');';
229
    unclosegroup.innerHTML=_("reopen basketgroup");
230
    unclosegroup.id = 'unclose-' + bgid;
231
232
    div.appendChild(cantprint);
233
    div.appendChild(unclosegroup);
234
}
235
236
function closeandprint(bg){
237
    if(document.location = '/cgi-bin/koha/acqui/basketgroup.pl?op=closeandprint&amp;basketgroupid=' + bg ){
238
        setTimeout("window.location.reload();",3000);
239
    }else{
240
        alert(_("Error downloading the file"));
241
    }
242
}
243
244
//function that lets the user unclose a basketgroup as long as he hasn't submitted the changes to the page.
245
function unclosegroup(bgid){
246
    var div = document.getElementById('basketgroup-'+bgid+'-closed').parentNode;
247
    var divtodel = document.getElementById('unclose-' + bgid);
248
    if (divtodel){
249
        div.removeChild(divtodel);
250
    }
251
    divtodel = document.getElementById('unclose-' + bgid);
252
    if (divtodel){
253
        div.removeChild(divtodel);
254
    }
255
    var closeinput = document.getElementById('basketgroup-'+bgid+'-closed');
256
    var ul = document.getElementById('bg-'+bgid);
257
258
    var newclose = document.createElement('a');
259
    var newrename = document.createElement('a');
260
    var newp = document.createElement('p');
261
262
    newclose.innerHTML="close";
263
    newclose.href="javascript: closebasketgroup('"+bgid+"', 'bg-"+bgid+"');";
264
265
    newrename.href="javascript:" + "renameinit("+bgid+");";
266
    newrename.innerHTML="rename";
267
268
    var todel = div.getElementsByTagName('p')[0];
269
    div.removeChild(todel);
270
271
    var changed = document.getElementById("basketgroup-"+bgid+"-changed");
272
    changed.value=1;
273
274
    newp.innerHTML=" [ ";
275
    newp.appendChild(newrename);
276
    newp.innerHTML+=" / ";
277
    newp.appendChild(newclose);
278
    newp.innerHTML+=" ]";
279
280
    div.insertBefore(newp, ul);
281
    closeinput.value="0";
282
    div.className = "workarea";
283
    ul.className="draglist";
284
285
//rescan draglists, we have a new target (again :-)
286
    YAHOO.util.Event.onDOMReady(DDApp.init, DDApp, true);
287
}
288
289
290
291
function renameinit(bgid){
292
    var ul = document.getElementById('bg-'+bgid);
293
    var div = ul.parentNode;
294
    var nameelm = div.getElementsByTagName('h3')[0];
295
    var p = div.getElementsByTagName('p')[0];
296
297
298
    var nameinput = document.createElement("input");
299
    nameinput.type = "text";
300
    nameinput.id="rename-"+bgid;
301
    nameinput.value = nameelm.innerHTML;
302
    nameinput.onkeypress = function(e){rename(e, bgid, document.getElementById('rename-'+bgid).value); };
303
//    nameinput.setAttribute('onkeypress', 'rename(event, bgid, document.getElementById(rename-'+bgid+').value);');
304
305
    div.removeChild(nameelm);
306
    div.insertBefore(nameinput, p);
307
}
308
309
function rename(event, bgid, name){
310
    if (!enterpressed(event)){
311
        return false;
312
    }
313
    var ul = document.getElementById('bg-'+bgid);
314
    var div = ul.parentNode;
315
    var p = div.getElementsByTagName('p')[0];
316
    var nameinput = document.getElementById("rename-"+bgid);
317
    var changedinput = document.getElementById("basketgroup-"+bgid+"-changed");
318
    var newh3 = document.createElement("h3");
319
    var hiddenname = document.getElementById("basketgroup-"+bgid+"-name");
320
321
    div.removeChild(nameinput);
322
323
    newh3.innerHTML=name;
324
    hiddenname.value=name;
325
    changedinput.value = 1;
326
    div.insertBefore(newh3, p);
327
}
328
329
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt (-2 / +1 lines)
Lines 9-15 Link Here
9
<script type="text/javascript" src="[% yuipath %]/button/button-min.js"></script>
9
<script type="text/javascript" src="[% yuipath %]/button/button-min.js"></script>
10
<script type="text/javascript" src="[% yuipath %]/container/container_core-min.js"></script>
10
<script type="text/javascript" src="[% yuipath %]/container/container_core-min.js"></script>
11
<script type="text/javascript" src="[% yuipath %]/menu/menu-min.js"></script>
11
<script type="text/javascript" src="[% yuipath %]/menu/menu-min.js"></script>
12
<script type="text/javascript" src="[% themelang %]/js/acq.js"></script>
12
<script type="text/javascript" src="[% themelang %]/js/basketgroup.js"></script>
13
[% IF ( grouping ) %]
13
[% IF ( grouping ) %]
14
<script type="text/javascript" src="[% yuipath %]/yahoo-dom-event/yahoo-dom-event.js"></script>
14
<script type="text/javascript" src="[% yuipath %]/yahoo-dom-event/yahoo-dom-event.js"></script>
15
<script type="text/javascript" src="[% yuipath %]/animation/animation-min.js"></script>
15
<script type="text/javascript" src="[% yuipath %]/animation/animation-min.js"></script>
16
- 

Return to bug 10533