//########################################################
function GetSearchFolder(SFId ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'search-folders/' + SFId,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
debugger;
//temp = $.grep(resp.data, function (d) {
// return d.name == WSName;
//});
//cache[ "ws_id" ] = temp[0].id ;
console.log("GetWorkspace:success");
},
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
}
})
);
}
//########################################################
function GetWorkspace(WSName ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'workspaces/search',// ?name=' + WSName,//until we get the indexer to work
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
temp = $.grep(resp.data, function (d) {
return d.name == WSName;
});
cache[ "ws_id" ] = temp[0].id ;
console.log("GetWorkspace:success");
},
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
}
})
);
}
//########################################################
function CreateSearchFolder(folderName, TaxYear ){
var stripped = cache[ "ws_id"].replace(/\D/g,'');
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "ws_id" ] + '/search-folders',
type: 'post',
data: JSON.stringify({
database: "Blah",
name: folderName,
default_security: "inherit",
searchprofile:
{
"custom4":TaxYear,
"container": stripped,
"databases":"Blah"
}
}),
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
//cache[ "folder_id" ] = resp.data.id;
console.log("CreateSearchFolder:success");
},
failure: function( resp ){
console.log("CreateSearchFolder:failure");
console.log(resp);
}
})
);
}
//########################################################
// implementation
//########################################################
getToken().then(GetWorkspace("Blah"))
.then(CreateSearchFolder("31-Dec-2017", "2017"))
No comments:
Post a Comment