| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- if(!dojo._hasResource["dojox.form.Uploader"]){
- dojo._hasResource["dojox.form.Uploader"] = true;
- dojo.provide("dojox.form.Uploader");
- dojo.experimental("dojox.form.Uploader");
- dojo.require("dojox.form.uploader.Base");
- dojo.require("dijit.form.Button");
-
-
-
-
-
-
-
-
-
-
- dojo.declare("dojox.form.Uploader", [dojox.form.uploader.Base], {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- uploadOnSelect:false,
-
-
- tabIndex:0,
-
-
- multiple:false,
-
-
-
- label:"Upload...",
-
-
-
-
- url:"",
-
-
-
-
-
- name:"uploadedfile",
-
-
-
-
- flashFieldName:"",
-
-
-
-
-
- uploadType:"form",
-
- _nameIndex:0,
- widgetsInTemplate:true,
- templateString:'<div class="dojoxFileInput"><div dojoType="dijit.form.Button" dojoAttachPoint="button">${label}</div></div>',
- postMixInProperties: function(){
- this._inputs = [];
- this._getButtonStyle(this.srcNodeRef);
- this.inherited(arguments);
- },
- postCreate: function(){
- var restore = false;
- var parent = this.domNode.parentNode;
- var position = this._getNodePosition(this.domNode);
- if(!this.btnSize.w || !this.btnSize.h) {
- dojo.body().appendChild(this.domNode);
- this._getButtonStyle(this.domNode);
- restore = true;
- }
- this._setButtonStyle();
- if(restore){
- dojo.place(this.domNode, position.node, position.pos)
- }
- this.inherited(arguments);
- },
-
- onChange: function(/* Array */fileArray){
-
-
-
-
- },
- onBegin: function(/* Array */dataArray){
-
-
- },
- onProgress: function(/* Object */customEvent){
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
- onComplete: function(/* Object */customEvent){
-
-
-
-
- this.reset();
- },
- onCancel: function(){
-
-
-
-
- },
- onAbort: function(){
-
-
-
- },
- onError: function(/* Object or String */evtObject){
-
-
-
-
- },
-
- upload: function(/*Object ? */formData){
-
-
- },
- submit: function(/* form Node ? */form){
-
-
-
- },
- reset: function(){
-
-
-
-
-
-
-
-
- this._disconnectButton();
- dojo.forEach(this._inputs, dojo.destroy, dojo);
- this._inputs = [];
- this._nameIndex = 0;
- this._createInput();
- },
- getFileList: function(){
-
-
-
- var fileArray = [];
- if(this.supports("multiple")){
- dojo.forEach(this.inputNode.files, function(f, i){
- fileArray.push({
- index:i,
- name:f.name,
- size:f.size,
- type:f.type
- });
- }, this);
- }else{
- dojo.forEach(this._inputs, function(n, i){
- fileArray.push({
- index:i,
- name:n.value.substring(n.value.lastIndexOf("\\")+1),
- size:0,
- type:n.value.substring(n.value.lastIndexOf(".")+1)
- });
- }, this)
- }
- return fileArray;
- },
-
- _getValueAttr: function(){
-
-
- return this.getFileList();
- },
- _setValueAttr: function(disabled){
- console.error("Uploader value is read only");
- },
- _getDisabledAttr: function(){
-
-
- return this._disabled;
- },
- _setDisabledAttr: function(disabled){
-
-
- if(this._disabled == disabled){ return; }
- this.button.set('disabled', disabled);
- dojo.style(this.inputNode, "display", disabled ? "none" : "block");
- },
- _getNodePosition: function(node){
- if(node.previousSibling){
- return {
- node:node.previousSibling,
- pos:"after"
- }
- }
- return {
- node:node.nextSibling,
- pos:"before"
- }
- },
- _getButtonStyle: function(node){
- if(!node){
-
- this.btnSize = {
- w:200,
- h:25
- };
- }else{
- this.btnSize = dojo.marginBox(node);
- }
- },
- _setButtonStyle: function(){
- var hasParent = true;
- if(!this.domNode.parentNode || !this.domNode.parentNode.tagName){
- document.body.appendChild(this.domNode);
- hasParent = false;
- }
- dojo.style(this.domNode, {
- width:this.btnSize.w+"px",
- height:(this.btnSize.h+4)+"px",
- overflow:"hidden",
- position:"relative"
- });
- this.inputNodeFontSize = Math.max(2, Math.max(Math.ceil(this.btnSize.w / 60), Math.ceil(this.btnSize.h / 15)));
- this._createInput();
- dojo.style(this.button.domNode, {
- margin:"0px",
- display:"block",
- verticalAlign:"top"
- });
- dojo.style(this.button.domNode.firstChild, {
- margin:"0px",
- display:"block"
-
- });
- if(!hasParent){
- document.body.removeChild(this.domNode);
- }
- },
- _createInput: function(){
- if(this._inputs.length){
- dojo.style(this.inputNode, {
- top:"500px"
- });
- this._disconnectButton();
- this._nameIndex++;
- }
- var name;
- if(this.supports("multiple")){
-
- name = this.name+"s[]";
- }else{
-
- name = this.name + (this.multiple ? this._nameIndex : "");
- }
- this.inputNode = dojo.create("input", {type:"file", name:name, className:"dojoxInputNode"}, this.domNode, "first");
- if(this.supports("multiple") && this.multiple){
- dojo.attr(this.inputNode, "multiple", true);
- }
- this._inputs.push(this.inputNode);
- dojo.style(this.inputNode, {
- fontSize:this.inputNodeFontSize+"em"
- });
- var size = dojo.marginBox(this.inputNode);
- dojo.style(this.inputNode, {
- position:"absolute",
- top:"-2px",
- left:"-"+(size.w-this.btnSize.w-2)+"px",
- opacity:0
- });
- this._connectButton();
- },
- _connectButton: function(){
- this._cons = [];
- var cs = dojo.hitch(this, function(nm){
- this._cons.push(dojo.connect(this.inputNode, nm, this, function(evt){
- this.button._cssMouseEvent({type:nm})
- }));
- });
- cs("mouseover");
- cs("mouseout");
- cs("mousedown");
- this._cons.push(dojo.connect(this.inputNode, "change", this, function(evt){
- this.onChange(this.getFileList(evt));
- if(!this.supports("multiple") && this.multiple) this._createInput();
- }));
- this.button.set('tabIndex', -1);
- if(this.tabIndex > -1){
- this.inputNode.tabIndex = this.tabIndex;
- var restoreBorderStyle = dojo.style(this.button.domNode.firstChild, "border");
- this._cons.push(dojo.connect(this.inputNode, "focus", this, function(){
- dojo.style(this.button.domNode.firstChild, "border", "1px dashed #ccc");
- }));
- this._cons.push(dojo.connect(this.inputNode, "blur", this, function(){
- dojo.style(this.button.domNode.firstChild, "border", restoreBorderStyle);
- }));
- }
- },
- _disconnectButton: function(){
- dojo.forEach(this._cons, dojo.disconnect, dojo);
- }
- });
- (function(){
- dojox.form.UploaderOrg = dojox.form.Uploader;
- var extensions = [dojox.form.UploaderOrg];
- dojox.form.addUploaderPlugin = function(plug){
-
-
-
-
- extensions.push(plug);
- dojo.declare("dojox.form.Uploader", extensions, {});
- }
- })();
- }
|