| 1 |
|
function disknodeCallback(in_target, in_maxfiles, in_fburl) { |
| 2 |
|
this.target = in_target; |
| 3 |
|
if (in_maxfiles == 0) { |
| 4 |
|
in_maxfiles = 1; |
| 5 |
|
} |
| 6 |
|
this.maxfiles = in_maxfiles; |
| 7 |
|
this.filebrowserUrl = in_fburl; |
| 8 |
|
this.lastValue = ""; |
| 9 |
|
}; |
| 10 |
|
|
| 11 |
|
disknodeCallback.prototype.add = function(val) { |
| 12 |
|
if (this.target) { |
| 13 |
|
this.lastValue = val; |
| 14 |
|
if (this.maxfiles != 1) { |
| 15 |
|
// find duplicates and max |
| 16 |
|
var curlist = this.target.value.split('\n'); |
| 17 |
|
for (i = 0; i < curlist.length; i++) { |
| 18 |
|
// duplicate |
| 19 |
|
curlist[i] = curlist[i].replace( /(^\s+)/g, "" ); // trim leading |
| 20 |
|
curlist[i] = curlist[i].replace( /(\s+$)/g, "" ); // trim trailing |
| 21 |
|
if (curlist[i] == "") { // empty line |
| 22 |
|
curlist.splice(i, 1); |
| 23 |
|
i--; |
| 24 |
|
continue; |
| 25 |
|
} |
| 26 |
|
if (curlist[i] == val) return true; |
| 27 |
|
} |
| 28 |
|
curlist[i] = val; |
| 29 |
|
this.target.value = curlist.join('\n'); |
| 30 |
|
} |
| 31 |
|
else { |
| 32 |
|
this.target.value = val; |
| 33 |
|
} |
| 34 |
|
return true; |
| 35 |
|
} |
| 36 |
|
return false; |
| 37 |
|
}; |
| 38 |
|
|
| 39 |
|
disknodeCallback.prototype.getLastValue = function() { |
| 40 |
|
return this.lastValue; |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
disknodeCallback.prototype.openWindow = function() { |
| 44 |
|
if (this.filebrowser && !this.filebrowser.closed) { |
| 45 |
|
this.filebrowser.focus(); |
| 46 |
|
return; |
| 47 |
|
} |
| 48 |
|
this.filebrowser = window.open(this.filebrowserUrl+'&selection='+disknodeFiles.getLastValue(), 'filebrowser', 'width=640, height=640, resizable=yes, scrollbars=yes'); |
| 49 |
|
} |