Browse files

MDL-36900 files: D&D upload uses new file name increment function

  • Loading branch information...
1 parent 8158fe0 commit 04cbea2cd61a504bd53a8b1bf3dfaf64e3af26ac @FMCorz FMCorz committed Feb 25, 2013
Showing with 6 additions and 30 deletions.
  1. +6 −30 lib/form/dndupload.js
View
36 lib/form/dndupload.js
@@ -778,41 +778,17 @@ M.form_dndupload.init = function(Y, options) {
},
/**
- * Adds _NUMBER to the end of the filename and increments this number until
- * a unique name is found
+ * Gets a unique file name
+ *
* @param string filename
* @return string the unique filename generated
*/
generate_unique_name: function(filename) {
- // Split the filename into the basename + extension.
- var extension;
- var basename;
- var dotpos = filename.lastIndexOf('.');
- if (dotpos == -1) {
- basename = filename;
- extension = '';
- } else {
- basename = filename.substr(0, dotpos);
- extension = filename.substr(dotpos, filename.length);
- }
-
- // Look to see if the name already has (NN) at the end of it.
- var number = 0;
- var hasnumber = basename.match(/^(.*) \((\d+)\)$/);
- if (hasnumber !== null) {
- // Note the current number & remove it from the basename.
- number = parseInt(hasnumber[2], 10);
- basename = hasnumber[1];
- }
-
// Loop through increating numbers until a unique name is found.
- var newname;
- do {
- number++;
- newname = basename + ' (' + number + ')' + extension;
- } while (this.has_name_clash(newname));
-
- return newname;
+ while (this.has_name_clash(filename)) {
+ filename = increment_filename(filename);
+ }
+ return filename;
},
/**

0 comments on commit 04cbea2

Please sign in to comment.