-
Notifications
You must be signed in to change notification settings - Fork 6
/
files.js
132 lines (122 loc) · 4.18 KB
/
files.js
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
/*
FILE NAME : files.js
DESCRIPTION: optical design
REVISION: 1.00
AUTHOR: Oleg Dzhimiev <oleg@elphel.com>
LICENSE: AGPL, see http://www.gnu.org/licenses/agpl.txt
Copyright (C) 2014 Elphel, Inc.
*/
var path_local = "local";
var path_remote = "https://raw.githubusercontent.com/Elphel/elens/master";
var path_remote_browse = "https://github.com/Elphel/elens";
var pattern_local = "local: ";
var pattern_remote = "github: ";
function save_design(){
console.log("save_design(): "+$("#file_to_save").val());
var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Document>\n";
$(".elements").each(function(i){
//console.log($(this).find("#distance").val()+" ")
xml += "\t<element>\n";
xml += "\t\t<distance>"+e[i].d+"</distance>\n";
xml += "\t\t<thickness>"+e[i].t+"</thickness>\n";
xml += "\t\t<material>"+e[i].m+"</material>\n";
xml += "\t\t<name>"+e[i].name+"</name>\n";
xml += "\t\t<front>\n";
xml += "\t\t\t<height>"+e[i].front.h+"</height>\n";
xml += "\t\t\t<rcurve>"+e[i].front.c+"</rcurve>\n";
xml += "\t\t\t<k>"+e[i].front.k+"</k>\n";
xml += "\t\t\t<a1>"+e[i].front.a[0]+"</a1>\n";
xml += "\t\t\t<a2>"+e[i].front.a[1]+"</a2>\n";
xml += "\t\t\t<a3>"+e[i].front.a[2]+"</a3>\n";
xml += "\t\t\t<a4>"+e[i].front.a[3]+"</a4>\n";
xml += "\t\t</front>\n";
xml += "\t\t<back>\n";
xml += "\t\t\t<height>"+e[i].back.h+"</height>\n";
xml += "\t\t\t<rcurve>"+e[i].back.c+"</rcurve>\n";
xml += "\t\t\t<k>"+e[i].back.k+"</k>\n";
xml += "\t\t\t<a1>"+e[i].back.a[0]+"</a1>\n";
xml += "\t\t\t<a2>"+e[i].back.a[1]+"</a2>\n";
xml += "\t\t\t<a3>"+e[i].back.a[2]+"</a3>\n";
xml += "\t\t\t<a4>"+e[i].back.a[3]+"</a4>\n";
xml += "\t\t</back>\n";
xml += "\t</element>\n";
});
xml += "</Document>";
postSettings($("#file_to_save").val(), "save", xml);
}
function postSettings(file, cmd, xml) {
$.ajax({
url: "files.php?file="+file+"&cmd="+cmd+"&path="+path_local,
type: "POST",
dataType: "xml",
data: xml,
async:false,
complete: function(response){parse_save_response(response.responseText);},
contentType: "text/xml; charset=\"utf-8\""
});
}
function parse_save_response(text) {
//$("#test").html(text);
//reload list
designs = Array();
get_designs_list("load_designs_list");
jquery_list("load_designs_list","Load",load_design);
}
function getDesign(f,p) {
//set globals
createLink(f,p);
$.ajax({
url: "files.php?file="+f+"&cmd=read&path="+p,
type: "GET",
async: false,
complete: function(response){
restore_design(response.responseXML);
},
contentType: "text/xml; charset=\"utf-8\""
});
}
function restore_design(text){
console.log("restore_design()");
//erase old
$(".elements").each(function(){
console.log("removing "+$(this).attr("value"));
array_remove_element($(this).attr("value"));
// $("#element_"+i).remove();
// $("#cnv1").removeLayer("element_"+i).drawLayers();
});
selected_elements = Array();
//draw new
var data = $(text).find("Document");
data.find("element").each(function(){
array_add_element(
$(this).find("distance").text(),
$(this).find("thickness").text(),
$(this).find("material").text(),
$(this).find("name").text(),
$(this).find("front").find("height").text(),
$(this).find("front").find("rcurve").text(),
$(this).find("front").find("k").text(),
$(this).find("front").find("a1").text(),
$(this).find("front").find("a2").text(),
$(this).find("front").find("a3").text(),
$(this).find("front").find("a4").text(),
$(this).find("back").find("height").text(),
$(this).find("back").find("rcurve").text(),
$(this).find("back").find("k").text(),
$(this).find("back").find("a1").text(),
$(this).find("back").find("a2").text(),
$(this).find("back").find("a3").text(),
$(this).find("back").find("a4").text()
);
});
}
function createLink(f,p){
var string = "<a href='";
string+= window.location.href.substr(0,window.location.href.lastIndexOf('?'));
string+="?file="+f;
string+="&path="+p;
string+="'>Permanent Link</a>";
$("#link").html(string);
string = "<a href='files.php?file="+f+"&path="+p+"'>Download XML</a>";
$("#link_dl").html(string);
}