-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote.js
57 lines (52 loc) · 1.29 KB
/
remote.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
function init_remotestorage(){
remoteStorage.claimAccess({ "dns": 'rw' });
remoteStorage.displayWidget();
}
function zone_to_object(zone_id){
var zone = get_zone(zone_id);
if(!zone){
return;
}
var data = new Object;
data["soa"] = inputs_to_object(zone);
data["name"] = zone_name(zone);
data["records"] = to_array(get_records_div(zone_id)
.getElementsByClassName("record_li"))
.map(
function(record){
return inputs_to_object(record);
}
);
return data;
}
function store_zone(zone_id){
var data = zone_to_object(zone_id);
console.log(data);
notify("Storeing : "+zone_name(get_zone(zone_id)))
remoteStorage.dns.store_zone(data);
}
function load_zone(name){
console.log("loading zone : " + name)
remoteStorage.dns.zone(name).then(
function(data) {
var zone = get_zone_by_name(name);
object_to_input(zone,data["soa"]);
// delete old records for this zone_id here
var records_div = new_records_div(zone.dataset["zone_id"])
data["records"].forEach(
function (record){
object_to_input(new_record(records_div), record);
}
)
}
);
}
function load_all_zones(){
remoteStorage.dns.ls_zones().then(
function(list){
list.forEach(
function(zone){
load_zone(zone);
});
});
}