Repository navigation
Expand file tree
/
Copy pathSPP_CopyFile.js
More file actions
46 lines (44 loc) · 1.45 KB
/
Copy pathSPP_CopyFile.js
File metadata and controls
46 lines (44 loc) · 1.45 KB
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
/*
SPP_ExtendedCheckIn Plugin written by John Green for The Physician's Postgraduate Press in May, 2019
The prupose of this plugin is to extend SharePointPlus's capabilities. It makes use of the Copy service
to allow duplicating files on the server.
*/
$SP().registerPlugin('CopyFile', function(setup) {
// default values
var _this=this;
return _this._promise(function(prom_resolve, prom_reject) {
setup = setup || {};
if (!setup.source) throw "[SharepointPlus Plugin 'CopyFile'] the file destination path is required.";
if (!setup.destination) throw "[SharepointPlus Plugin 'CopyFile'] the file destination path is required.";
setup.url = ((setup.url===undefined)?window.location.protocol + '//' + window.location.hostname:setup.url);
setup.url = ((setup.url.endsWith('/'))?setup.url.substring(0, setup.url.length - 1):setup.url);
console.log(setup);
try {
$SP().webService({
service:"Copy",
operation:"CopyIntoItemsLocal",
webURL:setup.url,
properties:{
SourceUrl:setup.url+setup.source,
DestinationUrls:"<string>"+setup.url+setup.destination+"</string>"
}
}).then(
function(data){
var res = data.getElementsByTagName('CopyResult');
if (res.length!=1){
prom_reject(res);
} else {
res = res[0];
}
if (res.getAttributeNode('ErrorCode').value != "Success") {
prom_reject(res);
} else {
prom_resolve(data);
}
}
);
} catch (e) {
prom_reject(e);
}
});
});