FSN#44507: (PDA) Bijlagen toevoegen herzien savepoint
svn path=/Website/branches/v2017.2/; revision=35573
This commit is contained in:
@@ -284,7 +284,8 @@ api2_rest = {
|
||||
var result = model["REST_" + method]( requestparams, key );
|
||||
}
|
||||
else if (filter.mode == "attachment" && "custom_fields" in model.includes)
|
||||
{ // GET/PUT/POST https://xxxx.facilitor.nl/trunk/api2/visitors/99685/attachments/1040/testfile.jpg"
|
||||
{ // GET/PUT/POST https://xxxx.facilitor.nl/api2/visitors/99685/attachments/1040/testfile.jpg" bestaande folder
|
||||
// POST https://xxxx.facilitor.nl/api2/issues/0/attachments/1040/testfile.jpg" nieuw object, maakt TEMP aan
|
||||
if (wasCodePage != 65001)
|
||||
{
|
||||
// Door de IIS rewriter is de filenaam in de url utf-8 encoded
|
||||
@@ -328,8 +329,22 @@ api2_rest = {
|
||||
fileStream.Open();
|
||||
fileStream.Write(Request.BinaryRead(bytes));
|
||||
jsondata["custom_fields"][0]["attachments"][0].datastream = fileStream;
|
||||
if (key == 0) // new record
|
||||
{
|
||||
var token = model.includes["custom_fields"].model.REST_POST(requestparams, jsondata.custom_fields[0], -1);
|
||||
|
||||
var record = { xflexparentkey: -1, propertyid: jsondata.custom_fields[0].propertyid};
|
||||
var fileparams = { getFiles: true, api2name: null, tmpfolder: token };
|
||||
var data = model.includes["custom_fields"].model.get_file_info(requestparams, record, fileparams );
|
||||
|
||||
api2_rest.deliver(data, /* dummy model */ { record_name: "attachment" }, "json", true);
|
||||
return;
|
||||
}
|
||||
else
|
||||
method = "PUT"; // het moet altijd een update van een issue zijn
|
||||
}
|
||||
var data = model["REST_" + method](requestparams, jsondata, key);
|
||||
|
||||
var data = model["REST_" + method](requestparams, jsondata, key); // via het hoofdmodel met authorisatie controle en alles
|
||||
if (method == "GET")
|
||||
{
|
||||
if (!data.length) // mogelijk not authorized op hele record
|
||||
|
||||
@@ -88,34 +88,42 @@ function model_custom_fields(formodel, flexModel, flexParams)
|
||||
}
|
||||
};
|
||||
|
||||
this.get_file_info = function (params, record, fileparams)
|
||||
{
|
||||
var flexparam = flexProps(flexModule, record.xflexparentkey,
|
||||
String(record.propertyid), flexParams.pNiveau,
|
||||
fileparams);
|
||||
var attachments = [];
|
||||
for (var f in flexparam.files)
|
||||
{
|
||||
var file = flexparam.files[f];
|
||||
var attachment = { name: file.name,
|
||||
date: file.date,
|
||||
size: file.size,
|
||||
content_url: file.deepurl,
|
||||
token: file.token,
|
||||
digest: file.digest };
|
||||
switch (params.filter.fileencoding) // De enige twee encodings die we ondersteunen
|
||||
{
|
||||
case "base64":
|
||||
attachment.content_base64 = file.data;
|
||||
break;
|
||||
case "hex":
|
||||
attachment.content_hex = file.data;
|
||||
break;
|
||||
}
|
||||
attachments.push(attachment);
|
||||
};
|
||||
return attachments;
|
||||
}
|
||||
// Deze functie wordt na de GET aangeroepen. De bijlagen zijn zo afwijkend
|
||||
// dat ik dat niet fatsoenlijk in 'fields' verwerkt kreeg
|
||||
this.post_get = function (params, record)
|
||||
{
|
||||
if (record.type == 'F' || record.type == 'M')
|
||||
{
|
||||
var flexparam = flexProps(flexModule, record.xflexparentkey, String(record.propertyid), flexParams.pNiveau,
|
||||
{ getFiles: true, getFileEncoded: params.filter.fileencoding, api2name: formodel.records_name });
|
||||
record.attachments = [];
|
||||
for (var f in flexparam.files)
|
||||
{
|
||||
var file = flexparam.files[f];
|
||||
var attachment = { name: file.name,
|
||||
date: file.date,
|
||||
size: file.size,
|
||||
content_url: file.deepurl,
|
||||
digest: file.digest };
|
||||
switch (params.filter.fileencoding) // De enige twee encodings die we ondersteunen
|
||||
{
|
||||
case "base64":
|
||||
attachment.content_base64 = file.data;
|
||||
break;
|
||||
case "hex":
|
||||
attachment.content_hex = file.data;
|
||||
break;
|
||||
}
|
||||
record.attachments.push(attachment);
|
||||
};
|
||||
var fileparams = { getFiles: true, getFileEncoded: params.filter.fileencoding, api2name: formodel.records_name };
|
||||
record.attachments = this.get_file_info(params, record, fileparams);
|
||||
}
|
||||
delete record["xflexparentkey"]; // nu niet meer nodig
|
||||
}
|
||||
@@ -172,7 +180,9 @@ function model_custom_fields(formodel, flexModel, flexParams)
|
||||
}
|
||||
if (typ == 'F' || typ == 'M')
|
||||
{
|
||||
var flexparams = flexProps(this.module, parent_key, the_key, flexParams.pNiveau);
|
||||
if (!(parent_key > 0))
|
||||
var tmpfolder = safe.filename(shared.random(32));
|
||||
var flexparams = flexProps(this.module, parent_key, the_key, flexParams.pNiveau, { tmpfolder: tmpfolder });
|
||||
// TODO: bij type F zorgen dat er <20><>n file overblijft
|
||||
for (var i = 0; i < jsondata.attachments.length; i++)
|
||||
{
|
||||
@@ -201,7 +211,7 @@ function model_custom_fields(formodel, flexModel, flexParams)
|
||||
}
|
||||
}
|
||||
|
||||
if (typ != "M")
|
||||
if (typ != "M" && parent_key > 0)
|
||||
{
|
||||
var sql = "BEGIN flx.setflex({0}".format(safe.quoted_sql(this.module))
|
||||
+ " , {0}".format(the_key) // == jsondata.propertyid
|
||||
@@ -213,12 +223,13 @@ function model_custom_fields(formodel, flexModel, flexParams)
|
||||
if (err.friendlyMsg)
|
||||
api2.error(400, err.friendlyMsg);
|
||||
}
|
||||
return tmpfolder;
|
||||
}
|
||||
|
||||
if (flexModel) // nog even niet voor MLD
|
||||
this.REST_POST = function (params, jsondata, parent_key) /* add custom_field */
|
||||
{ // Voor flexvelden is er geen verschil tusen 'toevoegen' en 'bijwerken'
|
||||
this.REST_PUT(params, jsondata, jsondata.propertyid, parent_key);
|
||||
return this.REST_PUT(params, jsondata, jsondata.propertyid, parent_key);
|
||||
}
|
||||
|
||||
this.disabled_REST_DELETE = function (params, the_key) /* remove custom_field */
|
||||
|
||||
@@ -236,7 +236,7 @@ function flexProps(pModule, pKey, pSubpath, pNiveau, params)
|
||||
result.AttachRootPath = S("flexFilesPath");
|
||||
result.AttachPath = result.AttachRootPath + "/" + pModule + "/";
|
||||
result.AttachPath += (pKey > 0? subfolderKey(bepaalNiveau(pModule, pNiveau), pKey)
|
||||
: subfolderNew(bepaalNiveau(pModule, pNiveau), user_key + "_" + getQParam("tmpfolder")));
|
||||
: subfolderNew(bepaalNiveau(pModule, pNiveau), user_key + "_" + (params.tmpfolder||getQParam("tmpfolder"))));
|
||||
result.AttachPath += "/" + pSubpath + "/";
|
||||
result.extFilter = getQParam("extFilter", S("flexExtensionFilter"));
|
||||
result.regexp = getQParam("pregexp", ""); //P800x600 cropt/resized naar 800x600
|
||||
@@ -495,8 +495,11 @@ function oneFileInfo(fsoFile, result, pModule, pKey, pSubpath, pNiveau, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (params.api2name)
|
||||
if (params.tmpfolder)
|
||||
{
|
||||
filedata.token = params.tmpfolder;
|
||||
}
|
||||
else if (params.api2name)
|
||||
{
|
||||
var deepurl = HTTP.urlzelf() + "/api2/{0}/{1}/attachments/{2}/{3}".format(
|
||||
params.api2name,
|
||||
|
||||
Reference in New Issue
Block a user