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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | 15x 15x 15x 15x 198x 15x 15x 6x 6x 15x 192x 192x 15x 12x 12x 12x 12x 12x 15x 21x 21x 21x 15x 108x 108x 108x 33x 15x 18x 18x 3x 15x 15x 15x 18x 18x 18x 15x 18x 15x 18x 18x 18x 18x 15x 6x 6x 6x 15x 12x 12x 15x 15x 177x 177x 15x 177x 177x 6x 177x 15x 177x 177x 177x 177x 177x 177x 177x 177x 177x 177x 177x 177x 177x 177x 15x 177x 177x 177x 177x 177x 177x 177x 177x 15x 177x 177x 118x 177x 177x 177x 177x 177x 177x 15x 96x 828x 15x 18x 18x 18x 18x 15x 78x 78x 78x 801x 78x 78x 15x 66x 15x 33x 33x 33x 33x 33x 33x 33x 33x 15x 33x 33x 33x 33x 33x 33x 33x 15x 39x 39x 33x 33x 33x 15x 69x 69x 14x 26x 15x 69x 69x 69x 69x 15x 33x 33x 15x 195x 195x 15x 15x 15x 15x 15x 72x 72x 15x 15x 267x 15x | /* Copyright 2008-2009 University of Toronto Copyright 2008-2009 University of California, Berkeley Copyright 2008-2009 University of Cambridge Copyright 2010-2016 OCAD University Copyright 2011 Lucendo Development Ltd. Copyright 2013 Raising the Floor - US Copyright 2015 Raising the Floor - International Licensed under the Educational Community License (ECL), Version 2.0 or the New BSD license. You may not use this file except in compliance with one these Licenses. You may obtain a copy of the ECL 2.0 License and BSD License at https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt */ var fluid_3_0_0 = fluid_3_0_0 || {}; /******************* * File Queue View * *******************/ (function ($, fluid) { "use strict"; fluid.registerNamespace("fluid.uploader.fileQueueView"); // Real data binding would be nice to replace these two pairs. fluid.uploader.fileQueueView.rowForFile = function (that, file) { return that.container.find("#" + file.id); }; fluid.uploader.fileQueueView.errorRowForFile = function (that, file) { return $("#" + file.id + "_error", that.container); }; // TODO: None of this hierarchy operates a proper model idiom since it just shares an array instance with fileQueue fluid.uploader.fileQueueView.fileForRow = function (that, row) { return fluid.find_if(that.queueFiles, function (file) { return file.id.toString() === row.prop("id"); }); }; fluid.uploader.fileQueueView.progressorForFile = function (that, file) { var progressId = file.id + "_progress"; return that.fileProgressors[progressId]; }; fluid.uploader.fileQueueView.startFileProgress = function (that, file) { var fileRowElm = fluid.uploader.fileQueueView.rowForFile(that, file); that.scroller.scrollTo(fileRowElm); // update the progressor and make sure that it's in position var fileProgressor = fluid.uploader.fileQueueView.progressorForFile(that, file); fileProgressor.refreshView(); fileProgressor.show(); }; fluid.uploader.fileQueueView.updateFileProgress = function (that, file, fileBytesComplete, fileTotalBytes) { var filePercent = fluid.uploader.derivePercent(fileBytesComplete, fileTotalBytes); var filePercentStr = filePercent + "%"; fluid.uploader.fileQueueView.progressorForFile(that, file).update(filePercent, filePercentStr); }; fluid.uploader.fileQueueView.hideFileProgress = function (that, file) { var fileRowElm = fluid.uploader.fileQueueView.rowForFile(that, file); fluid.uploader.fileQueueView.progressorForFile(that, file).hide(); if (file.filestatus === fluid.uploader.fileStatusConstants.COMPLETE) { that.locate("fileIconBtn", fileRowElm).removeClass(that.options.styles.dim); } }; fluid.uploader.fileQueueView.removeFileProgress = function (that, file) { var fileProgressor = fluid.uploader.fileQueueView.progressorForFile(that, file); if (!fileProgressor) { return; } var rowProgressor = fileProgressor.displayElement; rowProgressor.remove(); }; fluid.uploader.fileQueueView.animateRowRemoval = function (that, row) { row.fadeOut("fast", function () { row.remove(); that.refreshView(); }); }; fluid.uploader.fileQueueView.removeFileErrorRow = function (that, file) { Iif (file.filestatus === fluid.uploader.fileStatusConstants.ERROR) { fluid.uploader.fileQueueView.animateRowRemoval(that, fluid.uploader.fileQueueView.errorRowForFile(that, file)); } }; fluid.uploader.fileQueueView.removeFileAndRow = function (that, file, row) { // Clean up the stuff associated with a file row. fluid.uploader.fileQueueView.removeFileProgress(that, file); fluid.uploader.fileQueueView.removeFileErrorRow(that, file); // Remove the file itself. that.events.onFileRemoved.fire(file); fluid.uploader.fileQueueView.animateRowRemoval(that, row); }; fluid.uploader.fileQueueView.removeFileForRow = function (that, row) { var file = fluid.uploader.fileQueueView.fileForRow(that, row); Iif (!file || file.filestatus === fluid.uploader.fileStatusConstants.COMPLETE) { return; } fluid.uploader.fileQueueView.removeFileAndRow(that, file, row); }; fluid.uploader.fileQueueView.removeRowForFile = function (that, file) { var row = fluid.uploader.fileQueueView.rowForFile(that, file); fluid.uploader.fileQueueView.removeFileAndRow(that, file, row); }; fluid.uploader.fileQueueView.bindHover = function (row, styles) { var over = function () { if (row.hasClass(styles.ready) && !row.hasClass(styles.uploading)) { row.addClass(styles.hover); } }; var out = function () { if (row.hasClass(styles.ready) && !row.hasClass(styles.uploading)) { row.removeClass(styles.hover); } }; row.hover(over, out); }; fluid.uploader.fileQueueView.bindDeleteKey = function (that, row) { var deleteHandler = function () { fluid.uploader.fileQueueView.removeFileForRow(that, row); }; fluid.activatable(row, null, { additionalBindings: [{ key: $.ui.keyCode.DELETE, activateHandler: deleteHandler }] }); }; fluid.uploader.fileQueueView.bindRowHandlers = function (that, row) { Iif ($.browser.msie && $.browser.version < 7) { fluid.uploader.fileQueueView.bindHover(row, that.options.styles); } that.locate("fileIconBtn", row).click(function () { fluid.uploader.fileQueueView.removeFileForRow(that, row); }); fluid.uploader.fileQueueView.bindDeleteKey(that, row); }; fluid.uploader.fileQueueView.renderRowFromTemplate = function (that, file) { var row = that.rowTemplate.clone(), fileName = file.name, fileSize = fluid.uploader.formatFileSize(file.size); row.removeClass(that.options.styles.hiddenTemplate); that.locate("fileName", row).text(fileName); that.locate("fileSize", row).text(fileSize); var fileIconBtn = that.locate("fileIconBtn", row); fileIconBtn.addClass(that.options.styles.remove); fluid.updateAriaLabel(fileIconBtn, that.options.strings.buttons.remove); row.prop("id", file.id); row.addClass(that.options.styles.ready); fluid.uploader.fileQueueView.bindRowHandlers(that, row); fluid.updateAriaLabel(row, fileName + " " + fileSize); return row; }; fluid.uploader.fileQueueView.createProgressorFromTemplate = function (that, row) { // create a new progress bar for the row and position it var rowProgressor = that.rowProgressorTemplate.clone(); var rowId = row.prop("id"); var progressId = rowId + "_progress"; rowProgressor.prop("id", progressId); rowProgressor.css("top", row.position().top); rowProgressor.height(row.height()).width(5); that.container.after(rowProgressor); that.fileProgressors[progressId] = fluid.progress(that.options.uploaderContainer, { selectors: { progressBar: "#" + rowId, displayElement: "#" + progressId, label: "#" + progressId + " .fl-uploader-file-progress-text", indicator: "#" + progressId } }); }; fluid.uploader.fileQueueView.addFile = function (that, file) { var row = fluid.uploader.fileQueueView.renderRowFromTemplate(that, file); /* FLUID-2720 - do not hide the row under IE8 */ if (!($.browser.msie && ($.browser.version >= 8))) { row.hide(); } that.container.append(row); row.attr("title", that.options.strings.status.remove); row.fadeIn("slow"); fluid.uploader.fileQueueView.createProgressorFromTemplate(that, row); that.refreshView(); that.scroller.scrollTo("100%"); }; // Toggle keyboard row handlers on and off depending on the uploader state fluid.uploader.fileQueueView.enableRows = function (rows, state) { for (var i = 0; i < rows.length; i++) { fluid.enabled(rows[i], state); } }; fluid.uploader.fileQueueView.prepareForUpload = function (that) { var rowButtons = that.locate("fileIconBtn", that.locate("fileRows")); rowButtons.prop("disabled", true); rowButtons.addClass(that.options.styles.dim); fluid.uploader.fileQueueView.enableRows(that.locate("fileRows"), false); }; fluid.uploader.fileQueueView.refreshAfterUpload = function (that) { var rows = that.locate("fileRows"); var rowButtons = that.locate("fileIconBtn", rows); // only re-enable rowButtons for files that have not been uploaded. rowButtons.each(function (index, rowButton) { // TODO: Improve detection of completed files so as not to rely on row styling. $(rowButton).prop("disabled", rows.eq(index).hasClass(that.options.styles.uploaded)); }); rowButtons.removeClass(that.options.styles.dim); fluid.uploader.fileQueueView.enableRows(that.locate("fileRows"), true); }; fluid.uploader.fileQueueView.changeRowState = function (that, row, newState) { row.removeClass(that.options.styles.ready).removeClass(that.options.styles.error).addClass(newState); }; fluid.uploader.fileQueueView.markRowAsComplete = function (that, file) { // update styles and keyboard bindings for the file row var row = fluid.uploader.fileQueueView.rowForFile(that, file); fluid.uploader.fileQueueView.changeRowState(that, row, that.options.styles.uploaded); row.attr("title", that.options.strings.status.success); fluid.enabled(row, false); // update the click event and the styling for the file delete button var rowButton = that.locate("fileIconBtn", row); rowButton.off("click"); rowButton.removeClass(that.options.styles.remove); rowButton.attr("title", that.options.strings.status.success); }; fluid.uploader.fileQueueView.renderErrorInfoFromTemplate = function (that, fileRow, error) { // Render the row by cloning the template and binding its id to the file. var errorRow = that.errorInfoTemplate.clone(); errorRow.prop("id", fileRow.prop("id") + "_error"); // Look up the error message and render it. var errorType = fluid.keyForValue(fluid.uploader.errorConstants, error); var errorMsg = that.options.strings.errors[errorType]; that.locate("errorText", errorRow).text(errorMsg); that.locate("fileName", fileRow).after(errorRow); that.scroller.scrollTo(errorRow); }; fluid.uploader.fileQueueView.showErrorForFile = function (that, file, error) { fluid.uploader.fileQueueView.hideFileProgress(that, file); if (file.filestatus === fluid.uploader.fileStatusConstants.ERROR) { var fileRowElm = fluid.uploader.fileQueueView.rowForFile(that, file); fluid.uploader.fileQueueView.changeRowState(that, fileRowElm, that.options.styles.error); fluid.uploader.fileQueueView.renderErrorInfoFromTemplate(that, fileRowElm, error); } }; fluid.uploader.fileQueueView.addKeyboardNavigation = function (that) { fluid.tabbable(that.container); that.selectableContext = fluid.selectable(that.container, { selectableSelector: that.options.selectors.fileRows, onSelect: function (itemToSelect) { $(itemToSelect).addClass(that.options.styles.selected); }, onUnselect: function (selectedItem) { $(selectedItem).removeClass(that.options.styles.selected); } }); }; fluid.uploader.fileQueueView.prepareTemplateElements = function (that) { // Grab our template elements out of the DOM. that.errorInfoTemplate = that.locate("errorInfoTemplate").remove(); that.errorInfoTemplate.removeClass(that.options.styles.hiddenTemplate); that.rowTemplate = that.locate("rowTemplate").remove(); that.rowProgressorTemplate = that.locate("rowProgressorTemplate", that.options.uploaderContainer).remove(); }; fluid.uploader.fileQueueView.markFileComplete = function (that, file) { fluid.uploader.fileQueueView.progressorForFile(that, file).update(100, "100%"); fluid.uploader.fileQueueView.markRowAsComplete(that, file); }; fluid.uploader.fileQueueView.refreshView = function (that) { that.selectableContext.refresh(); that.scroller.refreshView(); }; /** * Creates a new File Queue view. * * @param container {jQuery|selector} the file queue's container DOM element * @param queue {fileQueue} a file queue model instance * @param options {Object} configuration options for the view */ fluid.defaults("fluid.uploader.fileQueueView", { gradeNames: ["fluid.viewComponent"], mergePolicy: { // TODO: This mergePolicy was required by some attempts at fixing FLUID-5668 // and may be required again in future if this component is not modelised // "members.queueFiles": "nomerge" }, members: { fileProgressors: {} // queueFiles: applied in uploader options - TODO: no model idiom }, invokers: { addFile: { funcName: "fluid.uploader.fileQueueView.addFile", args: ["{that}", "{arguments}.0"] // file }, removeFile: { funcName: "fluid.uploader.fileQueueView.removeRowForFile", args: ["{that}", "{arguments}.0"] // file }, prepareForUpload: { funcName: "fluid.uploader.fileQueueView.prepareForUpload", args: "{that}" }, refreshAfterUpload: { funcName: "fluid.uploader.fileQueueView.refreshAfterUpload", args: "{that}" }, showFileProgress: { funcName: "fluid.uploader.fileQueueView.startFileProgress", args: ["{that}", "{arguments}.0"] // file }, updateFileProgress: { funcName: "fluid.uploader.fileQueueView.updateFileProgress", args: ["{that}", "{arguments}.0", "{arguments}.1", "{arguments}.2"] // file, fileBytesComplete, fileTotalBytes }, markFileComplete: { funcName: "fluid.uploader.fileQueueView.markFileComplete", args: ["{that}", "{arguments}.0"] // file }, showErrorForFile: { funcName: "fluid.uploader.fileQueueView.showErrorForFile", args: ["{that}", "{arguments}.0", "{arguments}.1"] // file, error }, hideFileProgress: { funcName: "fluid.uploader.fileQueueView.hideFileProgress", args: ["{that}", "{arguments}.0"] // file }, refreshView: { funcName: "fluid.uploader.fileQueueView.refreshView", args: "{that}" } }, components: { scroller: { type: "fluid.scrollableTable", container: "{fileQueueView}.container" } }, selectors: { fileRows: ".flc-uploader-file", fileName: ".flc-uploader-file-name", fileSize: ".flc-uploader-file-size", fileIconBtn: ".flc-uploader-file-action", errorText: ".flc-uploader-file-error", rowTemplate: ".flc-uploader-file-tmplt", errorInfoTemplate: ".flc-uploader-file-error-tmplt", rowProgressorTemplate: ".flc-uploader-file-progressor-tmplt" }, styles: { hover: "fl-uploader-file-hover", selected: "fl-uploader-file-focus", ready: "fl-uploader-file-state-ready", uploading: "fl-uploader-file-state-uploading", uploaded: "fl-uploader-file-state-uploaded", error: "fl-uploader-file-state-error", remove: "fl-uploader-file-action-remove", dim: "fl-uploader-dim", hiddenTemplate: "fl-uploader-hidden-templates" }, strings: { progress: { toUploadLabel: "To upload: %fileCount %fileLabel (%totalBytes)", singleFile: "file", pluralFiles: "files" }, status: { success: "File Uploaded", error: "File Upload Error", remove: "Press Delete key to remove file" }, errors: { HTTP_ERROR: "File upload error: a network error occured or the file was rejected (reason unknown).", IO_ERROR: "File upload error: a network error occured.", UPLOAD_LIMIT_EXCEEDED: "File upload error: you have uploaded as many files as you are allowed during this session", UPLOAD_FAILED: "File upload error: the upload failed for an unknown reason.", QUEUE_LIMIT_EXCEEDED: "You have as many files in the queue as can be added at one time. Removing files from the queue may allow you to add different files.", FILE_EXCEEDS_SIZE_LIMIT: "One or more of the files that you attempted to add to the queue exceeded the limit of %fileSizeLimit.", ZERO_BYTE_FILE: "One or more of the files that you attempted to add contained no data.", INVALID_FILETYPE: "One or more files were not added to the queue because they were of the wrong type." }, buttons: { remove: "Remove" } }, events: { onFileRemoved: null }, listeners: { "onCreate.prepareTemplateElement": "fluid.uploader.fileQueueView.prepareTemplateElements", "onCreate.addKeyboardNavigation": "fluid.uploader.fileQueueView.addKeyboardNavigation", "onCreate.addAriaRole": { "this": "{that}.container", method: "attr", args: { role: "application" } } } }); /** * An interactional mixin for binding a fileQueueView to an Uploader */ fluid.defaults("fluid.uploader.fileQueueView.bindUploader", { events: { onFileRemoved: "{uploader}.events.onFileRemoved" }, listeners: { "{uploader}.events.afterFileQueued": "{fileQueueView}.addFile", "{uploader}.events.onUploadStart": "{fileQueueView}.prepareForUpload", "{uploader}.events.onFileStart": "{fileQueueView}.showFileProgress", "{uploader}.events.onFileProgress": "{fileQueueView}.updateFileProgress", "{uploader}.events.onFileSuccess": "{fileQueueView}.markFileComplete", "{uploader}.events.onFileError": "{fileQueueView}.showErrorForFile", "{uploader}.events.afterFileComplete": "{fileQueueView}.hideFileProgress", "{uploader}.events.afterUploadComplete": "{fileQueueView}.refreshAfterUpload" } }); /************** * Scrollable * **************/ fluid.registerNamespace("fluid.scrollable"); fluid.scrollable.makeSimple = function (element) { return fluid.container(element); }; fluid.scrollable.makeTable = function (table, wrapperMarkup) { table.wrap(wrapperMarkup); return table.closest(".fl-scrollable-scroller"); }; /** * Simple component cover for the jQuery scrollTo plugin. Provides roughly equivalent * functionality to Uploader's old Scroller plugin. * * @param element {jQueryable} the element to make scrollable * @param options {Object} for the component * @return the scrollable component */ fluid.defaults("fluid.scrollable", { gradeNames: ["fluid.viewComponent"], makeScrollableFn: fluid.scrollable.makeSimple, // NB - a modern style would configure an invoker members: { scrollable: { expander: { func: "{that}.options.makeScrollableFn", args: ["{that}.container", "{that}.options.wrapperMarkup"] // TODO: we need to make sure that expander arguments are evaluated fully } }, maxHeight: { expander: { "this": "{that}.scrollable", method: "css", args: "max-height" } } }, invokers: { /** * Programmatically scrolls this scrollable element to the region specified. * This method is directly compatible with the underlying jQuery.scrollTo plugin. */ scrollTo: { "this": "{that}.scrollable", method: "scrollTo", args: "{arguments}.0" }, refreshView: { funcName: "fluid.scrollable.refreshView", args: "{that}" } }, listeners: { onCreate: "{that}.refreshView" } }); /* * Updates the view of the scrollable region. This should be called when the content of the scrollable region is changed. */ fluid.scrollable.refreshView = function (that) { Iif ($.browser.msie && $.browser.version === "6.0") { that.scrollable.css("height", ""); // Set height, if max-height is reached, to allow scrolling in IE6. if (that.scrollable.height() >= parseInt(that.maxHeight, 10)) { that.scrollable.css("height", that.maxHeight); } } }; /** * Wraps a table in order to make it scrollable with the jQuery.scrollTo plugin. * Container divs are injected to allow cross-browser support. * * @param table {jQueryable} the table to make scrollable * @param options {Object} configuration options * @return the scrollable component */ fluid.defaults("fluid.scrollableTable", { gradeNames: ["fluid.scrollable"], makeScrollableFn: fluid.scrollable.makeTable, wrapperMarkup: "<div class='fl-scrollable-scroller'><div class='fl-scrollable-inner'></div></div>" }); })(jQuery, fluid_3_0_0); |