[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 /** 2 * @requires javelin-install 3 * javelin-dom 4 * phabricator-notification 5 * @provides phabricator-file-upload 6 * @javelin 7 */ 8 9 JX.install('PhabricatorFileUpload', { 10 11 construct : function() { 12 this._notification = new JX.Notification(); 13 }, 14 15 properties : { 16 name : null, 17 totalBytes : null, 18 uploadedBytes : null, 19 ID : null, 20 PHID : null, 21 URI : null, 22 status : null, 23 markup : null, 24 error : null 25 }, 26 27 members : { 28 _notification : null, 29 30 update : function() { 31 if (!this._notification) { 32 return; 33 } 34 35 this._notification 36 .setDuration(0) 37 .show(); 38 39 var content; 40 switch (this.getStatus()) { 41 case 'done': 42 var link = JX.$N('a', {href: this.getURI()}, 'F' + this.getID()); 43 44 content = [ 45 JX.$N('strong', {}, ['Upload Complete (', link, ')']), 46 JX.$N('br'), 47 this.getName() 48 ]; 49 50 this._notification 51 .setContent(content) 52 .alterClassName('jx-notification-done', true) 53 .setDuration(12000); 54 this._notification = null; 55 break; 56 case 'error': 57 content = [ 58 JX.$N('strong', {}, 'Upload Failure'), 59 JX.$N('br'), 60 this.getName(), 61 JX.$N('br'), 62 JX.$N('br'), 63 this.getError() 64 ]; 65 66 this._notification 67 .setContent(content) 68 .alterClassName('jx-notification-error', true); 69 this._notification = null; 70 break; 71 default: 72 var info = ''; 73 if (this.getTotalBytes()) { 74 var p = this._renderPercentComplete(); 75 var f = this._renderFileSize(); 76 info = ' (' + p + ' of ' + f + ')'; 77 } 78 79 info = 'Uploading "' + this.getName() + '"' + info + '...'; 80 81 this._notification 82 .setContent(info); 83 break; 84 } 85 86 return this; 87 }, 88 _renderPercentComplete : function() { 89 if (!this.getTotalBytes()) { 90 return null; 91 } 92 var ratio = this.getUploadedBytes() / this.getTotalBytes(); 93 return parseInt(100 * ratio, 10) + '%'; 94 }, 95 _renderFileSize : function() { 96 if (!this.getTotalBytes()) { 97 return null; 98 } 99 100 var s = 3; 101 var n = this.getTotalBytes(); 102 while (s && n >= 1000) { 103 n = Math.round(n / 100); 104 n = n / 10; 105 s--; 106 } 107 108 s = ['GB', 'MB', 'KB', 'bytes'][s]; 109 return n + ' ' + s; 110 } 111 } 112 113 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |