Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elfinder.min.js : How to get the data in the response #5

Open
medinib opened this issue Apr 2, 2019 · 0 comments
Open

elfinder.min.js : How to get the data in the response #5

medinib opened this issue Apr 2, 2019 · 0 comments

Comments

@medinib
Copy link

medinib commented Apr 2, 2019

I created a new js function on the elfinder.min.js file :

elFinder.prototype.commands.importimage = function () {
        this.shortcuts = [{
            pattern: ""
        }], this.getstate = function (b) {
            var c = this.fm;
            return b = b || c.selected(), !this._disabled && b.length && a.map(b, function (a) {
                var b = c.file(a);
                return b && b.phash && !b.locked ? a : null
            }).length == b.length ? 0 : -1
        }, 
        this.exec = function (b) {
        	// Grise le bouton pour empecher les clics multiples
        	$('div[title="Insertion"]').addClass("ui-state-disabled");
            var c = this,
                d = this.fm,
                e = a.Deferred().fail(function (a) {
                    a && d.error(a)
                }),
                f = this.files(b),
                g = f.length,
                h = d.cwd().hash,
                i = !1,
                j = f[0].name;
            return this._disabled ? e.reject() : (a.each(f, function (a, b) {
                if (!b.phash) return !e.reject(["errImportJpeg", b.name, "errPerm"]);
                if (b.locked) return !e.reject(["errLocked", b.name]);
                b.hash == h && (i = d.root(b.hash))
            }), e.isRejected() || (f = this.hashes(b), d.confirm({
            	title: d.i18n(c.title),
                text: d.i18n(["confirmInsert", j, "confirm"]),
                accept: {
                    label: "btnYes",
                    callback: function () {
                        d.lockfiles({
                            files: f
                        }), d.request({
                            data: {
                                cmd: "importimage ",
                                targets: f,
                                current: h
                            },
                            notify: {
                                type: "mkfile",
                                cnt: g
                            },
                            preventFail: !0
                        }).fail(function (a) {
                        	if(a == "ERREUR_CONCURRENCE") {
                        		alert("error");
                            	window.location.href = document.getElementById('navAccueil').href;
                        	} else {
                        		e.reject(a);
                        	}
                        }).done(function (a) {
                        	alert(a);
                        	elFinderDone(a, 'importimage ');
                        }).always(function () {
                            d.unlockfiles({
                                files: f
                            })
                        })
                    }
                },
                cancel: {
                    label: "btnNo",
                    callback: function () {
                        e.reject()
                    }
                }
            })), e)
        }
    }

I need to get the data in the response to display them in a popup. The following code :

.done(function (a) {
                        	alert(a);
                        	elFinderDone(a, 'importimage ');
                        })

returns the following error " Syntax Error: Invalid character" when parsing the "a" argument of "elFinderDone(a, 'importimage ');" :
var obj = JSON.parse(a);

So my question is : how to get the json data correctly ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant