Wex5 of the attachmentsimple components of the nine diagram and single video upload

Source: Internet
Author: User

Define a CDATA temporary container that serves as a place for placing picture path information

Second, the Attachmentsimple component is located in the file Onloadmodel by JS limit the type and number of file upload

Model.prototype.modelLoad =function(event) {vardata = This. Comp ("Data1"); //limit only upload pictures and videos can be set on the Accept        varuploader = This. Comp ("AttachmentSimple2"). Uploader; /**//Set multiple attribute value in uploader, you can upload multiple pictures * $ (uploader.inputelement). attr (' multiple ', ' multiple '); */Uploader.on (' Onfileselected ',function(event) {varFile = Data.getvalue ("FileName"); varJsonlist = eval ("(" + file + ")"); //Debugger            if(Event.file.type = = "" | | Event.file.type.indexOf ("image/") = = 0) {type=Event.file.type; if(Jsonlist! = undefined && jsonlist.length >= 8) {                    if(Jsonlist.length = = 8) {Util.hint ("Uploading Pictures", {                            "Position": "Middle"                        }); $('. X-item-upload '). addclass (' x-upload-hide ');//Hide Upload}Else {                        $('. X-item-upload '). addclass (' x-upload-hide ');//Hide UploadUtil.hint ("Upload only 1 videos individually or upload 9 images separately!") ", {                            "Type": "Warning",                            "Position": "Middle"                        }); Event.cancel=true; }                } Else{util.hint ("Uploading Pictures", {                        "Position": "Middle"                    }); }            } Else if(Event.file.type = = "" | | Event.file.type.indexOf ("video/") = = 0) {type=Event.file.type; if(Jsonlist! = undefined && jsonlist.length >= 1) {Util.hint ("Upload only 1 videos individually or upload 9 images separately!" ", {                        "Type": "Warning",                        "Position": "Middle"                    }); Event.cancel=true; } Else{util.hint ("Uploading video ...", {                        "Position": "Middle"                    }); $('. X-item-upload '). addclass (' x-upload-hide ');//Hide Upload$ ('. X-item-remove '). addclass (' X-upload-hide '));    }            }        }); };

Third, click on the component minus sign to display the Upload plus button to control whether you can continue to upload the download (here has been controlled by the number, in order to more beautiful said dynamic hide display plus, minus button)

// Click the minus event    function (Event) {        $ ('. X-item-upload '). Removeclass (' x-upload-hide ');   unhide uploads    };

Four, save the image of the URL to the database, the picture of the physical file in the click of the plus sign, minus sign when the component has been uploaded to the default path of the server (can be modified by modifying the component source code)

//Save PictureModel.prototype.saveImage =function(self) {varMessageData = Self.comp ("MessageData"); varUserData = Self.comp ("UserData1"); vardata = Self.comp ("Data1"); varImageData = Self.comp ("ImageData"); varMessageId =Messagedata.getcurrentrowid (); varrow =Data.getcurrentrow (); varJsonlist = eval ("(" + row.val (' fileName ') + ")"); if(Jsonlist! =undefined) {            //1. Use Window.locaion.href to get the root path of the project            varCurwwwpath =Window.document.location.href; //2. Get the directory after the host address            varPathname=Window.document.location.pathname; varpos =curwwwpath.indexof (pathname); //3. Get the host address            varLocalhostpath = curwwwpath. substring (0, POS);  for(i = 0; i < jsonlist.length; i++) {Jsonlist[i].ownerid=Row.getid (); varownerID =Row.getid (); varRealfilename = jsonlist[i]["Realfilename"]; varStorefilename = jsonlist[i]["Storefilename"]; varOperatetype = "Preview";//Preview                varPreviewurl = Self.comp ("AttachmentSimple2"). Getfileurl (Realfilename, Storefilename, ownerID, Operatetype); varURL = Previewurl;//Picture Access Path                if(Type.indexof ("image/")! =-1) {//Upload as Picture                    if(Url! =NULL) {                        //gets the new message ID that is stored in the image tableImagedata.newdata (); Imagedata.setvalue ("MESSAGE_ID", messageId); Imagedata.setvalue ("Image_url", URL); //Real_url = "http://120.27.11.218:8095" +imageurl;                        varReal_url = Localhostpath+url;//Address bar preview path for stitching picturesConsole.log ("Picture preview path" +Real_url); Imagedata.setvaluebyid ("Real_url", Real_url);                    Imagedata.savedata (); }                }Else if(Type.indexof ("video/")! =-1) {//upload as VideoMessagedata.setvalue ("Video_url", URL); }            }        }        //Refresh data to prevent the next upload when the picture is still displayed in the interface        //Imagedata.refreshdata ();Data.refreshdata (); }

Wex5 of the attachmentsimple components of the nine diagram and single video upload

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.