-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
147 lines (140 loc) · 4.49 KB
/
main.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var dwui;
$(document).ready(function() {
var loadform = function(json) {
dwui = $dwui.preloadForm(json, {
element: '#dwmap'
});
dwui.refresh();
};
//this functionality should be moved to dwui
var showhidemap = function(active, chained) {
active = active || 'dwmap';
var timeout = 1000;
var m = {
about: {
show: function() { $("#about").show(timeout); },
hide: function() { $("#about").hide(timeout); }
},
listing: {
show: function() { $('#listing').show(timeout); },
hide: function() { $('#listing').hide(timeout); }
},
'new': {
show: function() { dwui.menuview(); },
hide: function() { dwui.menuview(true) }
},
helpbar: {
show: function() { $("#helpbar").show(timeout); },
hide: function() { $("#helpbar").hide(timeout); }
}
};
for(var i in m) {
if(i == active) { m[i].show(); }
else if(typeof chained == 'boolean' && chained) { m[i].show(); }
else { m[i].hide(); }
}
return;
switch(active) {
case 'about':
break;
case 'listing':
$('#listing').show(500);
dwui.menuview(true);
break;
case 'new':
$('#listing').hide(500);
dwui.menuview();
break;
default: //dwmap
//hide listing
//hide editor
$('#listing').hide(500);
dwui.menuview(true);
break;
}
};
var finished = function() {
Sammy('body', function() {
/*this.get(/^\/depweb(|-dev)\/$/, function() {
this.redirect("#/list");
});*/
this.get('#/web/:web', function() {
showhidemap() //default action
//console.log(this.params['web']);
//$('.grapharea div').hide();
//$('#dwmap').show();
$.get('./store/api.php?webid='+this.params['web'], null, 'json')
.done(function(data) {
//redo these as knockouts?
$('#save input[name="form_save_displayname"]').val(data.displayname)
$('#save input[name="form_save_exposure"]').val(data.exposure)
$('#save input[name="form_save_expiration"]').val(data.expiration)
if(data.errmsg) {
$dwui.errMsg(data.errmsg);
} else {
dwui.fromJSON(JSON.stringify(data.web, null, " "));
dwui.refresh();
}
});
}); //end #/web/:web
var listhandler = function() {
showhidemap('listing')
var page = this.params['p'] || 0;
dwui.ko.currentPage(page);
dwui.ko.list().splice(0, dwui.ko.list().length)
$.get('./store/api.php?list&p='+page, null, 'json')
.done(function(d) {
d.forEach(function(v) {
dwui.ko.list().push(v);
});
dwui.ko.list.valueHasMutated();
dwui.refresh();
}).fail(function() {
//error
});
};
this.get("#/list", listhandler);
this.get("#/list/", listhandler);
this.get("#/list/:p", listhandler);
//end #/list
/*this.get('#/edit', function() {
$('.grapharea div').hide();
$('#dw_graph').show();
});//end #/edit*/
this.get('#/new', function() {
showhidemap('new');
dwui.fromJSON('[]');
$('#save input[name="form_save_displayname"]').val('')
$('#save input[name="form_save_exposure"]').val('')
$('#save input[name="form_save_expiration"]').val('')
}); //end #/new
var about = function() {
showhidemap('about');
};
this.get('#/about', about);
this.get(/(\/|\.html)$/i, function() {
about();
$.get('./store/api.php?webid=dw5232acd6bd65b', null, 'json')
.done(function(data) {
//redo these as knockouts?
$('#save input[name="form_save_displayname"]').val(data.displayname)
$('#save input[name="form_save_exposure"]').val(data.exposure)
$('#save input[name="form_save_expiration"]').val(data.expiration)
if(data.errmsg) {
$dwui.errMsg(data.errmsg);
} else {
dwui.fromJSON(JSON.stringify(data.web, null, " "));
dwui.refresh();
}
});
}); //end #/about
this.get('#/help', function() {
console.log(arguments)
showhidemap('helpbar');
}); //end #/hep
}).run();
}
$.getJSON('./data.json')
.fail(loadform.bind({}, JSON.parse($('#dw_text').val())))
.done(loadform).always(finished);
});