-
Notifications
You must be signed in to change notification settings - Fork 90
/
ssctrltest1.html
351 lines (303 loc) · 13.3 KB
/
ssctrltest1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SS Ctrl Test 1</title>
<script type="text/javascript" src="socialcalcconstants.js"></script>
<script type="text/javascript" src="socialcalc-3.js"></script>
<script type="text/javascript" src="socialcalctableeditor.js"></script>
<script type="text/javascript" src="formatnumber2.js"></script>
<script type="text/javascript" src="formula1.js"></script>
<script type="text/javascript" src="socialcalcpopup.js"></script>
<script type="text/javascript" src="socialcalcspreadsheetcontrol.js"></script>
<link rel="stylesheet" type="text/css" href="socialcalc.css">
<style>
body
{font-family:verdana,helvetica,sans-serif;font-size:small;}
.testclass {border:2px dotted red;}
.testclass2 {background-image:url(images/sc-logo.gif);}
.smaller {font-size:smaller;}
.hide {display:none;}
</style>
</head>
<body onresize="doresize();">
<form name="f0" action="" method="POST">
<div style="padding:6px;background-color:#80A9F3;">
<span style="font-weight:bold;color:white;">ssctrltest1.html</span>
<input type="button" name="savespreadsheet" value="Save" onclick="dosave();" class="smaller">
<input type="submit" name="newcolors" value="New Colors" onclick="document.f0.action='?4C808';" class="smaller">
<input class="hide" type="button" value="Recalc" onclick="spreadsheet.ExecuteCommand('recalc', '');" class="smaller">
<input class="hide" type="button" value="Redisplay" onclick="spreadsheet.editor.ScheduleRender();" class="smaller">
<input class="hide" type="button" value="Settings" onclick="alert(sv=spreadsheet.editor.SaveEditorSettings());" class="smaller">
<input type="button" value="Reload" onclick="doreload();" class="smaller">
<input class="hide" type="button" value="CellHTMLSave" onclick="alert(spreadsheet.CreateCellHTMLSave(null));" class="smaller">
<input class="hide" type="button" value="CellHTML A1" onclick="alert(spreadsheet.CreateCellHTML('A1'));" class="smaller">
<input class="hide" type="button" value="SheetHTML" onclick="alert(spreadsheet.CreateSheetHTML());" class="smaller">
<input class="hide" type="button" value="SheetSave" onclick="alert(spreadsheet.CreateSheetSave());" class="smaller">
<input class="hide" type="button" value="Attribs" onclick="doattribs();" class="smaller">
<input class="hide" type="button" value="New Copy" onclick="newcopy();" class="smaller">
<input class="hide" type="button" value="Sum" onclick="dosum();" class="smaller">
<input class="hide" type="button" value="Sum2" onclick="dosum2();" class="smaller">
<input type="button" value="Loc Constants" onclick="doLocConstants();" class="smaller">
<input type="button" value="Canonicalize" onclick="var t=new Date();var i;for(i=0;i<1;i++){spreadsheet.sheet.CanonicalizeSheet(true);}addmsg(((new Date()-t)/1000));" class="smaller">
<input type="button" value="Canonical Save" onclick="alert(spreadsheet.sheet.CreateSheetSave(null,true));" class="smaller">
<input type="button" value="Time Canonicalize" onclick="var t=new Date();var i;for(i=0;i<100;i++){spreadsheet.sheet.CanonicalizeSheet(true);}addmsg(((new Date()-t)/1000));" class="smaller">
<input type="button" value="Time Save" onclick="var t=new Date();var i;for(i=0;i<100;i++){spreadsheet.CreateSpreadsheetSave();}addmsg(((new Date()-t)/1000));" class="smaller">
<input type="button" value="Time C-Save" onclick="var t=new Date();var i;for(i=0;i<100;i++){spreadsheet.sheet.CreateSheetSave(null,true);}addmsg(((new Date()-t)/1000));" class="smaller">
<input type="button" value="Time Encode" onclick="var t=new Date();var i;for(i=0;i<100;i++){spreadsheet.sheet.EncodeCellAttributes(spreadsheet.editor.ecell.coord);}addmsg(((new Date()-t)/1000));" class="smaller">
<textarea id="savestr" style="display:none;"></textarea>
<input type="hidden" name="newstr" id="newdata" value="">
<input type="hidden" name="pagename" value="$pagename">
<input type="hidden" name="sheetname" value="$sheetname">
</div>
</form>
<div id="msg" style="position:absolute;right:15px;">
<input type="button" style="font-size:x-small;" value="Clear" onclick="addmsg('',true);"><br>
<textarea id="msgtext" style="margin-top:10px;width:110px;height:200px;"></textarea><br>
</div>
<div id="tableeditor" style="margin:8px 140px 10px 0px;">editor goes here</div>
<script>
document.getElementById("msgtext").value = "";
function setmsg(msg) {document.getElementById("msg").innerHTML = msg;}
function addmsg(msg, clear) {
var msgtextid = document.getElementById("msgtext");
if (!msgtextid) {
document.getElementById("msg").innerHTML = '<textarea id="msgtext" cols="60" rows="5"></textarea>';
msgtextid = document.getElementById("msgtext");
}
if (clear) msgtextid.value = "";
if (msgtextid.value.length>0) msgtextid.value += "\n";
msgtextid.value += msg;
}
//
// Setup code starts here:
//
// SocialCalc.ConstantsSetClasses("");
var scc = SocialCalc.Constants;
var b1 = window.location.search.charAt(1) || "4";
var b2 = window.location.search.charAt(2) || "C";
var b3 = window.location.search.charAt(3) || "8";
var b4 = window.location.search.charAt(4) || "9";
var b5 = window.location.search.charAt(5) || "8";
scc.SCToolbarbackground = "background-color:#4040"+b1+"0;";
scc.SCTabbackground = "background-color:#CC"+b2+";";
scc.SCTabselectedCSS = "font-size:small;padding:6px 30px 6px 8px;color:#FFF;background-color:#4040"+b1+"0;cursor:default;border-right:1px solid #CC"+b2+";";
scc.SCTabplainCSS = "font-size:small;padding:6px 30px 6px 8px;color:#FFF;background-color:#8080"+b3+"0;cursor:default;border-right:1px solid #CC"+b2+";";
scc.SCToolbartext = "font-size:x-small;font-weight:bold;color:#FFF;padding-bottom:4px;";
scc.ISCButtonBorderNormal = "#4040"+b1+"0";
scc.ISCButtonBorderHover = "#99"+b4+"";
scc.ISCButtonBorderDown = "#FFF";
scc.ISCButtonDownBackground = "#88"+b5+"";
SocialCalc.Popup.LocalizeString = SocialCalc.LocalizeString; // needed for localization
var spreadsheet = new SocialCalc.SpreadsheetControl();
var savestr = document.getElementById("savestr");
spreadsheet.InitializeSpreadsheetControl("tableeditor", 0, 0, 0);
spreadsheet.ExecuteCommand('redisplay', '');
spreadsheet.ExportCallback = function(s) {
alert(SocialCalc.ConvertSaveToOtherFormat(SocialCalc.Clipboard.clipboard, "csv"));
}
// Dummy loadsheet for testing:
SocialCalc.Formula.SheetCache.LoadSheet = function(sheetname) {
var sfscc = SocialCalc.Formula.SheetCache.constants;
var doload = confirm("Loadsheet: "+sheetname+"?");
if (true) {
return {status: doload?sfscc.ok:sfscc.loading, str: "cell:A1:v:4\ncell:A2:t:Sheet\\c "+sheetname+"\ncell:A3:vtf:ndt:0:NOW()\ncell:B1:v:5\ncell:B2:v:6\nname:AONE::A1\nname:ATWO::A2\nname:RANGE::B1\\cB2\nname:TEST::A3",
recalc: true};
}
return null;
}
// ExpandWiki code for testing
SocialCalc.Callbacks.expand_wiki = function(displayvalue, sheetobj, linkstyle, valueformat) {
var subtype = valueformat.substring(9); // stuff after text-wiki
var result = "";
switch (subtype) {
case "":
result = SocialCalc.default_expand_markup(displayvalue, sheetobj, linkstyle);
break;
case "-link":
result = "link to: "+SocialCalc.special_chars(displayvalue);
break;
default:
result = SocialCalc.special_chars(valueformat+": "+displayvalue);
break;
}
return result || " ";
}
function dosave() {
savestr.value = spreadsheet.CreateSpreadsheetSave();
alert(savestr.value);
}
function doreload() {
var parts = spreadsheet.DecodeSpreadsheetSave(savestr.value);
if (parts) {
if (parts.sheet) {
spreadsheet.sheet.ResetSheet();
spreadsheet.ParseSheetSave(savestr.value.substring(parts.sheet.start, parts.sheet.end));
}
if (parts.edit) {
spreadsheet.editor.LoadEditorSettings(savestr.value.substring(parts.edit.start, parts.edit.end));
}
}
if (spreadsheet.editor.context.sheetobj.attribs.recalc=="off") {
spreadsheet.ExecuteCommand('redisplay', '');
}
else {
spreadsheet.ExecuteCommand('recalc', '');
}
}
function doresize() {
spreadsheet.DoOnResize();
}
function doattribs() {
var attribs = spreadsheet.sheet.EncodeCellAttributes(spreadsheet.editor.ecell.coord);
var str = "";
for (var attrib in attribs) {
str += attrib + ":" + " def="+attribs[attrib].def+", val='"+attribs[attrib].val+"'\n";
}
str+="=====\n";
attribs = spreadsheet.sheet.EncodeSheetAttributes();
for (var attrib in attribs) {
str += attrib + ":" + " def="+attribs[attrib].def+", val='"+attribs[attrib].val+"'\n";
}
alert(str);
}
var fromrange = "A1:A1";
function newcopy() {
var ta, cell, position, sel, parseobj;
var spreadsheet = SocialCalc.GetSpreadsheetControlObject();
var editor = spreadsheet.editor;
ta = editor.pasteTextarea;
ta.value = "";
cell=SocialCalc.GetEditorCellElement(editor, editor.ecell.row, editor.ecell.col);
if (cell) {
position = SocialCalc.GetElementPosition(cell.element);
ta.style.left = (position.left-1)+"px";
ta.style.top = (position.top-1)+"px";
}
if (editor.range.hasrange) {
sel = SocialCalc.crToCoord(editor.range.left, editor.range.top)+
":"+SocialCalc.crToCoord(editor.range.right, editor.range.bottom);
}
else {
sel = editor.ecell.coord;
}
parseobj = new SocialCalc.Parse("copy "+sel+" all");
SocialCalc.ExecuteSheetCommand(editor.context.sheetobj, parseobj, true); // note: not queued!!!??!!
SocialCalc.Clipboard.clipboard.loadedByCtrlC = true; // remember this clipboard data was from ctrl-c
ta.value = SocialCalc.ConvertSaveToOtherFormat(SocialCalc.Clipboard.clipboard, "tab");
ta.style.display = "block";
ta.focus();
ta.select();
// var range = document.selection.createRange();
var range = window.getSelection().getRangeAt(0);
range.execCommand("copy");
window.setTimeout(function() {
var s = SocialCalc.GetSpreadsheetControlObject();
var editor = s.editor;
var ta = editor.pasteTextarea;
ta.style.display = "none";
}, 200);
return;
}
function dosum() {
var cmd, cell, row, col, sel, cr, foundvalue;
var spreadsheet = SocialCalc.GetSpreadsheetControlObject();
var editor = spreadsheet.editor;
var sheet = editor.context.sheetobj;
if (editor.range.hasrange) {
sel = SocialCalc.crToCoord(editor.range.left, editor.range.top)+
":"+SocialCalc.crToCoord(editor.range.right, editor.range.bottom);
cmd = "set "+SocialCalc.crToCoord(editor.range.right, editor.range.bottom+1)+
" formula sum("+sel+")";
}
else {
row = editor.ecell.row - 1;
col = editor.ecell.col;
if (row<=1) {
cmd = "set "+editor.ecell.coord+" constant e#REF! 0 #REF!";
}
else {
foundvalue = false;
while (row>0) {
cr = SocialCalc.crToCoord(col, row);
cell = sheet.GetAssuredCell(cr);
if (!cell.datatype || cell.datatype=="t") {
if (foundvalue) {
row++;
break;
}
}
else {
foundvalue = true;
}
row--;
}
cmd = "set "+editor.ecell.coord+" formula sum("+
SocialCalc.crToCoord(col,row)+":"+SocialCalc.crToCoord(col, editor.ecell.row-1)+")";
}
}
editor.EditorScheduleSheetCommands(cmd);
}
function dosum2() {
var cmd, cell, row, col, sel, cr, foundvalue;
var spreadsheet = SocialCalc.GetSpreadsheetControlObject();
var editor = spreadsheet.editor;
var sheet = editor.context.sheetobj;
if (editor.range.hasrange) {
sel = SocialCalc.crToCoord(editor.range.left, editor.range.top)+
":"+SocialCalc.crToCoord(editor.range.right, editor.range.bottom);
cmd = "sum("+sel+")";
}
else {
row = editor.ecell.row - 1;
col = editor.ecell.col;
if (row<=1) {
cmd = "sum()";
}
else {
foundvalue = false;
while (row>0) {
cr = SocialCalc.crToCoord(col, row);
cell = sheet.GetAssuredCell(cr);
if (!cell.datatype || cell.datatype=="t") {
if (foundvalue) {
row++;
break;
}
}
else {
foundvalue = true;
}
row--;
}
cmd = "sum("+
SocialCalc.crToCoord(col,row)+":"+SocialCalc.crToCoord(col, editor.ecell.row-1)+")";
}
}
editor.EditorAddToInput(cmd, "=");
}
function doLocConstants() {
var str = "";
var cname, i, ctname, cval;
var cnames = [];
for (cname in SocialCalc.LocalizeStringList) {
cnames.push(cname);
}
cnames.sort();
for (i=0; i<cnames.length; i++) {
cname = cnames[i];
ctname = "s_loc_"+cname.toLowerCase().replace(/\s/g, "_").replace(/\W/g, "X");
cval = SocialCalc.Constants[ctname];
// str += ctname + ": ";
// str += '"' + SocialCalc.LocalizeStringList[cname] + '",\n';
if (!cval) {
str += ctname + ': "' + cname + '",\n';
}
}
if (!str) str = "All constants were pre-defined.";
addmsg(str);
alert(str);
}
</script>
</body>
</html>