[Koha-patches] [PATCH 31/78] Forgotten js & pl webservice
paul.poulain at biblibre.com
paul.poulain at biblibre.com
Thu May 28 18:32:41 CEST 2009
From: Paul Poulain <paul.poulain at biblibre.com>
---
acqui/check_budget_total.pl | 49 ++
koha-tmpl/intranet-tmpl/prog/en/js/acq.js | 968 +++++++++++++++++++++++++++++
2 files changed, 1017 insertions(+), 0 deletions(-)
create mode 100755 acqui/check_budget_total.pl
create mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/acq.js
diff --git a/acqui/check_budget_total.pl b/acqui/check_budget_total.pl
new file mode 100755
index 0000000..723e5ae
--- /dev/null
+++ b/acqui/check_budget_total.pl
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+
+# Copyright 2008-2009 BibLibre SARL
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+
+use strict;
+use CGI;
+use C4::Context;
+use C4::Output;
+use C4::Auth;
+use C4::Budgets;
+
+=head1
+
+fetches the budget amount fron the DB
+
+=cut
+
+my $input = new CGI;
+my $budget_id = $input->param('budget_id');
+my $total = $input->param('total');
+
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+ { template_name => "acqui/ajax.tmpl",
+ query => $input,
+ type => "intranet",
+ authnotrequired => 0,
+ debug => 1, } );
+
+my $budget = GetBudget($budget_id);
+
+$template->param( return => $budget->{'budget_amount'} );
+
+output_html_with_http_headers $input, $cookie, $template->output;
+1;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js
new file mode 100644
index 0000000..88061fc
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js
@@ -0,0 +1,968 @@
+//=======================================================================
+//input validation:
+// acqui/uncertainprice.tmpl uses this
+function uncheckbox(form, field) {
+ var price = new Number(form.elements['price' + field].value);
+ var tmpprice = "";
+ var errmsg = "ERROR: Price is not a valid number, please check the price and try again!"
+ if (isNaN(price)) {
+ alert(errmsg);
+ for(var i=0; i<form.elements['price' + field].value.length; ++i) {
+ price = new Number(form.elements['price' + field].value[i]);
+ if(! isNaN(price) || form.elements['price' + field].value[i] == ".") {
+ tmpprice += form.elements['price' + field].value[i];
+ }
+ }
+ form.elements['price' + field].value = tmpprice;
+ return false;
+ }
+ form.elements['uncertainprice' + field].checked = false;
+ return true;
+}
+
+// returns false if value is empty
+function isNotNull(f,noalert) {
+ if (f.value.length ==0) {
+ return false;
+ }
+ return true;
+}
+
+function isNull(f,noalert) {
+ if (f.value.length > 0) {
+ return false;
+ }
+ return true;
+}
+
+
+
+
+
+
+
+//Function returns false if v is not a number (if maybenull is 0, it also returns an error if the number is 0)
+function isNum(v,maybenull) {
+ var n = new Number(v.value);
+ if (isNaN(n)) {
+ return false;
+ }
+ if (maybenull==0 && v.value=='') {
+
+
+ return false;
+ }
+ return true;
+}
+
+// this function checks if date is like DD/MM/YYYY
+function CheckDate(field) {
+ var d = field.value;
+ if (d!="") {
+ var amin = 1900;
+ var amax = 2100;
+ var date = d.split("/");
+ var ok=1;
+ var msg;
+ if ( (date.length < 2) && (ok==1) ) {
+ msg = _("Separator must be /");
+ alert(msg); ok=0; field.focus();
+ return false;
+ }
+ var dd = date[0];
+ var mm = date[1];
+ var yyyy = date[2];
+ // checking days
+ if ( ((isNaN(dd))||(dd<1)||(dd>31)) && (ok==1) ) {
+ msg = _("day not correct.");
+ alert(msg); ok=0; field.focus();
+ return false;
+ }
+ // checking months
+ if ( ((isNaN(mm))||(mm<1)||(mm>12)) && (ok==1) ) {
+ msg = _("month not correct.");
+ alert(msg); ok=0; field.focus();
+ return false;
+ }
+ // checking years
+ if ( ((isNaN(yyyy))||(yyyy<amin)||(yyyy>amax)) && (ok==1) ) {
+ msg = _("years not correct.");
+ alert(msg); ok=0; field.focus();
+ return false;
+ }
+ // check day/month combination
+ if ((mm==4 || mm==6 || mm==9 || mm==11) && dd==31) {
+ msg = _("Invalid Day/Month combination. Please ensure that you have a valid day/month combination.");
+ alert(msg); ok=0; field.focus();
+ return false;
+ }
+ // check for february 29th
+ if (mm == 2) {
+ var isleap = (yyyy % 4 == 0 && (yyyy % 100 != 0 || yyyy % 400 == 0));
+ if (dd>29 || (dd==29 && !isleap)) {
+ msg = _("Invalid Day. This year is not a leap year. Please enter a value less than 29 for the day.");
+ alert(msg); ok=0; field.focus();
+ return false
+ }
+ }
+ }
+ return true;
+}
+
+// Checks wether start date is greater than end date
+function CompareDate(startdate, enddate) {
+ startdate=startdate.split("/");
+ syear = startdate[2];
+ smonth = startdate[1];
+ sday = startdate[0];
+ enddate=enddate.split("/");
+ eyear = enddate[2];
+ emonth = enddate[1];
+ eday = enddate[0];
+
+ var sdate = new Date(syear,smonth-1,sday);
+ var edate = new Date(eyear,emonth-1,eday);
+ if (sdate > edate) {
+ msg = _("Start date after end date, please check the dates!");
+ alert(msg); ok=0; field.focus();
+ return false;
+ }
+ return true;
+}
+
+// checks wether end date is before today, returns false if it is
+function CheckEndDate(enddate) {
+ enddate=enddate.split("/");
+ eyear = enddate[2];
+ emonth = enddate[1];
+ eday = enddate[0];
+ var edate = new Date(eyear,emonth-1,eday);
+ var today = new Date( );
+ if (today > edate) {
+ msg = _("End date before today, Invalid end date!");
+ alert(msg); ok=0; field.focus();
+ return false;
+ }
+ return true;
+}
+
+
+
+//=======================================================================
+
+//=======================================================================
+// Functions for drag-and-drop functionality
+
+
+(function() {
+
+var Dom = YAHOO.util.Dom;
+var Event = YAHOO.util.Event;
+var DDM = YAHOO.util.DragDropMgr;
+
+DDApp = {
+ init: function() {
+ var uls = document.getElementsByTagName('ul');
+ var i,j;
+ var ddtarget;
+ for (i=0; i<uls.length;i=i+1) {
+ if (uls[i].className == "draglist" || uls[i].className == "draglist_alt") {
+ ddtarget = YAHOO.util.DragDropMgr.getDDById(uls[i].id);
+// 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,
+// it has to be unlinked multiple times, so we need to test wether it is allready a target, otherwise we'll have a problem when closing the group
+ if( ! ddtarget ) {
+ new YAHOO.util.DDTarget(uls[i].id);
+ }
+ var children = uls[i].getElementsByTagName('li');
+ for( j=0; j<children.length; j=j+1) {
+// The yahoo drag and drop is (broken or not) in such a way, that if an element is subscribed as a target multiple times,
+// it has to be unlinked multiple times, so we need to test wether it is allready a target, otherwise we'll have a problem when closing the group
+ ddtarget = YAHOO.util.DragDropMgr.getDDById(children[j].id);
+ if( ! ddtarget ) {
+ new DDList(children[j].id);
+ }
+ }
+ }
+ }
+ }
+};
+
+
+// drag and drop implementation
+
+DDList = function(id, sGroup, config) {
+
+ DDList.superclass.constructor.call(this, id, sGroup, config);
+
+ this.logger = this.logger || YAHOO;
+ var el = this.getDragEl();
+ Dom.setStyle(el, "opacity", 0.67); // The proxy is slightly transparent
+
+ this.goingUp = false;
+ this.lastY = 0;
+};
+
+YAHOO.extend(DDList, YAHOO.util.DDProxy, {
+
+ startDrag: function(x, y) {
+ this.logger.log(this.id + " startDrag");
+
+ // make the proxy look like the source element
+ var dragEl = this.getDragEl();
+ var clickEl = this.getEl();
+ Dom.setStyle(clickEl, "visibility", "hidden");
+
+ dragEl.innerHTML = clickEl.innerHTML;
+
+ Dom.setStyle(dragEl, "color", Dom.getStyle(clickEl, "color"));
+ Dom.setStyle(dragEl, "backgroundColor", Dom.getStyle(clickEl, "backgroundColor"));
+ Dom.setStyle(dragEl, "border", "2px solid gray");
+ },
+
+ endDrag: function(e) {
+
+ var srcEl = this.getEl();
+ var proxy = this.getDragEl();
+
+ // Show the proxy element and animate it to the src element's location
+ Dom.setStyle(proxy, "visibility", "");
+ var a = new YAHOO.util.Motion(
+ proxy, {
+ points: {
+ to: Dom.getXY(srcEl)
+ }
+ },
+ 0.2,
+ YAHOO.util.Easing.easeOut
+ )
+ var proxyid = proxy.id;
+ var thisid = this.id;
+
+ // Hide the proxy and show the source element when finished with the animation
+ a.onComplete.subscribe(function() {
+ Dom.setStyle(proxyid, "visibility", "hidden");
+ Dom.setStyle(thisid, "visibility", "");
+ });
+ a.animate();
+// if we are in basketgrouping page, when finished moving, edit the basket's info to reflect new status
+ if(typeof(basketgroups) != 'undefined') {
+ a.onComplete.subscribe(function() {
+ var reg = new RegExp("[-]+", "g");
+// add a changed input to each moved basket, so we know which baskets to modify,
+// and so we don't need to modify each and every basket and basketgroup each time the page is loaded
+// FIXME: we shouldn't use getElementsByTagName, it's not explicit enough :-(
+ srcEl.getElementsByTagName('input')[1].value = "1";
+ if ( srcEl.parentNode.parentNode.className == "workarea" ) {
+ var dstbgroupid = srcEl.parentNode.parentNode.getElementsByTagName('input')[srcEl.parentNode.parentNode.getElementsByTagName('input').length-2].name.split(reg)[1];
+ srcEl.className="grouped";
+ srcEl.getElementsByTagName('input')[0].value = dstbgroupid;
+//FIXME: again, we shouldn't be using getElementsByTagName!!
+ srcEl.parentNode.parentNode.getElementsByTagName('input')[srcEl.parentNode.parentNode.getElementsByTagName('input').length-1].value = 1;
+ }
+ else if ( srcEl.parentNode.parentNode.className == "workarea_alt" ){
+ srcEl.className="ungrouped";
+ srcEl.getElementsByTagName('input')[0].value = "0";
+ }
+ });
+ }
+ },
+
+ onDragDrop: function(e, id) {
+
+ // If there is one drop interaction, the li was dropped either on the list,
+ // or it was dropped on the current location of the source element.
+ if (DDM.interactionInfo.drop.length === 1) {
+
+ // The position of the cursor at the time of the drop (YAHOO.util.Point)
+ var pt = DDM.interactionInfo.point;
+
+ // The region occupied by the source element at the time of the drop
+ var region = DDM.interactionInfo.sourceRegion;
+
+ // Check to see if we are over the source element's location. We will
+ // append to the bottom of the list once we are sure it was a drop in
+ // the negative space (the area of the list without any list items)
+ if (!region.intersect(pt)) {
+ var destEl = Dom.get(id);
+ var destDD = DDM.getDDById(id);
+ destEl.appendChild(this.getEl());
+ destDD.isEmpty = false;
+ DDM.refreshCache();
+ }
+ }
+ },
+
+ onDrag: function(e) {
+
+ // Keep track of the direction of the drag for use during onDragOver
+ var y = Event.getPageY(e);
+
+ if (y < this.lastY) {
+ this.goingUp = true;
+ } else if (y > this.lastY) {
+ this.goingUp = false;
+ }
+ this.lastY = y;
+ },
+
+ onDragOver: function(e, id) {
+
+ var srcEl = this.getEl();
+ var destEl = Dom.get(id);
+
+ // We are only concerned with list items, we ignore the dragover
+ // notifications for the list.
+ if (destEl.nodeName.toLowerCase() == "li") {
+ var orig_p = srcEl.parentNode;
+ var p = destEl.parentNode;
+
+ if (this.goingUp) {
+ p.insertBefore(srcEl, destEl); // insert above
+ } else {
+ p.insertBefore(srcEl, destEl.nextSibling); // insert below
+ }
+
+ DDM.refreshCache();
+ }
+ }
+});
+})();
+
+
+
+
+//creates new group, parameter is the group's name
+function newGroup(event, name) {
+ if (name == ''){
+ return 0;
+ }
+ if (!enterpressed(event) && event != "button"){
+ return false;
+ }
+ var pardiv = document.getElementById('groups');
+ var newdiv = document.createElement('div');
+ var newh3 = document.createElement('h3');
+ var newul = document.createElement('ul');
+ var newclose = document.createElement('a');
+ var newrename = document.createElement('a');
+ var newbasketgroupname = document.createElement('input');
+ var nbgclosed = document.createElement('input');
+ var newp = document.createElement('p');
+ var reg=new RegExp("[-]+", "g");
+ var i = 0;
+ var maxid = 0;
+ while( i < pardiv.getElementsByTagName('input').length ){
+ if (! isNaN(parseInt(pardiv.getElementsByTagName('input')[i].name.split(reg)[1])) && parseInt(pardiv.getElementsByTagName('input')[i].name.split(reg)[1]) > maxid){
+ maxid = parseInt(pardiv.getElementsByTagName('input')[i].name.split(reg)[1]);
+ }
+ ++i;
+ }
+// var bgid = parseInt(pardiv.getElementsByTagName('input')[pardiv.getElementsByTagName('input').length-2].name.split(reg)[1]) + 1;
+ var bgid = maxid + 1;
+ var newchanged = document.createElement('input');
+
+ newul.id="bg-"+bgid;
+ newul.className='draglist';
+
+ newh3.innerHTML=name;
+// newh3.style.display="inline";
+
+ newclose.innerHTML="close";
+ newclose.href="javascript: closebasketgroup('"+bgid+"', 'bg-"+bgid+"');";
+
+ newrename.href="javascript:" + "renameinit("+bgid+");";
+ newrename.innerHTML="rename";
+
+// newp.style.display="inline";
+ newp.innerHTML=" [ ";
+ newp.appendChild(newrename);
+ newp.innerHTML+=" / ";
+ newp.appendChild(newclose);
+ newp.innerHTML+=" ]";
+
+ newbasketgroupname.type="hidden";
+ newbasketgroupname.name="basketgroup-" + bgid + "-name";
+ newbasketgroupname.id = "basketgroup-" + bgid + "-name";
+ newbasketgroupname.value=name;
+
+ nbgclosed.type="hidden";
+ nbgclosed.name="basketgroup-" + bgid + "-closed";
+ nbgclosed.value="0";
+ nbgclosed.id=nbgclosed.name;
+
+ newchanged.type="hidden";
+ newchanged.id="basketgroup-"+bgid+"-changed";
+ newchanged.name=newchanged.id;
+ newchanged.value="1";
+
+ newdiv.style.backgroundColor='red';
+ newdiv.appendChild(newh3);
+ newdiv.appendChild(newp);
+ newdiv.appendChild(newul);
+ newdiv.appendChild(newbasketgroupname);
+ newdiv.appendChild(nbgclosed);
+ newdiv.appendChild(newchanged);
+ newdiv.className='workarea';
+ pardiv.appendChild(newdiv);
+
+ YAHOO.util.Event.onDOMReady(DDApp.init, DDApp, true);
+}
+
+//this traps enters in input fields
+function enterpressed(event){
+ var keycode;
+ if (window.event) keycode = window.event.keyCode;
+ else if (event) keycode = event.which;
+ else return false;
+
+ if (keycode == 13)
+ {
+ return true;
+ }
+ else return false;
+}
+
+
+
+
+
+//Closes a basketgroup
+function closebasketgroup(bgid) {
+ var answer=confirm(_("Are you sure you want to close this basketgroup?"));
+ if(! answer){
+ return;
+ }
+ ulid = 'bg-'+bgid;
+ var i = 0;
+ tagname='basketgroup-'+bgid+'-closed';
+ var ddtarget;
+ var closeinput = document.getElementById(tagname);
+ closeinput.value = 1;
+ var changed = document.getElementById("basketgroup-"+bgid+"-changed");
+ changed.value=1;
+
+ var div = document.getElementById(tagname).parentNode;
+ var stufftoremove = div.getElementsByTagName('p')[0];
+ var ul = document.getElementById(ulid);
+ var lis = ul.getElementsByTagName('li');
+ if (lis.length == 0 ) {
+ alert(_("Why close an empty basket?"));
+ return;
+ }
+ var cantprint = document.createElement('p');
+
+ div.className = "closed";
+ ul.className="closed";
+
+ for(i=0; i<lis.length; ++i) {
+ ddtarget = YAHOO.util.DragDropMgr.getDDById(lis[i].id);
+ ddtarget.unreg();
+ }
+ ddtarget = YAHOO.util.DragDropMgr.getDDById(ul.id);
+ ddtarget.unreg();
+ div.removeChild(stufftoremove);
+// the print button is disabled because the page's content might (or is probably) not in sync with what the database contains
+ cantprint.innerHTML=_("You need to save the page before printing");
+ cantprint.id = 'cantprint-' + bgid;
+ var unclosegroup = document.createElement('a');
+ unclosegroup.href='javascript:unclosegroup('+bgid+');';
+ unclosegroup.innerHTML=_("unclose basketgroup");
+ unclosegroup.id = 'unclose-' + bgid;
+
+ div.appendChild(cantprint);
+ div.appendChild(unclosegroup);
+}
+
+//function that lets the user unclose a basketgroup as long as he hasn't submitted the changes to the page.
+function unclosegroup(bgid){
+ var div = document.getElementById('basketgroup-'+bgid+'-closed').parentNode;
+ var divtodel = document.getElementById('unclose-' + bgid);
+ if (divtodel){
+ div.removeChild(divtodel);
+ }
+ divtodel = document.getElementById('unclose-' + bgid);
+ if (divtodel){
+ div.removeChild(divtodel);
+ }
+ var closeinput = document.getElementById('basketgroup-'+bgid+'-closed');
+ var ul = document.getElementById('bg-'+bgid);
+
+ var newclose = document.createElement('a');
+ var newrename = document.createElement('a');
+ var newp = document.createElement('p');
+
+ newclose.innerHTML="close";
+ newclose.href="javascript: closebasketgroup('"+bgid+"', 'bg-"+bgid+"');";
+
+ newrename.href="javascript:" + "renameinit("+bgid+");";
+ newrename.innerHTML="rename";
+
+ var todel = div.getElementsByTagName('p')[0];
+ div.removeChild(todel);
+
+ var changed = document.getElementById("basketgroup-"+bgid+"-changed");
+ changed.value=1;
+
+ newp.innerHTML=" [ ";
+ newp.appendChild(newrename);
+ newp.innerHTML+=" / ";
+ newp.appendChild(newclose);
+ newp.innerHTML+=" ]";
+
+ div.insertBefore(newp, ul);
+ closeinput.value="0";
+ div.className = "workarea";
+ ul.className="draglist";
+
+//rescan draglists, we have a new target (again :-)
+ YAHOO.util.Event.onDOMReady(DDApp.init, DDApp, true);
+}
+
+//a function to filter basketgroups using a regex (javascript regex)
+function filterGroups(event, searchstring ){
+ if (!enterpressed(event) && event != "button"){
+ return false;
+ }
+ var reg = new RegExp(searchstring, "g");
+ var Dom = YAHOO.util.Dom;
+ var divs = Dom.getElementsByClassName("workarea", "div");
+
+ for (var i = 0; i < divs.length; ++i){
+ if (! reg.exec(divs[i].innerHTML)){
+ divs[i].style.display='none';
+ }
+ else {
+ divs[i].style.display='';
+ }
+ }
+ divs = Dom.getElementsByClassName("closed", "div");
+ for (var i = 0; i < divs.length; ++i){
+ if (! reg.exec(divs[i].innerHTML)){
+ divs[i].style.display='none';
+ }
+ else {
+ divs[i].style.display='';
+ }
+ }
+}
+
+//function to hide (or show) closed baskets (if show is true, it shows all the closed baskets)
+function showhideclosegroups(show){
+ var Dom = YAHOO.util.Dom;
+ var divs = Dom.getElementsByClassName("closed", "div");
+ var display;
+ if (show){
+ display = '';
+ }
+ else display = 'none';
+ for(var i = 0; i < divs.length; ++i){
+ divs[i].style.display=display;
+ }
+}
+
+function moveallungroupedto(event, newbgname){
+ if (!enterpressed(event) && event != "button"){
+ return false;
+ }
+ var Dom = YAHOO.util.Dom;
+ var ungrouped = Dom.getElementsByClassName("ungrouped", "li");
+ var unclosed = Dom.getElementsByClassName("workarea", "div");
+ var reg = new RegExp("[-]+", "g");
+
+ for (var i = 0; i < unclosed.length; ++i){
+ if(unclosed[i].getElementsByTagName('h3')[0].innerHTML == newbgname){
+ var ul = unclosed[i].getElementsByTagName('ul')[0];
+ var id = unclosed[i].getElementsByTagName('input')[unclosed[i].getElementsByTagName('input').length-2].name.split(reg)[1];
+ for (var j = 0; j< ungrouped.length; ++j){
+ ungrouped[j].className = "grouped";
+ ungrouped[j].getElementsByTagName('input')[0].value = id;
+ ul.appendChild(ungrouped[j]);
+//FIXME: these should be using getElementById, but i don't know how.
+//this might not be explicit enough, and it's quite complex and hard to read. (above is the basketgroupid of the basket,
+// below is the changed status
+ ungrouped[j].getElementsByTagName('input')[1].value = 1;
+
+ }
+ }
+ }
+}
+
+function renameinit(bgid){
+ var ul = document.getElementById('bg-'+bgid);
+ var div = ul.parentNode;
+ var nameelm = div.getElementsByTagName('h3')[0];
+ var p = div.getElementsByTagName('p')[0];
+
+
+ var nameinput = document.createElement("input");
+ nameinput.type = "text";
+ nameinput.id="rename-"+bgid;
+ nameinput.value = nameelm.innerHTML;
+ nameinput.onkeypress = function(e){rename(e, bgid, document.getElementById('rename-'+bgid).value); };
+// nameinput.setAttribute('onkeypress', 'rename(event, bgid, document.getElementById(rename-'+bgid+').value);');
+
+ div.removeChild(nameelm);
+ div.insertBefore(nameinput, p);
+}
+
+function rename(event, bgid, name){
+ if (!enterpressed(event)){
+ return false;
+ }
+ var ul = document.getElementById('bg-'+bgid);
+ var div = ul.parentNode;
+ var p = div.getElementsByTagName('p')[0];
+ var nameinput = document.getElementById("rename-"+bgid);
+ var changedinput = document.getElementById("basketgroup-"+bgid+"-changed");
+ var newh3 = document.createElement("h3");
+ var hiddenname = document.getElementById("basketgroup-"+bgid+"-name");
+
+ div.removeChild(nameinput);
+
+ newh3.innerHTML=name;
+ hiddenname.value=name;
+ changedinput.value = 1;
+ div.insertBefore(newh3, p);
+}
+
+//=======================================================================
+//a logging function (a bit buggy, might open millions of log pages when initializing, but works fine after...
+function log(message) {
+ if (!log.window_ || log.window_.closed) {
+ var win = window.open("", null, "width=400,height=200," +
+ "scrollbars=yes,resizable=yes,status=no," +
+ "location=no,menubar=no,toolbar=no");
+ if (!win) return;
+ var doc = win.document;
+ doc.write("<html><head><title>Debug Log</title></head>" +
+ "<body></body></html>");
+ doc.close();
+ log.window_ = win;
+ }
+ var logLine = log.window_.document.createElement("div");
+ logLine.appendChild(log.window_.document.createTextNode(message));
+ log.window_.document.body.appendChild(logLine);
+}
+//=======================================================================
+
+
+
+ function ownerPopup(f) {
+ window.open("/cgi-bin/koha/admin/aqbudget_owner_search.pl?op=budget",'PatronPopup','width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
+ }
+ //
+//=======================================================================
+function getElementsByClass( searchClass, domNode, tagName) {
+ if (domNode == null) domNode = document;
+ if (tagName == null) tagName = '*';
+ var el = new Array();
+ var tags = domNode.getElementsByTagName(tagName);
+ var tcl = " "+searchClass+" ";
+ for(i=0,j=0; i<tags.length; i++) {
+ var test = " " + tags[i].className + " ";
+ if (test.indexOf(tcl) != -1)
+ el[j++] = tags[i];
+ }
+ return el;
+}
+
+
+function calcTotalRow(cell) {
+
+ var bud_id = cell.className;
+ var val1 = cell.value;
+ var remainingTotal = document.getElementById("budget_est_"+bud_id) ;
+ var remainingNew =0;
+ var budgetTotal = document.getElementById("budget_tot_"+bud_id ).textContent;
+ var arr = getElementsByClass(bud_id);
+
+ budgetTotal = budgetTotal.replace(/\,/, "");
+
+//percent strip and convert
+ if ( val1.match(/\%/) ) {
+ val1 = val1.replace(/\%/, "");
+ cell.value = (val1 / 100) * Math.abs(budgetTotal ) ;
+ }
+
+ for ( var i=0, len=arr.length; i<len; ++i ){
+ remainingNew += Math.abs(arr[i].value);
+ }
+
+ var cc = new Number(cell.value);
+ cell.value = cc.toFixed(2); // TIDYME...
+ remainingNew = Math.abs( budgetTotal ) - remainingNew ;
+
+ if ( remainingNew == 0) {
+ remainingTotal.style.color = 'black';
+ }
+ else if ( remainingNew > 0 ) {
+ remainingTotal.style.color = 'green';
+ } else { // if its negative, make it red..
+ remainingTotal.style.color = 'red';
+ }
+
+ remainingTotal.textContent = remainingNew.toFixed(2) ;
+}
+
+function autoFillRow(bud_id) {
+
+ var remainingTotal = document.getElementById("budget_est_"+bud_id) ;
+ var remainingNew = new Number;
+ var budgetTotal = document.getElementById("budget_tot_"+bud_id ).textContent;
+ var arr = getElementsByClass(bud_id);
+
+ budgetTotal = budgetTotal.replace(/\,/, "");
+ var qty = new Number;
+// get the totals
+ for ( var i=0, len=arr.length; i<len; ++i ) {
+ remainingNew += Math.abs (arr[i].value );
+
+ if ( arr[i].value == 0 ) {
+ qty += 1;
+ }
+ }
+
+ remainingNew = Math.abs( budgetTotal) - remainingNew ;
+ var newCell = new Number (remainingNew / qty);
+
+ for ( var i=0, len=arr.length; i<len; ++i ) {
+ if ( Math.abs(arr[i].value) == 0 ) {
+ arr[i].value = newCell.toFixed(2) ;
+ }
+ }
+
+ remainingTotal.textContent = '0.00' ;
+ remainingTotal.style.color = 'black';
+}
+
+
+function messenger(X,Y,etc){ // FIXME: unused?
+ win=window.open("","mess","height="+X+",width="+Y+",screenX=150,screenY=0");
+ win.focus();
+ win.document.close();
+ win.document.write("<body link='#333333' bgcolor='#ffffff' text='#000000'><font size='2'><p><br />");
+ win.document.write(etc);
+ win.document.write("<center><form><input type=button onclick='self.close()' value='Close'></form></center>");
+ win.document.write("</font></body></html>");
+}
+
+
+//=======================================================================
+
+// NEXT BLOCK IS USED BY NEWORDERBEMPTY
+
+function calcNeworderTotal(f){
+ //collect values
+ var quantity = new Number(f.quantity.value);
+ var discount = new Number(f.discount.value);
+ var listinc = new Number (f.listinc.value);
+ var currency = f.currency.value;
+ var applygst = new Number (f.applygst.value);
+ var list_price = new Number(f.list_price.value);
+ var invoiceingst = new Number (f.invoiceincgst.value);
+ var exchangerate = new Number(f.elements[currency].value); //get exchange rate
+ var gst_on=(!listinc && invoiceingst);
+
+ //do real stuff
+ var rrp = new Number(list_price*exchangerate);
+ var ecost = new Number(rrp * (100 - discount ) / 100);
+ var GST = new Number(0);
+ if (gst_on) {
+ rrp=rrp * (1+f.gstrate.value / 100);
+ GST=ecost * f.gstrate.value / 100;
+ }
+
+ var total = new Number( (ecost + GST) * quantity);
+
+ f.rrp.value = rrp.toFixed(2);
+
+// f.rrp.value = rrp
+// f.rrp.value = 'moo'
+
+ f.ecost.value = ecost.toFixed(2);
+ f.total.value = total.toFixed(2);
+ f.list_price.value = list_price.toFixed(2);
+
+// gst-stuff needs verifing, mason.
+ if (f.GST) {
+ f.GST.value=GST;
+ }
+ return true;
+}
+
+// ----------------------------------------
+//USED BY NEWORDEREMPTY.PL
+/*
+function fetchSortDropbox(f) {
+ var budgetId=f.budget_id.value;
+ var handleSuccess = function(o){
+ if(o.responseText !== undefined){
+ sort_dropbox.innerHTML = o.responseText;
+ }
+ }
+
+ var callback = { success:handleSuccess };
+ var sUrl = '../acqui/fetch_sort_dropbox.pl?sort=1&budget_id='+budgetId
+ var sort_dropbox = document.getElementById('sort1');
+ var request1 = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
+ var rr = '00';
+
+// FIXME: --------- twice , coz the 2 requests get mixed up otherwise
+
+ var handleSuccess2 = function(o){
+ if(o.responseText !== undefined){
+ sort2_dropbox.innerHTML = o.responseText;
+ }
+ }
+
+ var callback2 = { success:handleSuccess };
+ var sUrl2 = '../acqui/fetch_sort_dropbox.pl?sort=2&budget_id='+budgetId;
+ var sort2_dropbox = document.getElementById('sort2');
+ var request2 = YAHOO.util.Connect.asyncRequest('GET', sUrl2, callback2);
+
+}
+*/
+
+
+
+//USED BY NEWORDEREMPTY.PL
+function fetchSortDropbox(f) {
+ var budgetId=f.budget_id.value;
+
+ for (i=1;i<=2;i++) {
+
+ var sort_dropbox = document.getElementById('sort'+i);
+ var url = '../acqui/fetch_sort_dropbox.pl?sort='+i+'&budget_id='+budgetId;
+
+ var xmlhttp = null;
+ xmlhttp = new XMLHttpRequest();
+ if ( typeof xmlhttp.overrideMimeType != 'undefined') {
+ xmlhttp.overrideMimeType('text/xml');
+ }
+
+ xmlhttp.open('GET', url, false);
+ xmlhttp.send(null);
+
+ xmlhttp.onreadystatechange = function() {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ // stupid JS...
+ } else {
+ // wait for the call to complete
+ }
+ };
+ // rc = eval ( xmlhttp.responseText );
+ sort_dropbox.innerHTML = xmlhttp.responseText;
+ }
+}
+
+
+
+
+
+
+
+//USED BY NEWORDEREMPTY.PL
+function totalExceedsBudget(budgetId, total) {
+
+ var xmlhttp = null;
+ xmlhttp = new XMLHttpRequest();
+ if ( typeof xmlhttp.overrideMimeType != 'undefined') {
+ xmlhttp.overrideMimeType('text/xml');
+ }
+
+ var url = '../acqui/check_budget_total.pl?budget_id=' + budgetId + "&total=" + total;
+ xmlhttp.open('GET', url, false);
+ xmlhttp.send(null);
+
+ xmlhttp.onreadystatechange = function() {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+
+ actTotal = eval ( xmlhttp.responseText );
+
+ if ( Math.abs(actTotal) < Math.abs(total) ) {
+ // if budget is to low :(
+ return true ;
+ } else {
+ return false;
+ }
+ }
+ }
+}
+
+
+//USED BY AQBUDGETS.TMPL
+function budgetExceedsParent(budgetTotal, budgetId, newBudgetParent, periodID) {
+
+
+ var xmlhttp = null;
+ xmlhttp = new XMLHttpRequest();
+ if ( typeof xmlhttp.overrideMimeType != 'undefined') {
+ xmlhttp.overrideMimeType('text/xml');
+ }
+
+// make the call... yawn
+// var url = '../admin/check_parent_total.pl?budget_id=' + budgetId + '&parent_id=' + newBudgetParent + "&total=" + budgetTotal + "&period_id="+ periodID ;
+
+
+ var url = '../admin/check_parent_total.pl?total=' + budgetTotal + "&period_id="+ periodID ;
+
+if (budgetId ) { url += '&budget_id=' + budgetId };
+if ( newBudgetParent ) { url += '&parent_id=' + newBudgetParent};
+
+
+ xmlhttp.open('GET', url, false);
+ xmlhttp.send(null);
+
+ xmlhttp.onreadystatechange = function() {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ // stupid JS...
+ } else {
+ // wait for the call to complete
+ }
+ };
+
+ var result = eval ( xmlhttp.responseText );
+
+ if (result == '1') {
+ return _("- Budget total exceeds parent allocation\n");
+ } else if (result == '2') {
+ return _("- Budget total exceeds period allocation\n");
+ } else {
+ return false;
+ }
+}
+
+
+
+
+//USED BY AQBUDGETS.TMPL
+function checkBudgetParent(budgetId, newBudgetParent) {
+ var xmlhttp = null;
+ xmlhttp = new XMLHttpRequest();
+ if ( typeof xmlhttp.overrideMimeType != 'undefined') {
+ xmlhttp.overrideMimeType('text/xml');
+ }
+
+ var url = '../admin/check_budget_parent.pl?budget_id=' + budgetId + '&new_parent=' + newBudgetParent;
+ xmlhttp.open('GET', url, false);
+ xmlhttp.send(null);
+
+ xmlhttp.onreadystatechange = function() {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ // do something with the results
+ } else {
+ // wait for the call to complete
+ }
+ };
+
+ var result = eval ( xmlhttp.responseText );
+
+ if (result == '1') {
+ return _("- New budget-parent is beneath budget\n");
+// } else if (result == '2') {
+// return "- New budget-parent has insufficent funds\n";
+// } else {
+// return false;
+ }
+}
+
--
1.6.0.4
More information about the Koha-patches
mailing list