forked from jessgusclark/gadget-unpublished
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
127 lines (104 loc) · 3.58 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<!-- This title is not used. -->
<title>Gadget Starter</title>
<!-- Use Bootstrap to match the look of OU Campus. -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="css/app.css" />
<!-- jQuery IS REQUIRED for gadgetlib.js to work. -->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<!-- gadgetlib.js is a library of basic functions that gadgets can use. -->
<script type="text/javascript" src="js/gadgetlib.min.js"></script>
</head>
<body>
<div id="main">
<a id="unpublish" role="button" class="btn btn-danger" style="width:100%">Unpublish</a>
<div id="prompt" class="hidden">
<p>Are you sure?</p>
<button type="button" id="cancel" class="btn btn-default btn-sm">Cancel</button>
<button type="button" id="confirm" class="btn btn-danger btn-sm">Yes, Unpublish</button>
</div>
<div id="response" class="hidden">
<div class="alert alert-success">
<strong>Success!</strong> The file has been unpublished.
</div>
</div>
</div>
<!--
The following hidden div is only needed if you'll be editing your gadget in
OU Campus's source code editor. OU Campus automatically adds a DirectEdit link
to HTML files that you edit in OU Campus. This div hides the DirectEdit link.
-->
<div style="display:none">
<!-- ouc:ob --><!-- /ouc:ob -->
</div>
<script type="text/javascript">
$(document).ready(function () {
var currentPage;
gadget.ready().then(gadget.fetch).then(function () {
var apihost = gadget.get('apihost');
var token = gadget.get('token');
var site = gadget.get('site');
$("#unpublish").click(function(){
// make them confirm they want to unpublish
$('#prompt').removeClass('hidden');
});
$('#cancel').click(function(e){
$('#prompt').addClass('hidden');
});
$("#confirm").click(function(){
gadget.oucGetCurrentFileInfo().then(function(data){
var fileInfo = {
"authorization_token" : token,
"site" : site,
"path" : data.stagingPath
}
$.ajax({
dataType: "json",
url: apihost + "/files/info",
data: fileInfo,
success: DeleteFile
});
})
});
function DeleteFile(data) {
var sendData = {
"authorization_token" : token,
"remote": true,
"site": site,
"path" : data.info.remote_path
}
$.ajax({
dataType: "json",
url: apihost + "/files/delete",
data: sendData,
type: "POST",
success: function() {
$("#unpublish").addClass("hidden");
$("#prompt").addClass("hidden");
$("#response").removeClass("hidden");
currentPage = data.info.staging_path;
}
});
}
});
$(gadget).on({
'view_changed': function (evt) {
gadget.oucGetCurrentFileInfo().then(function(data){
if (currentPage != data.stagingPath){
resetGadget(data.id);
}
});
}
});
function resetGadget(path) {
currentPage = path;
$("#unpublish").removeClass("hidden");
$("#prompt").addClass("hidden");
$("#response").addClass("hidden");
}
});
</script>
</body>
</html>