Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 1 | $.Class ("ChronoShare", { }, |
| 2 | { |
| 3 | init: function (username, foldername) { |
| 4 | $("#folder-name").text (foldername); |
| 5 | $("#user-name").text (username); |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 6 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 7 | this.username = new Name (username); |
| 8 | this.files = new Name ("/localhost").add (this.username).add ("chronoshare").add (foldername).add ("info").add ("files").add ("folder"); |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 9 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 10 | this.actions = new Name ("/localhost").add (this.username).add ("chronoshare").add (foldername).add ("info").add ("actions"); |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 11 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 12 | this.restore = new Name ("/localhost").add (this.username).add ("chronoshare").add (foldername).add ("cmd").add ("restore").add ("file"); |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 13 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 14 | this.ndn = new NDN ({host:"127.0.0.1"}); |
| 15 | }, |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 16 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 17 | run: function () { |
| 18 | console.log ("RUN page: " + PAGE); |
| 19 | $("#loader").fadeIn (500); |
| 20 | $("#error").addClass ("hidden"); |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 21 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 22 | cmd = {}; |
| 23 | if (PAGE == "fileList") { |
| 24 | cmd = this.info_files (PARAMS.item); |
| 25 | } |
| 26 | else if (PAGE == "folderHistory") { |
| 27 | cmd = this.info_actions ("folder", PARAMS.item); |
| 28 | } |
| 29 | else if (PAGE == "fileHistory") { |
| 30 | cmd = this.info_actions ("file", PARAMS.item); |
| 31 | } |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 33 | if (cmd.request && cmd.callback) { |
| 34 | console.log (cmd.request.to_uri ()); |
| 35 | this.ndn.expressInterest (cmd.request, cmd.callback); |
| 36 | } |
| 37 | else { |
| 38 | $("#loader").fadeOut (500); // ("hidden"); |
| 39 | $("#content").empty (); |
| 40 | if (cmd.error) { |
| 41 | $("#error").html (cmd.error); |
| 42 | } |
| 43 | else { |
| 44 | $("#error").html ("Unknown error with " + PAGE); |
| 45 | } |
| 46 | $("#error").removeClass ("hidden"); |
| 47 | } |
| 48 | }, |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 49 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 50 | info_files: function(folder) { |
| 51 | request = new Name ().add (this.files)./*add (folder_in_question).*/addSegment (PARAMS.offset?PARAMS.offset:0); |
| 52 | return { request:request, callback: new FilesClosure (this) }; |
| 53 | }, |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 54 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 55 | info_actions: function (type/*"file" or "folder"*/, fileOrFolder /*file or folder name*/) { |
| 56 | if (type=="file" && !fileOrFolder) { |
| 57 | return { error: "info_actions: fileOrFolder parameter is missing" }; |
| 58 | } |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 60 | request = new Name ().add (this.actions).add (type); |
| 61 | if (fileOrFolder) { |
| 62 | request.add (fileOrFolder); |
| 63 | } |
| 64 | request.addSegment (PARAMS.offset?PARAMS.offset:0); |
| 65 | return { request: request, callback: new HistoryClosure (this) }; |
| 66 | }, |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 67 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 68 | cmd_restore_file: function (filename, version, hash, callback/*function (bool <- data received, status <- returned status)*/) { |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 69 | request = new Name ().add (this.restore) |
| 70 | .add (filename) |
| 71 | .addSegment (version) |
| 72 | .add (hash); |
| 73 | console.log (request.to_uri ()); |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 74 | this.ndn.expressInterest (request, new CmdRestoreFileClosure (this, callback)); |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 75 | } |
| 76 | }); |
Zhenkai Zhu | 5c2475b | 2013-02-26 22:57:31 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 78 | $.Class ("CmdRestoreFileClosure", {}, { |
| 79 | init: function (chronoshare, callback) { |
| 80 | this.chronoshare = chronoshare; |
| 81 | this.callback = callback; |
| 82 | }, |
| 83 | upcall: function(kind, upcallInfo) { |
| 84 | if (kind == Closure.UPCALL_CONTENT) { |
| 85 | convertedData = DataUtils.toString (upcallInfo.contentObject.content); |
| 86 | this.callback (true, convertedData); |
| 87 | } |
| 88 | else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) { |
| 89 | this.callback (false, "Interest timed out"); |
| 90 | } |
| 91 | else { |
| 92 | this.callback (false, "Unknown error happened"); |
| 93 | } |
| 94 | } |
| 95 | }); |
| 96 | |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 97 | $.Class ("FilesClosure", {}, { |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 98 | init: function (chronoshare) { |
| 99 | this.chronoshare = chronoshare; |
| 100 | }, |
| 101 | |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 102 | upcall: function(kind, upcallInfo) { |
| 103 | $("#loader").fadeOut (500); // ("hidden"); |
| 104 | if (kind == Closure.UPCALL_CONTENT) { |
| 105 | convertedData = DataUtils.toString (upcallInfo.contentObject.content); |
Alexander Afanasyev | c15e016 | 2013-02-28 23:38:52 -0800 | [diff] [blame] | 106 | if (PARAMS.debug) { |
| 107 | $("#json").text (convertedData); |
| 108 | $("#json").removeClass ("hidden"); |
| 109 | } |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 110 | data = JSON.parse (convertedData); |
Zhenkai Zhu | 5c2475b | 2013-02-26 22:57:31 -0800 | [diff] [blame] | 111 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 112 | tbody = $("<tbody />", { "id": "file-list-files" }); |
| 113 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 114 | /// @todo Eventually set title for other pages |
| 115 | $("title").text ("ChronoShare - List of files" + (PARAMS.item?" - "+PARAMS.item:"")); |
| 116 | |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 117 | // error handling? |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 118 | newcontent = $("<div />", { "id": "content" }).append ( |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 119 | $("<h2 />").append ($(document.createTextNode("List of files ")), $("<green />").text (PARAMS.item)), |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 120 | $("<table />", { "class": "item-list" }) |
| 121 | .append ($("<thead />") |
| 122 | .append ($("<tr />") |
| 123 | .append ($("<th />", { "class": "filename border-left", "scope": "col" }).text ("Filename")) |
| 124 | .append ($("<th />", { "class": "version", "scope": "col" }).text ("Version")) |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 125 | .append ($("<th />", { "class": "size", "scope": "col" }).text ("Size")) |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 126 | .append ($("<th />", { "class": "modified", "scope": "col" }).text ("Modified")) |
| 127 | .append ($("<th />", { "class": "modified-by border-right", "scope": "col" }).text ("Modified By")))) |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 128 | .append (tbody) |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 129 | .append ($("<tfoot />") |
| 130 | .append ($("<tr />") |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 131 | .append ($("<td />", { "colspan": "5", "class": "border-right border-left" }))))); |
| 132 | newcontent.hide (); |
Zhenkai Zhu | 5c2475b | 2013-02-26 22:57:31 -0800 | [diff] [blame] | 133 | |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 134 | for (var i = 0; i < data.files.length; i++) { |
| 135 | file = data.files[i]; |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 136 | |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 137 | row = $("<tr />", { "class": "with-context-menu" } ); |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 138 | if (i%2) { row.addClass ("odd"); } |
| 139 | |
| 140 | row.bind('mouseenter mouseleave', function() { |
| 141 | $(this).toggleClass('highlighted'); |
| 142 | }); |
| 143 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 144 | row.attr ("filename", file.filename); //encodeURIComponent(encodeURIComponent(file.filename))); |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 145 | row.bind('click', function (e) { openHistoryForItem ($(this).attr ("filename")) }); |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 146 | |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 147 | row.append ($("<td />", { "class": "filename border-left" }) |
| 148 | .text (file.filename) |
| 149 | .prepend ($("<img />", { "src": fileExtension(file.filename) }))); |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 150 | row.append ($("<td />", { "class": "version" }).text (file.version)); |
| 151 | row.append ($("<td />", { "class": "size" }).text (SegNumToFileSize (file.segNum))); |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 152 | row.append ($("<td />", { "class": "modified" }).text (new Date (file.timestamp+"+00:00"))); // convert from UTC |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 153 | row.append ($("<td />", { "class": "modified-by border-right"}) |
Alexander Afanasyev | 46bd806 | 2013-02-27 23:59:15 -0800 | [diff] [blame] | 154 | .append ($("<userName />").text (file.owner.userName)) |
| 155 | .append ($("<seqNo> /").text (file.owner.seqNo))); |
| 156 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 157 | tbody = tbody.append (row); |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 158 | } |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 159 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 160 | displayContent (newcontent, data.more, this.base_url ()); |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 161 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 162 | $.contextMenu( 'destroy', ".with-context-menu" ); // cleanup |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 163 | $.contextMenu({ |
| 164 | selector: ".with-context-menu", |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 165 | items: { |
| 166 | "info": {name: "x", type: "html", html: "<b>File operations</b>"}, |
| 167 | "sep1": "---------", |
| 168 | history: {name: "View file history", |
| 169 | icon: "quit", // need a better icon |
| 170 | callback: function(key, opt) { |
| 171 | openHistoryForItem (opt.$trigger.attr ("filename")); |
| 172 | }}, |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 173 | } |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 174 | }); |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 175 | } |
| 176 | else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) { |
| 177 | $("#error").html ("Interest timed out"); |
| 178 | $("#error").removeClass ("hidden"); |
| 179 | } |
| 180 | else { |
| 181 | $("#error").html ("Unknown error happened"); |
| 182 | $("#error").removeClass ("hidden"); |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 183 | } |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 184 | }, |
| 185 | |
| 186 | base_url: function () { |
| 187 | url = "#fileList"+ |
| 188 | "&user="+encodeURIComponent (encodeURIComponent (PARAMS.user)) + |
| 189 | "&folder="+encodeURIComponent (encodeURIComponent (PARAMS.folder)); |
| 190 | if (PARAMS.item !== undefined) { |
| 191 | url += "&item="+encodeURIComponent (encodeURIComponent (PARAMS.item)); |
| 192 | } |
| 193 | return url; |
Zhenkai Zhu | 5c2475b | 2013-02-26 22:57:31 -0800 | [diff] [blame] | 194 | } |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 195 | }); |
Zhenkai Zhu | 5c2475b | 2013-02-26 22:57:31 -0800 | [diff] [blame] | 196 | |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 197 | |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 198 | $.Class ("HistoryClosure", {}, { |
| 199 | init: function (chronoshare) { |
| 200 | this.chronoshare = chronoshare; |
| 201 | }, |
| 202 | |
| 203 | upcall: function(kind, upcallInfo) { |
| 204 | $("#loader").fadeOut (500); // ("hidden"); |
| 205 | if (kind == Closure.UPCALL_CONTENT) { |
| 206 | convertedData = DataUtils.toString (upcallInfo.contentObject.content); |
Alexander Afanasyev | c15e016 | 2013-02-28 23:38:52 -0800 | [diff] [blame] | 207 | if (PARAMS.debug) { |
| 208 | $("#json").text (convertedData); |
| 209 | $("#json").removeClass ("hidden"); |
| 210 | } |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 211 | data = JSON.parse (convertedData); |
| 212 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 213 | tbody = $("<tbody />", { "id": "history-list-actions" }); |
| 214 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 215 | /// @todo Eventually set title for other pages |
| 216 | $("title").text ("ChronoShare - Recent actions" + (PARAMS.item?" - "+PARAMS.item:"")); |
| 217 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 218 | newcontent = $("<div />", { "id": "content" }).append ( |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 219 | $("<h2 />").append ($(document.createTextNode("Recent actions ")), $("<green />").text (PARAMS.item)), |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 220 | $("<table />", { "class": "item-list" }) |
| 221 | .append ($("<thead />") |
| 222 | .append ($("<tr />") |
| 223 | .append ($("<th />", { "class": "filename border-left", "scope": "col" }).text ("Filename")) |
| 224 | .append ($("<th />", { "class": "version", "scope": "col" }).text ("Version")) |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 225 | .append ($("<th />", { "class": "size", "scope": "col" }).text ("Size")) |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 226 | .append ($("<th />", { "class": "modified", "scope": "col" }).text ("Modified")) |
| 227 | .append ($("<th />", { "class": "modified-by border-right", "scope": "col" }).text ("Modified By")))) |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 228 | .append (tbody) |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 229 | .append ($("<tfoot />") |
| 230 | .append ($("<tr />") |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 231 | .append ($("<td />", { "colspan": "5", "class": "border-right border-left" }))))); |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 232 | |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 233 | for (var i = 0; i < data.actions.length; i++) { |
| 234 | action = data.actions[i]; |
| 235 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 236 | row = $("<tr />"); |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 237 | if (i%2) { row.addClass ("odd"); } |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 238 | if (action.action=="DELETE") { |
| 239 | row.addClass ("delete"); |
| 240 | } |
| 241 | else { |
| 242 | row.addClass ("with-context-menu"); |
| 243 | row.attr ("file_version", action.version); |
| 244 | row.attr ("file_hash", action.update.hash); |
| 245 | row.attr ("file_modified_by", action.id.userName); |
| 246 | } |
| 247 | |
| 248 | row.attr ("filename", action.filename); |
| 249 | row.bind('click', function (e) { openHistoryForItem ($(this).attr ("filename")) }); |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 250 | |
| 251 | row.bind('mouseenter mouseleave', function() { |
| 252 | $(this).toggleClass('highlighted'); |
| 253 | }); |
| 254 | |
Alexander Afanasyev | f7c7cde | 2013-03-02 00:01:32 -0800 | [diff] [blame] | 255 | row.append ($("<td />", { "class": "filename border-left" }) |
| 256 | .text (action.filename) |
| 257 | .prepend ($("<img />", { "src": fileExtension(action.filename) }))); |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 258 | row.append ($("<td />", { "class": "version" }).text (action.version)); |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 259 | row.append ($("<td />", { "class": "size" }).text (action.update?SegNumToFileSize (action.update.segNum):"")); |
| 260 | row.append ($("<td />", { "class": "timestamp" }).text (new Date (action.timestamp+"+00:00"))); // conversion from UTC timezone (we store action time in UTC) |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 261 | row.append ($("<td />", { "class": "modified-by border-right" }) |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 262 | .append ($("<userName />").text (action.id.userName)) |
| 263 | .append ($("<seqNo> /").text (action.id.seqNo))); |
| 264 | |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 265 | tbody = tbody.append (row); |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 266 | } |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 267 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 268 | displayContent (newcontent, data.more, this.base_url (PAGE)); |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 269 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 270 | $.contextMenu( 'destroy', ".with-context-menu" ); // cleanup |
| 271 | $.contextMenu({ |
| 272 | selector: ".with-context-menu", |
| 273 | items: { |
| 274 | "sep1": "---------", |
| 275 | restore: {name: "Restore this revision", |
| 276 | icon: "cut", // need a better icon |
| 277 | callback: function(key, opt) { |
| 278 | filename = opt.$trigger.attr ("filename"); |
| 279 | version = opt.$trigger.attr ("file_version"); |
| 280 | hash = DataUtils.toNumbers (opt.$trigger.attr ("file_hash")); |
| 281 | console.log (hash); |
| 282 | modified_by = opt.$trigger.attr ("file_modified_by"); |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 283 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 284 | $("<div />", { "title": "Restore version " + version + "?" }) |
| 285 | .append ($("<p />") |
| 286 | .append ($("<span />", { "class": "ui-icon ui-icon-alert", |
| 287 | "style": "float: left; margin: 0 7px 50px 0;" }), |
| 288 | $(document.createTextNode ("Are you sure you want restore version ")), |
| 289 | $("<green/>").text (version), |
| 290 | $(document.createTextNode (" by ")), |
| 291 | $("<green/>").text (modified_by))) |
| 292 | .dialog ({ |
| 293 | resizable: true, |
| 294 | height:200, |
| 295 | width:300, |
| 296 | modal: true, |
| 297 | buttons: { |
| 298 | "Restore": function() { |
| 299 | self = $(this); |
| 300 | CHRONOSHARE.cmd_restore_file (filename, version, hash, function(didGetData, response) { |
| 301 | if (!didGetData || response != "OK") { |
| 302 | custom_alert (response); |
| 303 | } |
| 304 | console.log (response); |
| 305 | self.dialog ("close"); |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 306 | |
Alexander Afanasyev | 4c17b48 | 2013-03-02 01:32:35 -0800 | [diff] [blame^] | 307 | $.timer (function() {CHRONOSHARE.run ();}).once (1000); |
| 308 | }); |
| 309 | }, |
| 310 | Cancel: function() { |
| 311 | $(this).dialog ("close"); |
| 312 | } |
| 313 | } |
| 314 | }); |
| 315 | // openHistoryForItem (opt.$trigger.attr ("filename")); |
| 316 | }}, |
| 317 | "sep2": "---------", |
| 318 | } |
| 319 | }); |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 320 | } |
| 321 | else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) { |
| 322 | $("#error").html ("Interest timed out"); |
| 323 | $("#error").removeClass ("hidden"); |
| 324 | } |
| 325 | else { |
| 326 | $("#error").html ("Unknown error happened"); |
| 327 | $("#error").removeClass ("hidden"); |
| 328 | } |
Alexander Afanasyev | 3c95c85 | 2013-03-01 18:58:50 -0800 | [diff] [blame] | 329 | }, |
| 330 | |
| 331 | base_url: function (page) { |
| 332 | url = "#"+page+ |
| 333 | "&user="+encodeURIComponent (encodeURIComponent (PARAMS.user)) + |
| 334 | "&folder="+encodeURIComponent (encodeURIComponent (PARAMS.folder)); |
| 335 | if (PARAMS.item !== undefined) { |
| 336 | url += "&item="+encodeURIComponent (encodeURIComponent (PARAMS.item)); |
| 337 | } |
| 338 | return url; |
Alexander Afanasyev | f63a514 | 2013-02-28 02:21:42 -0800 | [diff] [blame] | 339 | } |
| 340 | }); |
| 341 | |
| 342 | |
Alexander Afanasyev | fd5e627 | 2013-02-27 20:25:20 -0800 | [diff] [blame] | 343 | |
| 344 | |