<commit_before>type("PicList", ["WatchList"], {

    renderItem: function (item) {
        return item.draw();
    },

    addItem: function() {
        var addPic = new PicItem(this, 'edit');
        this.insert(addPic, '0');
    },

    deleteItem: function(item) {
        var self = this;
        var killProgress = IndicoUI.Dialogs.Util.progress();
        jsonRpc(Indico.Urls.JsonRpcService, 'event.pic.delete', {'picId': item.id, 'conference':self.confId},
                function(response, error){
                    if (exists(error)) {
                        killProgress();
                        IndicoUtil.errorReport(error);
                    }
                    else {
                        killProgress();
                        self.remove(item);
                    }
                });
    }

},

     function(picslist, web_container, uploadAction, confId) {
         this.WatchList();
         this.uploadAction = uploadAction;
         this.confId = confId
         var self = this;
         each(picslist, function(item){
             self.append(new PicItem(self, 'display', item));
         });
         $B($E(web_container), this, this.renderItem);
     }

    );


type("PicItem", ["IWidget"], {

    _iFrameLoaded : function(iframeId) {
        var doc;

        if (Browser.IE) {
            // *sigh*
            doc = document.frames[iframeId].document;
        } else {
            doc = $E(iframeId).dom.contentDocument;
        }

        var res = Json.read($('textarea', doc.body).val());

        if (res.status == "ERROR") {
            IndicoUtil.errorReport(res.info);
        } else {
            this.id = res.info.id;
            this.picURL = res.info.picURL;
            this.chooser.set('display');
        }
    },

    draw: function() {
        var self = this;

        this.chooser = new Chooser(new Lookup({
            edit: function() {
                var stuffUploadForm = function(inputField, uploadType, submitText) {
                    var killProgress;
                    var frameId = Html.generateId();
                    var form = Html.form({target: frameId, method: 'post', id: Html.generateId(),
                        action: self.parentList.uploadAction,
                        enctype: 'multipart/form-data'});

                    form.append(inputField);

                    form.append(Widget.button(
                        command(function(){
                            self.uploading = true;
                            killProgress = IndicoUI.Dialogs.Util.progress();
                            form.dom.submit();
                        }, submitText)
                    ));

                    var iframe = Html.iframe({id: frameId, name: frameId, style: {display: 'none'}});

                    var loadFunc = function() {
                        if (self.uploading) {
                            killProgress();
                            self.uploading = false;
                            // need to pass the ID, due to IE
                            self._iFrameLoaded(frameId);
                        }
                    };

                    if (Browser.IE) {
                        // cof! cof!
                        iframe.dom.onreadystatechange = loadFunc;
                    } else {
                        // for normal browsers
                        iframe.observeEvent("load", loadFunc);
                    }

                    return Html.div({}, [form, iframe]);
                };

                var fileUpload = stuffUploadForm(Html.input('file', {name: 'file'}), 'file', 'Upload');


                var closeArea = Html.div({},Widget.button(
                    command(function() {
                        self.parentList.remove(self);
                    },"Close")));

                return this.IWidget.prototype.draw.call(this, Html.div({},[fileUpload, closeArea]));
            },
            display: function() {
                var image = Html.img({
                    src: ""+self.picURL,
                    alt: 'Picture preview',
                    title: 'Picture preview',
                    style: {
                        width: "10%",
                        height: "10%",
                        border: "0px"
                    }
                });
                var linkToUse = Html.span({style:{color: 'green'}});<commit_msg>[REF] Use jQuery form plugin for iamge upload<commit_after>type("PicList", ["WatchList"], {

    renderItem: function (item) {
        return item.draw();
    },

    addItem: function() {
        var addPic = new PicItem(this, 'edit');
        this.insert(addPic, '0');
    },

    deleteItem: function(item) {
        var self = this;
        var killProgress = IndicoUI.Dialogs.Util.progress();
        jsonRpc(Indico.Urls.JsonRpcService, 'event.pic.delete', {'picId': item.id, 'conference':self.confId},
            function(response, error){
                if (exists(error)) {
                    killProgress();
                    IndicoUtil.errorReport(error);
                }
                else {
                    killProgress();
                    self.remove(item);
                }
            });
        }
    },

     function(picslist, web_container, uploadAction, confId) {
         this.WatchList();
         this.uploadAction = uploadAction;
         this.confId = confId
         var self = this;
         each(picslist, function(item){
             self.append(new PicItem(self, 'display', item));
         });
         $B($E(web_container), this, this.renderItem);
     }

    );


type("PicItem", ["IWidget"], {

    draw: function() {
        var self = this;

        this.chooser = new Chooser(new Lookup({
            edit: function() {
                var stuffUploadForm = function(inputField, uploadType, submitText) {
                    var killProgress;
                    var form = Html.form({method: 'post', id: Html.generateId(),
                        action: self.parentList.uploadAction,
                        enctype: 'multipart/form-data'});

                    form.append(inputField);

                    form.append(Widget.button(
                        command(function(){
                            killProgress = IndicoUI.Dialogs.Util.progress();
                            $(form.dom).submit();
                        }, submitText)
                    ));

                    $(form.dom).ajaxForm({
                        dataType: 'json',
                        iframe: true,
                        complete: function() {
                            killProgress();
                        },
                        success: function(resp) {
                            if (resp.status == 'ERROR') {
                                IndicoUtil.errorReport(resp.info);
                            }
                            else {
                                self.id = resp.info.id;
                                self.picURL = resp.info.picURL;
                                self.chooser.set('display');
                            }
                        }
                    });

                    return Html.div({}, [form]);
                };

                var fileUpload = stuffUploadForm(Html.input('file', {name: 'file'}), 'file', 'Upload');


                var closeArea = Html.div({},Widget.button(
                    command(function() {
                        self.parentList.remove(self);
                    },"Close")));

                return this.IWidget.prototype.draw.call(this, Html.div({},[fileUpload, closeArea]));
            },
            display: function() {
                var image = Html.img({
                    src: ""+self.picURL,
                    alt: 'Picture preview',
                    title: 'Picture preview',
                    style: {
                        maxWidth: "200px",
                        maxHeight: "100px",
                        border: "0px"
                    }
                });
                var linkToUse = Html.span({style:{color: 'green'}});
{'fraction_non_alphanumeric': 0.11939379004435682, 'fraction_numerical': 0.0017249876786594382, 'mean_word_length': 1.1226464435146444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6536785', 'n_tokens_mistral': 2115, 'n_tokens_neox': 1939, 'n_words': 378}