123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- /*
- * Copyright Scand LLC http://www.scbr.com To use this component please contact
- * info@scbr.com to obtain license
- */
- document.write("<link rel='stylesheet' type='text/css' href='" + _css_prefix
- + "dhtmlXGrid_calck.css'></link>");
- // simple text editor
- function eXcell_calck(cell) {
- try {
- this.cell = cell;
- this.grid = this.cell.parentNode.grid;
- } catch (er) {
- }
- this.edit = function() {
- this.val = this.getValue();
- var arPos = this.grid.getPosition(this.cell);
- this.obj = new calcX(arPos[0] - this.grid.objBox.scrollLeft, arPos[1]
- + this.cell.offsetHeight - this.grid.objBox.scrollTop,
- this, this.val);
- }
- this.getValue = function() {
- // this.grid.editStop();
- return this.grid._aplNFb(this.cell.innerHTML.toString()._dhx_trim(),
- this.cell._cellIndex);
- }
- this.detach = function(x, val) {
- if (x)
- this.setValue(val);
- else if (this.obj)
- this.obj.removeSelf();
- this.obj = null;
- return this.val != this.getValue();
- }
- }
- eXcell_calck.prototype = new eXcell;
- eXcell_calck.prototype.setValue = function(val) {
- if (!val || val.toString()._dhx_trim() == "")
- val = "0"
- this.cell.innerHTML = this.grid._aplNF(val, this.cell._cellIndex);
- }
- function calcX(left, top, onReturnSub, val) {
- this.top = top || 0;
- this.left = left || 0;
- this.onReturnSub = onReturnSub || null;
- this.operandA = 0;
- this.operandB = 0;
- this.operatorA = "";
- this.state = 0;
- this.dotState = 0;
- this.calckGo = function() {
- return (eval(this.operandA + "*1" + this.operatorA + this.operandB
- + "*1"));
- };
- this.isNumeric = function(str) {
- return ((str.search(/[^1234567890]/gi) == -1) ? (true) : (false));
- };
- this.isOperation = function(str) {
- return ((str.search(/[^\+\*\-\/]/gi) == -1) ? (true) : (false));
- }
- this.onCalcKey = function() {
- that = this.calk;
- var z = this.innerHTML;
- var rZone = that.inputZone;
- if (((that.state == 0) || (that.state == 2)) && (that.isNumeric(z)))
- if (rZone.value != "0")
- rZone.value += z;
- else
- rZone.value = z;
- if ((((that.state == 0) || (that.state == 2)) && (z == '.'))
- && (that.dotState == 0)) {
- that.dotState = 1;
- rZone.value += z;
- }
- if ((z == "C")) {
- rZone.value = 0;
- that.dotState = 0;
- that.state = 0;
- }
- if ((that.state == 0) && (that.isOperation(z))) {
- that.operatorA = z;
- that.operandA = rZone.value;
- that.state = 1;
- }
- if ((that.state == 2) && (that.isOperation(z))) {
- that.operandB = rZone.value;
- rZone.value = that.calckGo();
- that.operatorA = z;
- that.operandA = rZone.value;
- that.state = 1;
- }
- if ((that.state == 2) && (z == "=")) {
- that.operandB = rZone.value;
- rZone.value = that.calckGo();
- that.operatorA = z;
- that.operandA = rZone.value;
- that.state = 3;
- }
- if ((that.state == 1) && (that.isNumeric(z))) {
- rZone.value = z;
- that.state = 2;
- that.dotState = 0
- }
- if ((that.state == 3) && (that.isNumeric(z))) {
- rZone.value = z;
- that.state = 0;
- }
- if ((that.state == 3) && (that.isOperation(z))) {
- that.operatorA = z;
- that.operandA = rZone.value;
- that.state = 1;
- }
- if (z == "e") {
- rZone.value = Math.E;
- if (that.state == 1)
- that.state = 2;
- that.dotState = 0
- }
- if (z == "p") {
- rZone.value = Math.PI;
- if (that.state == 1)
- that.state = 2;
- that.dotState = 0
- }
- if (z == "Off")
- that.topNod.removeNode(true);
- }
- this.sendResult = function() {
- that = this.calk;
- if (that.state == 2) {
- var rZone = that.inputZone;
- that.operandB = rZone.value;
- rZone.value = that.calckGo();
- that.operatorA = z;
- that.operandA = rZone.value;
- that.state = 3;
- }
- var z = that.inputZone.value;
- that.topNod.parentNode.removeChild(that.topNod);
- that.onReturnSub.detach(1, z);
- };
- this.removeSelf = function() {
- if (this.topNod.parentNode)
- this.topNod.parentNode.removeChild(this.topNod);
- }
- this.keyDown = function() {
- this.className = "calcPressed";
- };
- this.keyUp = function() {
- this.className = "calcButton";
- };
- this.init_table = function() {
- var table = this.topNod.childNodes[0];
- if ((!table) || (table.tagName != "TABLE"))
- return;
- for (i = 1; i < table.childNodes[0].childNodes.length; i++)
- for (j = 0; j < table.childNodes[0].childNodes[i].childNodes.length; j++) {
- table.childNodes[0].childNodes[i].childNodes[j].onclick = this.onCalcKey;
- table.childNodes[0].childNodes[i].childNodes[j].onmousedown = this.keyDown;
- table.childNodes[0].childNodes[i].childNodes[j].onmouseout = this.keyUp;
- table.childNodes[0].childNodes[i].childNodes[j].onmouseup = this.keyUp;
- table.childNodes[0].childNodes[i].childNodes[j].calk = this;
- }
- this.inputZone = this.topNod.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
- if (this.onReturnSub) {
- this.topNod.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].onclick = this.sendResult;
- this.topNod.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].calk = this;
- } else
- this.topNod.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].innerHTML = "";
- }
- this.drawSelf = function() {
- var div = document.createElement("div");
- div.className = "calcTable";
- div.style.position = "absolute";
- div.style.top = this.top + "px";
- div.style.left = this.left + "px";
- div.innerHTML = "<table cellspacing='0' id='calc_01' class='calcTable'><tr><td colspan='4'><table cellpadding='1' cellspacing='0' width='100%'><tr><td width='100%'><input style='width:100%' class='calcInput' value='0' align='right' readonly='true' style='text-align:right'></td><td class='calkSubmit'>=</td></tr></table></td></tr><tr><td class='calcButton' width='25%'>Off</td><td class='calcButton' width='25%'>p</td><td class='calcButton' width='25%'>e</td><td class='calcButton' width='25%'>/</td></tr><tr><td class='calcButton'>7</td><td class='calcButton'>8</td><td class='calcButton'>9</td><td class='calcButton'>*</td></tr><tr><td class='calcButton'>4</td><td class='calcButton'>5</td><td class='calcButton'>6</td><td class='calcButton'>+</td></tr><tr><td class='calcButton'>1</td><td class='calcButton'>2</td><td class='calcButton'>3</td><td class='calcButton'>-</td></tr><tr><td class='calcButton'>0</td><td class='calcButton'>.</td><td class='calcButton'>C</td><td class='calcButton'>=</td></tr></table>";
- document.body.appendChild(div);
- this.topNod = div;
- }
- this.drawSelf();
- this.init_table();
- if (val) {
- var rZone = this.inputZone;
- rZone.value = val * 1;
- this.operandA = val * 1;
- this.state = 1;
- }
- return this;
- };
|