1 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=javascript: */
3 * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 const nsCI = Components.interfaces;
23 const treeViewContract = "@aasii.org/view/tree-transcript;1";
24 const reportContract = "@aasii.org/report/transcript;1";
32 Components.classes['@mozilla.org/consoleservice;1']
33 .getService(Components.interfaces.nsIConsoleService)
34 .logStringMessage(str);
40 for (var prop in obj) {
42 dump(prop + ": " + obj[prop] + "\n");
44 dump(prop + ": error: " + e.message + "\n");
51 return document.defaultView.QueryInterface(nsCI.nsIInterfaceRequestor)
52 .getInterface(nsCI.nsIWebNavigation).sessionHistory;
57 document.defaultView.QueryInterface(nsCI.nsIInterfaceRequestor)
58 .getInterface(nsCI.nsIWebNavigation)
59 .loadURI(uri,nsCI.nsIWebNavigation.LOAD_FLAGS_NONE,null,null,null);
68 QueryInterface : function aaViewQI(iid)
70 if (iid.equals(nsCI.nsIObserver) ||
71 iid.equals(nsCI.nsISupportsWeakReference) ||
72 iid.equals(nsCI.nsISupports))
75 throw Components.results.NS_ERROR_NO_INTERFACE;
78 observe: function aaViewObserve(aSubject, aTopic, aData)
80 if (aSubject == gTree.view) {
81 if (aTopic == "tree-flags-change")
87 function transcriptPageLoad()
89 document.getElementById("filter.dateFrom").addEventListener("change", dateFromChange, false);
90 document.getElementById("header.dateFrom").value = document.
91 getElementById("filter.dateFrom").value;
92 document.getElementById("header.dateTo").value = document.
93 getElementById("filter.dateTo").value;
94 gTree = document.getElementById("transcript.tree");
95 gTree.view = Components.classes[treeViewContract]
96 .createInstance(nsCI.nsITreeView);
97 gReport = session().createQuery(reportContract).
98 QueryInterface(nsCI.aaITranscript);
99 gTree.view.QueryInterface(nsCI.aaIDataTreeView).dataSet = gReport;
102 addEventListener("resize", transcriptResize, true);
104 gView = new aaView();
105 var broadcaster = Components.classes["@mozilla.org/observer-service;1"].
106 getService(nsCI.nsIObserverService);
107 broadcaster.addObserver(gView, "tree-flags-change", true);
110 function transcriptResize()
115 function alignLabels()
117 var width = gTree.columns[3].width;
118 document.getElementById("header.sumCreditFrom").setAttribute('width',width);
119 document.getElementById("header.sumCreditTo").setAttribute('width',width);
124 if (document.getElementById("viewMode").hasAttribute("disabled")) {
125 session().beginQuery();
126 addEventListener("pageshow", choosenFlow, true);
128 loadURI("chrome://abstract/content/flow.xul");
131 function choosenFlow()
133 removeEventListener("pageshow", choosenFlow, true);
134 var buffer = session().queryBuffer;
135 gReport.flow = buffer
136 ? buffer.QueryInterface(nsCI.aaIFlow) : null;
138 updateFlowLink("filter");
141 function dateFromChange(event)
145 function dateToChange(event)
149 function transcriptLoad()
151 gReport.start = (document.getElementById("filter.dateFrom").dateValue
152 .getTime() - 1000 * 60 * 60 * 24) * 1000;
153 gReport.end = document.getElementById("filter.dateTo").dateValue
156 gTree.view.QueryInterface(nsCI.aaIDataTreeView).update();
157 updateFlowLink("header");
159 var startDate = new Date();
160 var endDate = new Date();
161 startDate.setTime(gReport.start/1000 + 1000 * 60 * 60 * 24);
162 endDate.setTime(gReport.end/1000);
164 document.getElementById("filter.dateFrom").dateValue = startDate;
165 document.getElementById("header.dateFrom").value =
166 startDate.toLocaleFormat('%Y-%m-%d');
167 document.getElementById("filter.dateTo").dateValue = endDate;
168 document.getElementById("header.dateTo").value =
169 endDate.toLocaleFormat('%Y-%m-%d');
176 function updateBalances()
178 var sumDebitFrom, sumCreditFrom, sumDebitTo, sumCreditTo;
179 if (gTree && gTree.view && gTree.view.flags) {
180 sumDebitFrom = gReport.opening &&
181 gReport.opening.side ? gReport.opening.value.toFixed(2) : "0.00" ;
182 sumCreditFrom = gReport.opening &&
183 ! gReport.opening.side ? gReport.opening.value.toFixed(2) : "0.00" ;
184 sumDebitTo = gReport.closing &&
185 gReport.closing.side ? gReport.closing.value.toFixed(2) : "0.00";
186 sumCreditTo = gReport.closing &&
187 ! gReport.closing.side ? gReport.closing.value.toFixed(2) : "0.00";
189 sumDebitFrom = gReport.opening &&
190 gReport.opening.side ? gReport.opening.amount.toFixed(2) : "0.00" ;
191 sumCreditFrom = gReport.opening &&
192 ! gReport.opening.side ? gReport.opening.amount.toFixed(2) : "0.00" ;
193 sumDebitTo = gReport.closing &&
194 gReport.closing.side ? gReport.closing.amount.toFixed(2) : "0.00";
195 sumCreditTo = gReport.closing &&
196 ! gReport.closing.side ? gReport.closing.amount.toFixed(2) : "0.00";
199 document.getElementById("header.sumDebitFrom").value = sumDebitFrom;
200 document.getElementById("header.sumCreditFrom").value = sumCreditFrom;
201 document.getElementById("header.sumDebitTo").value = sumDebitTo;
202 document.getElementById("header.sumCreditTo").value = sumCreditTo;
206 function updateFlowLink(part)
208 if (gReport && gReport.flow)
209 document.getElementById(part + ".flow").value = gReport.flow.tag;
211 document.getElementById(part + ".flow").value = document.
212 getElementById("bundle_abstract").getString("link.choose");
215 function setMode(isChange)
217 var newMode, oldMode;
220 newMode = document.getElementById("changeMode");
221 oldMode = document.getElementById("viewMode");
223 updateFlowLink("filter");
225 newMode = document.getElementById("viewMode");
226 oldMode = document.getElementById("changeMode");
229 oldMode.setAttribute("disabled","true");
230 oldMode.setAttribute("collapsed","true");
232 newMode.removeAttribute("disabled");
233 newMode.removeAttribute("collapsed");
236 function filterChange()
241 function filterReset()
246 function unitSwitch()
248 if (gTree && gTree.view)
249 gTree.view.QueryInterface(nsCI.aaIDataTreeView).flags =
250 document.getElementById("units.mode").selectedIndex;
255 if (document.getElementById("changeMode").hasAttribute("disabled")) {
264 document.getElementById("units.mode").selectedIndex = (document
265 .getElementById("units.mode").selectedIndex) ? 0 : 1;