Skip to content

Commit

Permalink
v2-Beta7 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 committed Jan 31, 2023
1 parent e7da2cb commit 304e940
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 65 deletions.
45 changes: 24 additions & 21 deletions frappe_better_attach_control/public/js/controls/attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,28 +247,31 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro
var tmp = {options: {restrictions: {}}};
tmp.allow_reload = toBool(ifNull(opts.allow_reload, true));
tmp.allow_remove = toBool(ifNull(opts.allow_remove, true));
function parseVal(v, t) {
if (isEmpty(v)) v = null;
if (t === 's' && v) {
v = cstr(v);
v = v.length ? v : null;
}
else if (t === 'b') v = toBool(ifNull(v, false));
else if (t === 'i' && v) {
v = cint(v);
if (isNaN(v) || v < 1) v = null;
}
else if (t === 'a') v = toArray(v);
return v;
}
each([['upload_notes', 's'], ['allow_multiple', 'b']], function(k) {
tmp.options[k[0]] = parseVal(opts[k[0]], k[1]);
});
each(
[
'upload_notes', 'allow_multiple',
'max_file_size', 'allowed_file_types',
'max_number_of_files', 'crop_image_aspect_ratio',
'as_public',
['max_file_size', 'i'], ['allowed_file_types', 'a'],
['max_number_of_files', 'i'], ['crop_image_aspect_ratio', 'i'],
['as_public', 'b'],
],
function(k, i) {
let v = opts[k];
if (isEmpty(v)) v = null;
if (v && i === 0) {
v = cstr(v);
v = v.length ? v : null;
}
else if (i === 1 || i === 6) v = toBool(ifNull(v, false));
else if (v && [2, 4, 5].indexOf(i) >= 0) {
v = cint(v);
if (isNaN(v) || v < 1) v = null;
}
else if (i === 3) v = toArray(v);
if (i < 2) tmp.options[k] = v;
else tmp.options.restrictions[k] = v;
function(k) {
tmp.options.restrictions[k[0]] = parseVal(opts[k[0]], k[1]);
}
);
return tmp;
Expand All @@ -283,12 +286,12 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro
if (!this._allow_reload) this.enable_reload();
else this.disable_reload();
}
if (ifNull(opt.allow_remove, true) !== this._allow_remove) {
if (ifNull(opts.allow_remove, true) !== this._allow_remove) {
if (!this._allow_remove) this.enable_remove();
else this.disable_remove();
}
}
let allow_multiple = opt.options && !!opt.options.allow_multiple;
let allow_multiple = opts.options && !!opts.options.allow_multiple;
if (allow_multiple !== this._allow_multiple) {
this._allow_multiple = allow_multiple;
this._set_max_attachments();
Expand Down
40 changes: 21 additions & 19 deletions frappe_better_attach_control/public/js/controls/v12/attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,28 +216,30 @@ frappe.ui.form.ControlAttach = frappe.ui.form.ControlAttach.extend({
_parse_options: function(opts) {
var tmp = {options: {restrictions: {}}};
tmp.allow_remove = toBool(ifNull(opts.allow_remove, true));
function parseVal(v, t) {
if (isEmpty(v)) v = null;
if (t === 's' && v) {
v = cstr(v);
v = v.length ? v : null;
}
else if (t === 'b') v = toBool(ifNull(v, false));
else if (t === 'i' && v) {
v = cint(v);
if (isNaN(v) || v < 1) v = null;
}
else if (t === 'a') v = toArray(v);
return v;
}
each([['upload_notes', 's'], ['allow_multiple', 'b']], function(k) {
tmp.options[k[0]] = parseVal(opts[k[0]], k[1]);
});
each(
[
'upload_notes', 'allow_multiple',
'max_file_size', 'allowed_file_types',
'max_number_of_files',
'as_public',
['max_file_size', 'i'], ['allowed_file_types', 'a'],
['max_number_of_files', 'i'], ['as_public', 'b'],
],
function(k, i) {
let v = opts[k];
if (isEmpty(v)) v = null;
if (v && i === 0) {
v = cstr(v);
v = v.length ? v : null;
}
else if (i === 1 || i === 6) v = toBool(ifNull(v, false));
else if (v && [2, 4, 5].indexOf(i) >= 0) {
v = cint(v);
if (isNaN(v) || v < 1) v = null;
}
else if (i === 3) v = toArray(v);
if (i < 2) tmp.options[k] = v;
else tmp.options.restrictions[k] = v;
function(k) {
tmp.options.restrictions[k[0]] = parseVal(opts[k[0]], k[1]);
}
);
return tmp;
Expand Down
40 changes: 21 additions & 19 deletions frappe_better_attach_control/public/js/controls/v13/attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,28 +237,30 @@ frappe.ui.form.ControlAttach = frappe.ui.form.ControlAttach.extend({
var tmp = {options: {restrictions: {}}};
tmp.allow_reload = toBool(ifNull(opts.allow_reload, true));
tmp.allow_remove = toBool(ifNull(opts.allow_remove, true));
function parseVal(v, t) {
if (isEmpty(v)) v = null;
if (t === 's' && v) {
v = cstr(v);
v = v.length ? v : null;
}
else if (t === 'b') v = toBool(ifNull(v, false));
else if (t === 'i' && v) {
v = cint(v);
if (isNaN(v) || v < 1) v = null;
}
else if (t === 'a') v = toArray(v);
return v;
}
each([['upload_notes', 's'], ['allow_multiple', 'b']], function(k) {
tmp.options[k[0]] = parseVal(opts[k[0]], k[1]);
});
each(
[
'upload_notes', 'allow_multiple',
'max_file_size', 'allowed_file_types',
'max_number_of_files',
'as_public',
['max_file_size', 'i'], ['allowed_file_types', 'a'],
['max_number_of_files', 'i'], ['as_public', 'b'],
],
function(k, i) {
let v = opts[k];
if (isEmpty(v)) v = null;
if (v && i === 0) {
v = cstr(v);
v = v.length ? v : null;
}
else if (i === 1 || i === 6) v = toBool(ifNull(v, false));
else if (v && [2, 4, 5].indexOf(i) >= 0) {
v = cint(v);
if (isNaN(v) || v < 1) v = null;
}
else if (i === 3) v = toArray(v);
if (i < 2) tmp.options[k] = v;
else tmp.options.restrictions[k] = v;
function(k) {
tmp.options.restrictions[k[0]] = parseVal(opts[k[0]], k[1]);
}
);
return tmp;
Expand Down
7 changes: 5 additions & 2 deletions frappe_better_attach_control/public/js/uploader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ frappe.ui.FileUploader = class FileUploader extends frappe.ui.FileUploader {
this.uploader.$watch('show_file_browser', function(show_file_browser) {
if (show_file_browser && !me.uploader.$refs.file_browser._restrictions) {
me._override_file_browser(
!isEmpty(opts.restrictions)
isPlainObject(opts) && !isEmpty(opts.restrictions)
? opts.restrictions
: {
max_file_size: null,
Expand All @@ -42,7 +42,10 @@ frappe.ui.FileUploader = class FileUploader extends frappe.ui.FileUploader {
}
_override_uploader(opts) {
var up = this.uploader;
up.restrictions.as_public = !!opts.restrictions.as_public;
if (opts) {
up.restrictions = opts.restrictions;
up.restrictions.as_public = !!opts.restrictions.as_public;
}
up.dropfiles = function(e) {
this.is_dragging = false;
if (isObject(e) && isObject(e.dataTransfer))
Expand Down
7 changes: 5 additions & 2 deletions frappe_better_attach_control/public/js/uploader/v12/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ frappe.ui.FileUploader = class FileUploader extends frappe.ui.FileUploader {
this.uploader.$watch('show_file_browser', function(show_file_browser) {
if (show_file_browser && !me.uploader.$refs.file_browser._restrictions) {
me._override_file_browser(
!isEmpty(opts.restrictions)
isPlainObject(opts) && !isEmpty(opts.restrictions)
? opts.restrictions
: {
max_file_size: null,
Expand All @@ -41,7 +41,10 @@ frappe.ui.FileUploader = class FileUploader extends frappe.ui.FileUploader {
}
_override_uploader(opts) {
var up = this.uploader;
up.restrictions.as_public = !!opts.restrictions.as_public;
if (opts) {
up.restrictions = opts.restrictions;
up.restrictions.as_public = !!opts.restrictions.as_public;
}
up.dropfiles = function(e) {
this.is_dragging = false;
if (isObject(e) && isObject(e.dataTransfer))
Expand Down
7 changes: 5 additions & 2 deletions frappe_better_attach_control/public/js/uploader/v13/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ frappe.ui.FileUploader = class FileUploader extends frappe.ui.FileUploader {
this.uploader.$watch('show_file_browser', function(show_file_browser) {
if (show_file_browser && !me.uploader.$refs.file_browser._restrictions) {
me._override_file_browser(
!isEmpty(opts.restrictions)
isPlainObject(opts) && !isEmpty(opts.restrictions)
? opts.restrictions
: {
max_file_size: null,
Expand All @@ -41,7 +41,10 @@ frappe.ui.FileUploader = class FileUploader extends frappe.ui.FileUploader {
}
_override_uploader(opts) {
var up = this.uploader;
up.restrictions.as_public = !!opts.restrictions.as_public;
if (opts) {
up.restrictions = opts.restrictions;
up.restrictions.as_public = !!opts.restrictions.as_public;
}
up.dropfiles = function(e) {
this.is_dragging = false;
if (isObject(e) && isObject(e.dataTransfer))
Expand Down

0 comments on commit 304e940

Please sign in to comment.