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