AttachmentController.js 92.0 KB
Newer Older
NoSubject's avatar
NoSubject 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
o2.widget = o2.widget || {};
o2.widget.AttachmentController = o2.widget.ATTER  = new Class({
    Extends: o2.widget.Common,
	Implements: [Options, Events],
	options: {
		"style": "default",
        "listStyle": "icon",
        "size": "max",
        "resize": true,
        "attachmentCount": 0,
        "isUpload": true,
        "isDelete": true,
        "isReplace": true,
        "isDownload": true,
        "isSizeChange": true,
        "readonly": false,
NoSubject's avatar
NoSubject 已提交
17
        "availableListStyles" : ["list","seq","icon","preview"],
R
roo00 已提交
18
        "toolbarGroupHidden" : [], //edit read list view
NoSubject's avatar
NoSubject 已提交
19 20
        "images": ["bmp", "gif", "png", "jpeg", "jpg", "jpe", "ico"],
        "audios": ["mp3", "wav", "wma", "wmv"],
R
roo00 已提交
21 22
        "videos": ["avi", "mkv", "mov", "ogg", "mp4", "mpa", "mpe", "mpeg", "mpg", "rmvb"],
        "actionShowText" : false
NoSubject's avatar
NoSubject 已提交
23 24 25 26 27 28 29 30 31
	},
	initialize: function(container, module, options){
		this.setOptions(options);
		this.pages = [];

		this.path = o2.session.path+"/widget/$AttachmentController/";
		this.cssPath = o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/css.wcss";
		this._loadCss();

32
        var iconUrl = this.options.iconConfigUrl ? this.options.iconConfigUrl : "../x_component_File/$Main/icon.json";
R
roo00 已提交
33
        o2.getJSON(iconUrl, function(json){
NoSubject's avatar
NoSubject 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
            this.icons = json;
        }.bind(this), false, false);

        this.module = module;

        this.actions = [];
        this.attachments = [];
        this.selectedAttachments = [];
		this.container = $(container);
	},
    load: function(){
        // if (!layout.mobile){
            if (this.options.size==="min"){
                this.loadMin();
            }else{
                this.loadMax();
            }
        // }else{
        //     this.loadMobile();
        // }
R
roo00 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    },
    reloadAttachments: function(){
        if (this.options.size==="min"){
            this.minContent.empty();
            var atts = this.attachments;
            this.attachments = [];
            while (atts.length){
                var att = atts.shift();
                this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(att.data, this));
            }
        }else{
            this.content.empty();
            var atts = this.attachments;
            this.attachments = [];
            while (atts.length){
                var att = atts.shift();
                this.attachments.push(new o2.widget.AttachmentController.Attachment(att.data, this));
            }
        }
        this.checkActions();
NoSubject's avatar
NoSubject 已提交
74 75 76 77
    },
	loadMax: function(){
        if (!this.node) this.node = new Element("div", {"styles": this.css.container});

R
roo00 已提交
78 79 80 81
        this.createTopNode();

        if (!this.contentScrollNode){
            //this.createTopNode();
NoSubject's avatar
NoSubject 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
            this.createContentNode();


            if (this.options.resize){
                this.createBottomNode();
                this.createResizeNode();
            }

            this.node.inject(this.container);

            //if (this.options.readonly) this.setReadonly();
            this.checkActions();

            this.setEvent();
        }else{
            this.contentScrollNode.setStyle("display", "block");
            if (this.bottomNode) this.bottomNode.setStyle("display", "block");
            if (this.titleNode) this.titleNode.setStyle("display", "block");
R
roo00 已提交
100
            //this.topNode.setStyle("display", "block");
NoSubject's avatar
NoSubject 已提交
101 102 103 104 105 106 107 108
            this.content.empty();
        }
        var atts = this.attachments;
        this.attachments = [];
        while (atts.length){
            var att = atts.shift();
            this.attachments.push(new o2.widget.AttachmentController.Attachment(att.data, this));
        }
NoSubject's avatar
NoSubject 已提交
109
        this.checkActions();
NoSubject's avatar
NoSubject 已提交
110 111 112
        //this.attachments = atts;
	},
    loadMin: function(){
R
roo00 已提交
113

NoSubject's avatar
NoSubject 已提交
114 115 116
        if (!this.node) this.node = new Element("div", {"styles": this.css.container_min});

        if (!this.minActionAreaNode){
NoSubject's avatar
NoSubject 已提交
117
            this.minActionAreaNode = new Element("div", {"styles": this.css.minActionAreaNode }).inject(this.node);
R
roo00 已提交
118
            //this.minContent = new Element("div", {"styles": this.css.minContentNode}).inject(this.node);
NoSubject's avatar
NoSubject 已提交
119 120 121 122 123 124

            this.loadMinActions();

            this.node.inject(this.container);

            //if (this.options.readonly) this.setReadonly();
R
roo00 已提交
125 126 127 128 129 130 131 132 133 134 135 136
            //this.checkActions();

            this.setEvent();
        }else{
            this.minActionAreaNode.setStyle("display", "");
            //this.minContent.setStyle("display", "block");
            //this.minContent.empty();
            this.minActionAreaNode.empty();

            this.loadMinActions();

            //this.checkActions();
NoSubject's avatar
NoSubject 已提交
137 138

            this.setEvent();
R
roo00 已提交
139 140 141 142 143 144 145
        }
        var hiddenGroup = this.options.toolbarGroupHidden;
        var flag = hiddenGroup.contains("edit") && hiddenGroup.contains("read")  && hiddenGroup.contains("view");

        if( flag )this.minActionAreaNode.setStyle("display","none");

        if( !this.minContent ){
NoSubject's avatar
NoSubject 已提交
146 147 148 149 150 151 152

            this.minContent = new Element("div", {"styles":
                layout.mobile ? this.css.minContentNode_mobile : this.css.minContentNode
            }).inject(this.node);
            if( layout.mobile ){
                this.minContent.setStyle("clear","both");
            }
NoSubject's avatar
NoSubject 已提交
153 154 155 156
        }else{
            this.minContent.setStyle("display", "block");
            this.minContent.empty();
        }
R
roo00 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

        //if (!hiddenGroup.contains("edit")){
        //        this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", o2.LP.widget.upload, function (e, node) {
        //            this.uploadAttachment(e, node);
        //        }.bind(this));
        //
        //        this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", o2.LP.widget["delete"], function (e, node) {
        //            this.deleteAttachment(e, node);
        //        }.bind(this));
        //
        //        this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", o2.LP.widget.replace, function (e, node) {
        //            this.replaceAttachment(e, node);
        //        }.bind(this));
        //    }
        //
        //    if (!hiddenGroup.contains("read")){
        //        this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", o2.LP.widget.download, function (e, node) {
        //            this.downloadAttachment(e, node);
        //        }.bind(this));
        //    }
        //
        //    if( !hiddenGroup.contains("edit") || !hiddenGroup.contains("read") ) {
        //        this.createSeparate(this.minActionAreaNode);
        //    }
        //
        //    if( !hiddenGroup.contains("view")){
        //        this.sizeAction = this.createAction(this.minActionAreaNode, "max", o2.LP.widget.min, function(){
        //            this.changeControllerSize();
        //        }.bind(this));
        //    }
        //
        //    this.node.inject(this.container);

NoSubject's avatar
NoSubject 已提交
190
        var atts = this.attachments;
NoSubject's avatar
NoSubject 已提交
191
        this.attachments = [];
NoSubject's avatar
NoSubject 已提交
192 193 194 195
        while (atts.length){
            var att = atts.shift();
            this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(att.data, this));
        }
NoSubject's avatar
NoSubject 已提交
196
        this.checkActions();
NoSubject's avatar
NoSubject 已提交
197 198 199 200 201 202 203 204
        //this.attachments = atts;
    },
    loadMobile: function(){

    },


    loadMinActions: function(){
R
roo00 已提交
205 206 207 208 209
        var hiddenGroup = this.options.toolbarGroupHidden;
        if (!hiddenGroup.contains("edit")) {
            this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", o2.LP.widget.upload, function (e, node) {
                this.uploadAttachment(e, node);
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
210

R
roo00 已提交
211 212 213
            this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", o2.LP.widget["delete"], function (e, node) {
                this.deleteAttachment(e, node);
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
214

R
roo00 已提交
215 216 217 218 219
            if( !this.options.isReplaceHidden ){
                this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", o2.LP.widget.replace, function (e, node) {
                    this.replaceAttachment(e, node);
                }.bind(this));
            }
R
roo00 已提交
220 221 222 223 224 225
        }
        if (!hiddenGroup.contains("read")) {
            this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", o2.LP.widget.download, function (e, node) {
                this.downloadAttachment(e, node);
            }.bind(this));
        }
NoSubject's avatar
NoSubject 已提交
226

R
roo00 已提交
227
        if( !hiddenGroup.contains("edit") || !hiddenGroup.contains("read") ) {
NoSubject's avatar
NoSubject 已提交
228
            this.createSeparate(this.minActionAreaNode);
R
roo00 已提交
229
        }
NoSubject's avatar
NoSubject 已提交
230

R
roo00 已提交
231 232 233 234 235 236 237
        if (this.options.isSizeChange){
            //this.createSeparate(this.minActionAreaNode);
            if( !hiddenGroup.contains("view")) {
                this.sizeAction = this.createAction(this.minActionAreaNode, "max", o2.LP.widget.min, function () {
                    this.changeControllerSize();
                }.bind(this));
            }
NoSubject's avatar
NoSubject 已提交
238
        }
NoSubject's avatar
NoSubject 已提交
239 240 241 242 243 244 245 246 247 248
    },

    setEvent: function(){
        if (this.contentScrollNode) this.contentScrollNode.addEvents({
            "mousedown": this.unSelectedAttachments.bind(this)
        });
        if (this.minContent) this.minContent.addEvents({
            "mousedown": this.unSelectedAttachments.bind(this)
        });
    },
R
roo00 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
    resetToolbarGroupHidden : function( hiddenGroup ){
        this.options.toolbarGroupHidden = hiddenGroup;
        if( this.options.size == "max" ){
            this.reloadTopNode();
        }else{
            this.loadMin();
        }
    },
    resetToolbarAvailableListStyle : function( availableListStyle ){
        this.options.availableListStyles = availableListStyle;
        if( this.options.size == "max" ){
            this.reloadTopNode();
        }else{
            this.loadMin();
        }
    },
NoSubject's avatar
NoSubject 已提交
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
    createContentNode: function(){
        this.contentScrollNode = new Element("div.contentScrollNode", {"styles": this.css.contentScrollNode}).inject(this.node);
        this.content = new Element("div.content", {"styles": this.css.contentNode}).inject(this.contentScrollNode);

        o2.require("o2.widget.ScrollBar", function(){
            new o2.widget.ScrollBar(this.contentScrollNode, {
                "style":"attachment", "where": "before", "distance": 30, "friction": 4,	"axis": {"x": false, "y": true}
            });
        }.bind(this));
    },
    createBottomNode: function(){
        this.bottomNode = new Element("div", {"styles": this.css.bottomNode}).inject(this.node);
    },
    createResizeNode: function(){
        this.resizeNode = new Element("div", {"styles": this.css.resizeNode}).inject(this.bottomNode);
        this.resizeDrag = new Drag(this.resizeNode, {
            "snap": "2",
            "onStart": function(el, e){
                el.store("startY", e.event.y);
                el.store("nodeHeight", this.node.getSize().y);

R
roo00 已提交
286 287 288 289 290 291
                var minHeight = this.node.getStyle("min-height");
                el.store("nodeMinHeight", minHeight ? minHeight.toFloat() : "");

                var contentScrollNodeMinHeight = this.contentScrollNode.getStyle("min-height");
                el.store("contentScrollNodeMinHeight", contentScrollNodeMinHeight ? contentScrollNodeMinHeight.toFloat() : "");

NoSubject's avatar
NoSubject 已提交
292
                if (!this.nodeHeight){
R
roo00 已提交
293
                    this.nodeHeight = minHeight.toFloat();
NoSubject's avatar
NoSubject 已提交
294 295 296 297 298
                }
            }.bind(this),
            "onDrag": function(el, e){
                var y = el.retrieve("startY");
                var nodeHeight = el.retrieve("nodeHeight");
R
roo00 已提交
299 300
                var nodeMinHeight = el.retrieve("nodeMinHeight");
                var contentScrollNodeMinHeight = el.retrieve("contentScrollNodeMinHeight");
NoSubject's avatar
NoSubject 已提交
301 302

                var setY = (e.event.y-y)+nodeHeight;
R
roo00 已提交
303 304 305

                if( nodeMinHeight && setY < nodeMinHeight && e.event.y<y)return;

NoSubject's avatar
NoSubject 已提交
306 307
                if (setY<this.nodeHeight) setY = this.nodeHeight;

R
roo00 已提交
308 309 310
                var setContentY = setY-81;

                if( contentScrollNodeMinHeight && setContentY < contentScrollNodeMinHeight && e.event.y<y )return;
NoSubject's avatar
NoSubject 已提交
311 312 313 314 315 316 317 318 319 320 321

                this.node.setStyle("height", ""+setY+"px");
                this.contentScrollNode.setStyle("height", ""+setContentY+"px");
            }.bind(this)
        });
    },

    createTopNode: function(){
        if (this.options.title){
            if (!this.titleNode) this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.options.title}).inject(this.node);
        }
R
roo00 已提交
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357

        if( !this.topNode ){
            this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
        }else{
            this.topNode.empty();
            this.editActionBoxNode = null;
            this.editActionsGroupNode=null;
            this.topNode.setStyle("display","");
            if( this.isHiddenTop ){
                if( this.oldContentScrollNodeHeight && this.contentScrollNode ){
                    this.contentScrollNode.setStyle("min-height",this.oldContentScrollNodeHeight);
                    this.oldContentScrollNodeHeight = null;
                }
                this.isHiddenTop = false;
            }
        }
        var hiddenGroup = this.options.toolbarGroupHidden;
        if( hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("list") && hiddenGroup.contains("view")){
            if(this.contentScrollNode){
                this.oldContentScrollNodeHeight = this.contentScrollNode.getStyle("min-height");
                this.contentScrollNode.setStyle("min-height",this.node.getStyle("min-height"));
                this.topNode.setStyle("display","none");
            }
            this.isHiddenTop = true;
            return;
        }
        if( !hiddenGroup.contains("edit") )this.createEditGroupActions();
        if( !hiddenGroup.contains("read") )this.createReadGroupActions();
        if( !hiddenGroup.contains("list") )this.createListGroupActions();
        if( !hiddenGroup.contains("view") )this.createViewGroupActions();

        //this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
        //this.createEditGroupActions();
        //this.createReadGroupActions();
        //this.createListGroupActions();
        //this.createViewGroupActions();
NoSubject's avatar
NoSubject 已提交
358 359

        //this.createConfigGroupActions();
NoSubject's avatar
NoSubject 已提交
360
    },
R
roo00 已提交
361 362 363
    reloadTopNode : function(){
        this.createTopNode();
    },
NoSubject's avatar
NoSubject 已提交
364
    createEditGroupActions: function(){
R
roo00 已提交
365 366
        if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
        if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
NoSubject's avatar
NoSubject 已提交
367 368 369 370 371 372 373 374
        this.uploadAction = this.createAction(this.editActionsGroupNode, "upload", o2.LP.widget.upload, function(e, node){
            this.uploadAttachment(e, node);
        }.bind(this));

        this.deleteAction = this.createAction(this.editActionsGroupNode, "delete", o2.LP.widget["delete"], function(e, node){
            this.deleteAttachment(e, node);
        }.bind(this));

R
roo00 已提交
375 376 377 378 379
        if( !this.options.isReplaceHidden ){
            this.replaceAction = this.createAction(this.editActionsGroupNode, "replace", o2.LP.widget.replace, function(e, node){
                this.replaceAttachment(e, node);
            }.bind(this));
        }
NoSubject's avatar
NoSubject 已提交
380 381 382 383 384

        // this.officeAction = this.createAction(this.editActionsGroupNode, "office", o2.LP.widget.office, function(e, node){
        //     this.openInOfficeControl(e, node);
        // }.bind(this));

R
roo00 已提交
385
        if( !this.options.toolbarGroupHidden.contains("read") )this.editActionSeparateNode = this.createSeparate(this.editActionsGroupNode);
NoSubject's avatar
NoSubject 已提交
386 387 388 389 390
    },

    createReadGroupActions: function(){
        //this.readActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
        //this.readActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.readActionBoxNode);
R
roo00 已提交
391 392
        if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
        if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
NoSubject's avatar
NoSubject 已提交
393 394 395 396 397 398 399 400 401 402 403 404 405 406
        this.downloadAction = this.createAction(this.editActionsGroupNode, "download", o2.LP.widget.download, function(){
            this.downloadAttachment();
        }.bind(this));

        //this.createAction(this.readActionsGroupNode, "share", o2.LP.widget.share, function(){
        //    this.transAttachment();
        //}.bind(this));

        //this.downloadAllAction = this.createAction(this.editActionsGroupNode, "downloadAll", o2.LP.widget.downloadAll, function(){
        //    this.downloadAllAttachment();
        //}.bind(this));

    },
    createListGroupActions: function(){
NoSubject's avatar
NoSubject 已提交
407 408 409 410 411 412 413 414 415 416
        var availableListStyles = this.options.availableListStyles;
        if( availableListStyles && availableListStyles.length > 0 ){
            this.listActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
            this.listActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.listActionBoxNode);

            if( availableListStyles.contains("list") ){
                this.listAction = this.createAction(this.listActionsGroupNode, "list", o2.LP.widget.list, function(){
                    this.changeListStyle("list");
                }.bind(this));
            }
NoSubject's avatar
NoSubject 已提交
417

NoSubject's avatar
NoSubject 已提交
418 419 420 421 422
            if( availableListStyles.contains("seq") ) {
                this.sequenceAction = this.createAction(this.listActionsGroupNode, "seq", o2.LP.widget.sequence, function () {
                    this.changeListStyle("sequence");
                }.bind(this));
            }
NoSubject's avatar
NoSubject 已提交
423

NoSubject's avatar
NoSubject 已提交
424 425 426 427 428
            if( availableListStyles.contains("icon") ) {
                this.iconAction = this.createAction(this.listActionsGroupNode, "icon", o2.LP.widget.icon, function () {
                    this.changeListStyle("icon");
                }.bind(this));
            }
NoSubject's avatar
NoSubject 已提交
429

NoSubject's avatar
NoSubject 已提交
430 431 432 433 434 435
            if( availableListStyles.contains("preview") ) {
                this.previewAction = this.createAction(this.listActionsGroupNode, "preview", o2.LP.widget.preview, function () {
                    this.changeListStyle("preview");
                }.bind(this));
            }
        }
NoSubject's avatar
NoSubject 已提交
436 437 438 439

    },

    createViewGroupActions: function(){
NoSubject's avatar
NoSubject 已提交
440 441 442 443 444 445 446 447
        if (this.options.isSizeChange){
            this.viewActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
            this.viewActionBoxNode.setStyles({"float": "right", "margin-right": "7px"});
            this.viewActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.viewActionBoxNode);
            this.sizeAction = this.createAction(this.viewActionsGroupNode, "min", o2.LP.widget.min, function(){
                this.changeControllerSize();
            }.bind(this));
        }
NoSubject's avatar
NoSubject 已提交
448 449 450 451 452
    },



    createSeparate: function(groupNode){
NoSubject's avatar
NoSubject 已提交
453
        var separateNode = new Element("div.separateNode", {"styles": this.css.separateNode}).inject(groupNode);
NoSubject's avatar
NoSubject 已提交
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
        return separateNode;
    },
    createAction: function(groupNode, img, title, click){
        var actionNode = new Element("div", {"styles": this.css.actionNode, "title": title}).inject(groupNode);
        var actionIconNode = new Element("div", {"styles": this.css.actionIconNode}).inject(actionNode);
        actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/icon/"+img+".png)");

        var _self = this;
        actionNode.addEvents({
            "mouseover": function(){
                if (!this.retrieve("disabled")) if (!this.retrieve("selected")) this.setStyle("background", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.options.style+"/overbg.png)");
            },
            "mouseout": function(){
                if (!this.retrieve("disabled")) if (!this.retrieve("selected")) this.setStyle("background", "transparent");
            },
            "click": function(e){
                if (!this.retrieve("disabled")) _self.doAction(e, this, click);
            }
        });
        this.actions.push(actionNode);
        return actionNode;
    },
    checkActions: function(){
    //    if (this.options.readonly){
    //        this.setReadonly();
    //    }else{
            this.checkUploadAction();
            this.checkDeleteAction();
R
roo00 已提交
482

NoSubject's avatar
NoSubject 已提交
483
            this.checkReplaceAction();
R
roo00 已提交
484

NoSubject's avatar
NoSubject 已提交
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
            //this.checkOfficeAction();
            this.checkDownloadAction();
            this.checkSizeAction();

            this.checkListStyleAction();
    //    }
    },
    checkUploadAction: function(){
        if (this.options.readonly){
            this.setActionDisabled(this.uploadAction);
            this.setActionDisabled(this.min_uploadAction);
            return false;
        }
        if (!this.options.isUpload){
            this.setActionDisabled(this.uploadAction);
            this.setActionDisabled(this.min_uploadAction);
        }else{
            if (this.options.attachmentCount!=0){
                if (this.attachments.length>=this.options.attachmentCount){
                    this.setActionDisabled(this.uploadAction);
                    this.setActionDisabled(this.min_uploadAction);
                }else{
                    this.setActionEnabled(this.uploadAction);
                    this.setActionEnabled(this.min_uploadAction);
                }
            }else{
                this.setActionEnabled(this.uploadAction);
                this.setActionEnabled(this.min_uploadAction);
            }
        }
    },
    checkDeleteAction: function(){
        if (this.options.readonly){
            this.setActionDisabled(this.deleteAction);
            this.setActionDisabled(this.min_deleteAction);
NoSubject's avatar
NoSubject 已提交
520
            this.setAttachmentsAction("delete", false );
NoSubject's avatar
NoSubject 已提交
521 522 523 524 525
            return false;
        }
        if (!this.options.isDelete){
            this.setActionDisabled(this.deleteAction);
            this.setActionDisabled(this.min_deleteAction);
NoSubject's avatar
NoSubject 已提交
526
            this.setAttachmentsAction("delete", false );
NoSubject's avatar
NoSubject 已提交
527 528 529 530 531 532 533 534
        }else{
            if (this.selectedAttachments.length){
                this.setActionEnabled(this.deleteAction);
                this.setActionEnabled(this.min_deleteAction);
            }else{
                this.setActionDisabled(this.deleteAction);
                this.setActionDisabled(this.min_deleteAction);
            }
NoSubject's avatar
NoSubject 已提交
535
            this.setAttachmentsAction("delete", true );
NoSubject's avatar
NoSubject 已提交
536 537
        }
    },
R
roo00 已提交
538 539 540 541 542
    isAttDeleteAvailable : function( att ){
        if (this.options.readonly)return false;
        if( this.options.toolbarGroupHidden.contains("edit") )return false;
        return this.options.isDelete;
    },
NoSubject's avatar
NoSubject 已提交
543 544 545 546 547
    // checkOfficeAction: function(){
    //     if (this.officeAction) this.officeAction.setStyle("display", "none");
    //     if (this.min_officeAction) this.min_officeAction.setStyle("display", "none");
    // },
    checkReplaceAction: function(){
R
roo00 已提交
548
        if( this.options.isReplaceHidden )return;
NoSubject's avatar
NoSubject 已提交
549 550 551
        if (this.options.readonly){
            this.setActionDisabled(this.replaceAction);
            this.setActionDisabled(this.min_replaceAction);
NoSubject's avatar
NoSubject 已提交
552
            this.setAttachmentsAction("replace", false );
NoSubject's avatar
NoSubject 已提交
553 554 555 556 557
            return false;
        }
        if (!this.options.isReplace){
            this.setActionDisabled(this.replaceAction);
            this.setActionDisabled(this.min_replaceAction);
NoSubject's avatar
NoSubject 已提交
558
            this.setAttachmentsAction("replace", false );
NoSubject's avatar
NoSubject 已提交
559 560 561 562 563 564 565 566
        }else{
            if (this.selectedAttachments.length && this.selectedAttachments.length==1){
                this.setActionEnabled(this.replaceAction);
                this.setActionEnabled(this.min_replaceAction);
            }else{
                this.setActionDisabled(this.replaceAction);
                this.setActionDisabled(this.min_replaceAction);
            }
NoSubject's avatar
NoSubject 已提交
567
            this.setAttachmentsAction("replace", true );
NoSubject's avatar
NoSubject 已提交
568 569
        }
    },
R
roo00 已提交
570 571 572 573 574
    isAttReplaceAvailable : function( att ){
        if (this.options.readonly)return false;
        if( this.options.toolbarGroupHidden.contains("edit") )return false;
        return this.options.isReplace;
    },
NoSubject's avatar
NoSubject 已提交
575 576 577 578
    checkDownloadAction: function(){
        if (!this.options.isDownload){
            this.setActionDisabled(this.downloadAction);
            this.setActionDisabled(this.downloadAllAction);
NoSubject's avatar
NoSubject 已提交
579
            this.setAttachmentsAction("download", false );
NoSubject's avatar
NoSubject 已提交
580 581 582 583 584 585 586
        }else{
            if (this.selectedAttachments.length){
                this.setActionEnabled(this.downloadAction);
            }else{
                this.setActionDisabled(this.downloadAction);
            }
            this.setActionEnabled(this.downloadAllAction);
NoSubject's avatar
NoSubject 已提交
587
            this.setAttachmentsAction("download", true );
NoSubject's avatar
NoSubject 已提交
588 589
        }
    },
R
roo00 已提交
590 591 592 593
    isAttDownloadAvailable : function( att ){
        if( this.options.toolbarGroupHidden.contains("read") )return false;
        return this.options.isDownload;
    },
NoSubject's avatar
NoSubject 已提交
594
    checkSizeAction: function(){
NoSubject's avatar
NoSubject 已提交
595 596 597 598 599 600
        if( this.sizeAction ){
            if (this.options.isSizeChange){
                this.setActionEnabled(this.sizeAction);
            }else{
                this.setActionDisabled(this.sizeAction);
            }
NoSubject's avatar
NoSubject 已提交
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
        }
    },
    checkListStyleAction: function(){
        switch (this.options.listStyle){
            case "list":
                this.setActionSelcted(this.listAction);
                this.setActionUnSelcted(this.iconAction);
                this.setActionUnSelcted(this.previewAction);
                this.setActionUnSelcted(this.sequenceAction);
                break;
            case "icon":
                this.setActionUnSelcted(this.listAction);
                this.setActionSelcted(this.iconAction);
                this.setActionUnSelcted(this.previewAction);
                this.setActionUnSelcted(this.sequenceAction);
                break;
            case "preview":
                this.setActionUnSelcted(this.listAction);
                this.setActionUnSelcted(this.iconAction);
                this.setActionSelcted(this.previewAction);
                this.setActionUnSelcted(this.sequenceAction);
                break;
            case "sequence":
                this.setActionUnSelcted(this.listAction);
                this.setActionUnSelcted(this.iconAction);
                this.setActionUnSelcted(this.previewAction);
                this.setActionSelcted(this.sequenceAction);
                break;
        }
    },
    setActionSelcted: function(action){
        if (action){
            if (!action.retrieve("selected")){
                action.setStyle("background", "url("+o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/selectedbg.png)");
                action.store("selected", true);
            }
        }

    },
    setActionUnSelcted: function(action){
        if (action){
            if (action.retrieve("selected")){
                action.setStyle("background", "");
                action.store("selected", false);
            }
        }
    },

    setActionEnabled: function(action){
        if (action){
            if (action.retrieve("disabled")){
                var iconNode = action.getFirst();
                var icon = iconNode.getStyle("background-image");
                var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
                icon = icon.substr(0, icon.lastIndexOf("_gray"))+"."+ext;
                iconNode.setStyle("background-image", icon);
                action.store("disabled", false);
            }
        }
    },
    setActionDisabled: function(action){
        if (action){
            if (!action.retrieve("disabled")){
                var iconNode = action.getFirst();
                var icon = iconNode.getStyle("background-image");
                var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
                icon = icon.substr(0, icon.lastIndexOf("."))+"_gray."+ext;
                iconNode.setStyle("background-image", icon);
                action.store("disabled", true);
            }
        }
    },
    setReadonly: function() {
        this.actions.each(function(action){
            this.setActionDisabled(action);
NoSubject's avatar
NoSubject 已提交
676
            this.setAttachmentsAction("all", false );
NoSubject's avatar
NoSubject 已提交
677 678
        }.bind(this));
    },
NoSubject's avatar
NoSubject 已提交
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
    setAttachmentsAction : function(type, enable){
        this.attachments.each( function( att ){
            this.setAttachmentAction( att, type, enable )
        }.bind(this))
    },
    setAttachmentAction : function(att, type, enable){
        var action;
        if( type === "all" ){
            ( att.actions || [] ).each( function(action){
                att[ enable ? "setActionEnabled" : "setActionDisabled" ](action);
            })
        }else{
            switch( type ){
                case "download" :
                    action = att.downloadAction;
                    break;
                case "config" :
                    action = att.configAction;
                    break;
                case "delete" :
                    action = att.deleteAction;
                    break;
                case "replace" :
                    action = att.replaceAction;
                    break;
            }
            if( !action )return;
            if( type === "config" ){
                var flag = enable;
                if( flag ){
                    var user = layout.session.user.distinguishedName;
R
roo00 已提交
710 711 712

                    if( !att.data.person && att.data.creatorUid )att.data.person = att.data.creatorUid;

NoSubject's avatar
NoSubject 已提交
713 714 715 716 717 718 719 720 721 722
                    if ((!att.data.control.allowControl || !att.data.control.allowEdit) && att.data.person!==user){
                        flag = false;
                    }
                }
                att[ flag ? "setActionEnabled" : "setActionDisabled" ](action);
            }else{
                att[ enable ? "setActionEnabled" : "setActionDisabled" ](action);
            }
        }
    },
NoSubject's avatar
NoSubject 已提交
723 724 725 726 727 728 729 730 731 732

    doAction: function(e, node, action){
        if (action){
            action.apply(this, [e, node]);
        }
    },

    uploadAttachment: function(e, node){
        if (this.module) this.module.uploadAttachment(e, node);
    },
NoSubject's avatar
NoSubject 已提交
733
    doUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size){
NoSubject's avatar
NoSubject 已提交
734
        if (FormData.expiredIE){
NoSubject's avatar
NoSubject 已提交
735
            this.doInputUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size);
NoSubject's avatar
NoSubject 已提交
736
        }else{
NoSubject's avatar
NoSubject 已提交
737
            this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size);
NoSubject's avatar
NoSubject 已提交
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
        }
    },
    addUploadMessage: function(fileName){
        var contentHTML = "";
        contentHTML = "<div style=\"overflow: hidden\"><div style=\"height: 2px; border:0px solid #999; margin: 3px 0px\">" +
            "<div style=\"height: 2px; background-color: #acdab9; width: 0px;\"></div></div>" +
            "<div style=\"height: 20px; line-height: 20px\">"+o2.LP.desktop.action.uploadTitle+"</div></div>" +
            "<iframe name='o2_upload_iframe' style='display:none'></iframe>" ;
        var msg = {
            "subject": o2.LP.desktop.action.uploadTitle,
            "content": fileName+"<br/>"+contentHTML
        };
        if (layout.desktop.message){
            var messageItem = layout.desktop.message.addMessage(msg);
            messageItem.close = function(callback, e){
                if (!messageItem.completed){

                }else{
                    messageItem.closeItem(callback, e);
                }
            };
        }
        window.setTimeout(function(){
            if (layout.desktop.message) if (!layout.desktop.message.isShow) layout.desktop.message.show();
        }.bind(this), 300);

        return messageItem;
    },
    setMessageTitle: function(messageItem, text){
        if (messageItem) messageItem.subjectNode.set("text", text);
    },
    setMessageText: function(messageItem, text){
        if (messageItem){
            var progressNode = messageItem.contentNode.getFirst("div").getFirst("div");
            var progressPercentNode = progressNode.getFirst("div");
            var progressInforNode = messageItem.contentNode.getFirst("div").getLast("div");
            progressInforNode.set("text", text);
            messageItem.dateNode.set("text", (new Date()).format("db"));
        }

    },
    doInputUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept){
        var restActions = action;
        if (typeOf(action)=="string"){
            restActions = o2.Actions.get(action).action;
        }
        restActions.getActions(function(){
            var url = restActions.actions[invokeUrl];
            url = restActions.address+url.uri;

            Object.each(parameter, function(v, k){
                url = url.replace("{"+k+"}", v);
            });

            var maskNode = this.module.content;
            if (!maskNode){
                if (this.module.form){
                    maskNode = this.module.form.app.content;
                }
            }
            if (!maskNode) maskNode = this.node;
            //var maskNode = this.module.content || this.module.node;
            if (maskNode){
                maskNode.mask({
                    "style": {
                        "opacity": 0.7,
                        "background-color": "#999"
                    }
                });
            }

            this.inputUploadAreaNode = new Element("div", {"styles": this.css.inputUploadAreaNode}).inject(this.container);
            this.inputUploadAreaNode.position({
                relativeTo: this.module.content,
                position: "center"
            });

            var messageItem = null;
            document.O2UploadCallbackFun = function(str){
                var json = JSON.decode(str);
                messageItem.completed = true;
                if (json.type==="success"){
                    if (every) every(json.data);
                    this.setMessageTitle(messageItem, o2.LP.desktop.action.uploadComplete);
                    this.setMessageText(messageItem, o2.LP.desktop.action.uploadComplete);
                    if(finish) finish();
                }else{
                    //formNode.unmask();
                    this.setMessageTitle(messageItem, o2.LP.desktop.action.sendError);
                    this.setMessageText(messageItem, o2.LP.desktop.action.sendError+": "+json.message);
                    o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
                }
            }.bind(this);

            var formNode = new Element("form", {
                "method": "POST",
                "action": url+"/callback/window.frameElement.ownerDocument.O2UploadCallbackFun",
                //"action": url,
                "enctype": "multipart/form-data",
                "target": "o2_upload_iframe"
            }).inject(this.inputUploadAreaNode);

            var titleNode = new Element("div", {"styles": this.css.inputUploadAreaTitleNode, "text": o2.LP.widget.uploadTitle}).inject(formNode);
            var inforNode = new Element("div", {"styles": this.css.inputUploadAreaInforNode, "text": o2.LP.widget.uploadInfor}).inject(formNode);
            var inputAreaNode = new Element("div", {"styles": this.css.inputUploadAreaInputAreaNode}).inject(formNode);
            var inputNode = new Element("input", {"name":"file", "type": "file", "styles": this.css.inputUploadAreaInputNode}).inject(inputAreaNode);
            var inputNameNode = new Element("input", {"type": "hidden", "name": "fileName"}).inject(inputAreaNode);

            Object.each(obj, function(v, k){
                new Element("input", {"type": "hidden", "name": k, "value": v}).inject(inputAreaNode);
            });

            var actionNode = new Element("div", {"styles": this.css.inputUploadActionNode}).inject(formNode);
            var cancelButton = new Element("button", {"styles": this.css.inputUploadCancelButton, "text": o2.LP.widget.cancel}).inject(actionNode);
            var okButton = new Element("input", {"type": "button", "styles": this.css.inputUploadOkButton, "value": o2.LP.widget.ok}).inject(actionNode);

            inputNode.addEvent("change", function(){
                var fileName = inputNode.get("value");
                if (fileName){
                    var tmpv = fileName.replace(/\\/g, "/");
                    var i = tmpv.lastIndexOf("/");
                    var fname = (i===-1) ? tmpv : tmpv.substr(i+1, tmpv.length-i);
                    inputNameNode.set("value", fname);
                }
            }.bind(this));

            cancelButton.addEvent("click", function(){
                if (maskNode) maskNode.unmask();
                this.inputUploadAreaNode.destroy();
            }.bind(this));

            okButton.addEvent("click", function(){
                formNode.mask({
                    "style": {
                        "opacity": 0.7,
                        "background-color": "#999"
                    }
                });

                var isContinue = true;
                if (beforeUpload) isContinue = beforeUpload([inputNameNode.get("value")]);
                if (isContinue){
                    messageItem = this.addUploadMessage(inputNameNode.get("value"));
                    formNode.submit();
                    if (maskNode) maskNode.unmask();
                    if (this.inputUploadAreaNode) this.inputUploadAreaNode.destroy();
                }
            }.bind(this));
        }.bind(this));
    },
NoSubject's avatar
NoSubject 已提交
888
    doFormDataUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size){
NoSubject's avatar
NoSubject 已提交
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
        if (!this.uploadFileAreaNode){
            this.uploadFileAreaNode = new Element("div");
            var html = "<input name=\"file\" multiple type=\"file\" accept=\"*/*\"/>";
            this.uploadFileAreaNode.set("html", html);

            this.fileUploadNode = this.uploadFileAreaNode.getFirst();
            this.fileUploadNode.addEvent("change", function(){
                var files = this.fileUploadNode.files;
                if (files.length){
                    var count = files.length;
                    var current = 0;

                    var restActions = action;
                    if (typeOf(action)=="string"){
                        restActions = o2.Actions.get(action).action;
                    }
                    //var url = restActions.action.actions[invokeUri];

                    var callback = function(){
                        if (current == count){
                            if(finish) finish();
                        }
                    };

                    var isContinue = true;
                    if (beforeUpload) isContinue = beforeUpload(files);
NoSubject's avatar
NoSubject 已提交
915
                    debugger;
NoSubject's avatar
NoSubject 已提交
916
                    if (isContinue){
NoSubject's avatar
NoSubject 已提交
917 918
                        var accepts = (accept) ? accept.split(o2.splitStr) : null;

NoSubject's avatar
NoSubject 已提交
919 920
                        for (var i = 0; i < files.length; i++) {
                            var file = files.item(i);
NoSubject's avatar
NoSubject 已提交
921
                            var ext = file.name.substr(file.name.lastIndexOf("."), file.name.length);
R
roo00 已提交
922
                            ext = ext.toLowerCase();
NoSubject's avatar
NoSubject 已提交
923 924 925 926 927
                            if (accepts && (accepts.indexOf(ext)===-1 && accepts.indexOf("*")===-1 && accepts.indexOf("*/*")===-1)){
                                var msg = {
                                    "subject": o2.LP.widget.refuseUpload,
                                    "content": "<div>名为:<font style='color:#0000ff'>“"+file.name+"”</font>的附件不符合允许上传类型,<font style='color:#ff0000'>已经被剔除</font></div>"
                                };
R
roo00 已提交
928 929
                                if (layout.desktop.message) layout.desktop.message.addTooltip(msg);
                                if (layout.desktop.message) layout.desktop.message.addMessage(msg);
NoSubject's avatar
NoSubject 已提交
930
                                if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("error", {"x": "right", "y": "top"}, "文件:“"+file.name+"”不符合允许上传类型", this.node);
NoSubject's avatar
NoSubject 已提交
931 932 933 934 935
                            }else if (size && file.size> size*1024*1024){
                                var msg = {
                                    "subject": o2.LP.widget.refuseUpload,
                                    "content": "<div>名为:<font style='color:#0000ff'>“"+file.name+"”</font>的附件超出允许的大小,<font style='color:#ff0000'>已经被剔除</font>(仅允许上传小于"+size+"M的文件)</div>"
                                };
R
roo00 已提交
936 937
                                if (layout.desktop.message) layout.desktop.message.addTooltip(msg);
                                if (layout.desktop.message) layout.desktop.message.addMessage(msg);
NoSubject's avatar
NoSubject 已提交
938
                                if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("error", {"x": "right", "y": "top"}, "文件:“"+file.name+"”超出允许的大小,(仅允许上传小于"+size+"M的文件)", this.node);
NoSubject's avatar
NoSubject 已提交
939 940 941 942 943 944
                            }else{
                                var formData = new FormData();
                                Object.each(obj, function(v, k){
                                    formData.append(k, v)
                                });
                                formData.append('file', file);
NoSubject's avatar
NoSubject 已提交
945
                                if(parameter.fileMd5){
946
                                    o2.load("../o2_lib/CryptoJS/components/spark-md5-min.js", function(){
NoSubject's avatar
NoSubject 已提交
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015

                                        var fileReader = new FileReader(), box = document.getElementById('box');
                                        var blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice;
                                        var chunkSize = 20971520;
                                        // read in chunks of 20MB
                                        var chunks = Math.ceil(file.size / chunkSize), currentChunk = 0, spark = new SparkMD5();

                                        fileReader.onload = function(e) {
                                            console.log("read chunk nr", currentChunk + 1, "of", chunks);
                                            spark.appendBinary(e.target.result);
                                            currentChunk++;

                                            if (currentChunk < chunks) {
                                                loadNext();
                                            } else {
                                                console.log("finished loading");
                                                var fileMd5 = spark.end();

                                                restActions.invoke({
                                                    "name": "checkFileExist",
                                                    "async": true,
                                                    "parameter": {"fileMd5":fileMd5},
                                                    "success": function(json){
                                                        if(json.data.value){
                                                            var formData2 = new FormData();
                                                            formData2.append("fileMd5",fileMd5);
                                                            formData2.append("fileName",file.name);
                                                            restActions.invoke({
                                                                "name": "addAttachmentMd5",
                                                                "async": true,
                                                                "data": formData2,
                                                                "parameter": parameter,
                                                                "success": function(json){
                                                                    current++;
                                                                    if (every) every(json, current, count);
                                                                    callback();
                                                                }
                                                            });
                                                        }else{
                                                            restActions.invoke({
                                                                "name": invokeUrl,
                                                                "async": true,
                                                                "data": formData,
                                                                "file": file,
                                                                "parameter": parameter,
                                                                "success": function(json){
                                                                    current++;
                                                                    if (every) every(json, current, count);
                                                                    callback();
                                                                }
                                                            });
                                                        }

                                                    }
                                                });
                                                // compute hash
                                            }
                                        };

                                        function loadNext() {
                                            var start = currentChunk * chunkSize, end = start + chunkSize >= file.size ? file.size : start + chunkSize;

                                            fileReader.readAsBinaryString(blobSlice.call(file, start, end));
                                        }

                                        loadNext();
                                    }.bind(this),null,false);

                                }else{
NoSubject's avatar
NoSubject 已提交
1016
                                    restActions.targetModule = {"module": this, "file": file};
NoSubject's avatar
NoSubject 已提交
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
                                    restActions.invoke({
                                        "name": invokeUrl,
                                        "async": true,
                                        "data": formData,
                                        "file": file,
                                        "parameter": parameter,
                                        "success": function(json){
                                            current++;
                                            if (every) every(json, current, count);
                                            callback();
                                        }
                                    });
                                }

NoSubject's avatar
NoSubject 已提交
1031
                            }
NoSubject's avatar
NoSubject 已提交
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
                        }
                    }
                    this.uploadFileAreaNode.destroy();
                    this.uploadFileAreaNode = null;
                }
            }.bind(this));
        }
        this.fileUploadNode.set("accept", accept || "*/*");
        this.fileUploadNode.set("multiple", (multiple!==false));
        this.fileUploadNode.click();
    },

NoSubject's avatar
NoSubject 已提交
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
    addFormDataMessage: function(file){
        return this.addAttachmentMessage(file);
    },

    addAttachmentMessage: function(file){
        var messageItem;
        if (this.options.size=="min"){
            messageItem = new o2.widget.AttachmentController.AttachmentMessageMin(file, this);
        }else{
            messageItem = new o2.widget.AttachmentController.AttachmentMessage(file, this);
        }
        if (!this.messageItemList) this.messageItemList = {};
        this.messageItemList[messageItem.data.id] = messageItem;
        return messageItem;
    },
NoSubject's avatar
NoSubject 已提交
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070

    openInOfficeControl: function(e, node){},
    deleteAttachment: function(e, node){
        if (this.selectedAttachments.length){
            if (this.module) this.module.deleteAttachments(e, node, this.selectedAttachments);
        }
    },
    replaceAttachment: function(e, node){
        if (this.selectedAttachments.length && this.selectedAttachments.length==1){
            if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
        }
    },
NoSubject's avatar
NoSubject 已提交
1071
    doReplaceAttachment: function(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size){
NoSubject's avatar
NoSubject 已提交
1072
        if (FormData.expiredIE){
NoSubject's avatar
NoSubject 已提交
1073
            this.doInputUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size);
NoSubject's avatar
NoSubject 已提交
1074
        }else{
NoSubject's avatar
NoSubject 已提交
1075
            this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size);
NoSubject's avatar
NoSubject 已提交
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
        }
    },



    downloadAttachment: function(e, node){
        if (this.selectedAttachments.length){
            if (this.module) this.module.downloadAttachment(e, node, this.selectedAttachments);
        }
    },

    openAttachment: function(e, node, attachment){
        if (attachment){
            if (this.module) this.module.openAttachment(e, node, attachment);
        }
    },

    downloadAllAttachment: function(e, node){
        if (this.module) this.module.downloadAttachment(e, node, this.attachments);
    },
    changeListStyle: function(style){
        this.options.listStyle = style;
        this.attachments.each(function(attachment){
            attachment.changeListStyle(style);
        }.bind(this));
        this.checkListStyleAction();
    },
    changeControllerSize: function(e, node){
        if (this.options.size=="max"){
            this.changeControllerSizeToMin();
        }else{
            this.changeControllerSizeToMax();
        }
    },

    changeControllerSizeToMin: function(){
        if (this.options.size!="min"){
            if (this.contentScrollNode) this.contentScrollNode.setStyle("display", "none");
            if (this.bottomNode) this.bottomNode.setStyle("display", "none");
            if (this.topNode) this.topNode.setStyle("display", "none");
            if (this.titleNode) this.titleNode.setStyle("display", "none");

            if (!this.nodeMorph) this.nodeMorph = new Fx.Morph(this.node, {"duration": 100});

            this.nodeMorph.start(this.css.container_min).chain(function(){
                this.options.size = "min";
                this.loadMin();
            }.bind(this));
        }
    },
    changeControllerSizeToMax: function(){
        if (this.options.size!="max") {
            if (this.minActionAreaNode) this.minActionAreaNode.setStyle("display", "none");
            if (this.minContent) this.minContent.setStyle("display", "none");

            if (!this.nodeMorph) this.nodeMorph = new Fx.Morph(this.node, {"duration": 100});

            this.nodeMorph.start(this.css.container).chain(function () {
                this.options.size = "max";
                this.loadMax();
            }.bind(this));
        }
    },

    getAttachmentNames: function(){
        var names = [];
        this.attachments.each(function(attachment){
            names.push(attachment.data.name);
        });
        return names;
    },

NoSubject's avatar
NoSubject 已提交
1148
    addAttachment: function(data, messageId){
NoSubject's avatar
NoSubject 已提交
1149
        if (this.options.size=="min"){
NoSubject's avatar
NoSubject 已提交
1150
            this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(data, this, messageId));
NoSubject's avatar
NoSubject 已提交
1151
        }else{
NoSubject's avatar
NoSubject 已提交
1152
            this.attachments.push(new o2.widget.AttachmentController.Attachment(data, this, messageId));
NoSubject's avatar
NoSubject 已提交
1153
        }
NoSubject's avatar
NoSubject 已提交
1154
        this.checkActions();
NoSubject's avatar
NoSubject 已提交
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
    },
    removeAttachment: function(attachment){
        this.attachments.erase(attachment);
        this.selectedAttachments.erase(attachment);
        attachment.node.destroy();
        delete attachment;
    },

    unSelectedAttachments: function(){
        while (this.selectedAttachments.length){
            var attachment = this.selectedAttachments.shift();
            attachment.unSelected();
        }
        this.checkActions();
    },
    clear: function(){
        this.selectedAttachments = [];
        this.attachments.each(function(att){
            att.node.destroy();
            o2.release(att);
        });
        this.attachments = [];
NoSubject's avatar
NoSubject 已提交
1177 1178
        var content = (this.minContent || this.content);
        if (content) content.empty();
NoSubject's avatar
NoSubject 已提交
1179 1180 1181 1182 1183 1184
    }

});

o2.widget.AttachmentController.Attachment = new Class({
	Implements: [Events],
NoSubject's avatar
NoSubject 已提交
1185
	initialize: function(data, controller, messageId){
NoSubject's avatar
NoSubject 已提交
1186
		this.data = data;
R
roo00 已提交
1187 1188 1189

        if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;

NoSubject's avatar
NoSubject 已提交
1190 1191 1192 1193 1194 1195
        this.controller = controller;
        this.css = this.controller.css;
        this.listStyle = this.controller.options.listStyle;
        this.content = this.controller.content;
        this.isSelected = false;
        this.seq = this.controller.attachments.length+1;
NoSubject's avatar
NoSubject 已提交
1196
        this.actions = [];
NoSubject's avatar
NoSubject 已提交
1197 1198 1199 1200 1201

        if (messageId && this.controller.messageItemList) {
            this.message = this.controller.messageItemList[messageId];
        }

NoSubject's avatar
NoSubject 已提交
1202 1203
        this.load();
	},
NoSubject's avatar
NoSubject 已提交
1204 1205 1206 1207 1208 1209 1210
    _getLnkPar: function(url){
        return {
            "icon": this.getIcon(),
            "title": this.data.name,
            "par": "@url#"+url
        };
    },
NoSubject's avatar
NoSubject 已提交
1211
    load: function(){
NoSubject's avatar
NoSubject 已提交
1212 1213 1214 1215 1216 1217 1218 1219
	    if (this.message){
            this.node = new Element("div").inject(this.message.node, "after");
            this.message.node.destroy();
            delete this.controller.messageItemList[this.message.data.id];
        }else{
            this.node = new Element("div").inject(this.content);
        }

NoSubject's avatar
NoSubject 已提交
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
        switch (this.controller.options.listStyle){
            case "list":
                this.loadList();
                break;
            case "icon":
                this.loadIcon();
                break;
            case "preview":
                this.loadPreview();
                break;
            case "sequence":
                this.loadSequence();
                break;
        }
NoSubject's avatar
NoSubject 已提交
1234 1235 1236 1237 1238 1239 1240

        this.controller.module.getAttachmentUrl(this, function(url){
            this.node.makeLnk({
                "par": this._getLnkPar(url)
            });
        }.bind(this));

NoSubject's avatar
NoSubject 已提交
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
        this.createInforNode(function(){
            if (!Browser.Platform.ios){
                this.tooltip = new mBox.Tooltip({
                    content: this.inforNode,
                    setStyles: {content: {padding: 15, lineHeight: 20}},
                    attach: this.node,
                    transition: 'flyin'
                });
            }
        }.bind(this));

        this.setEvent();
    },
    createInforNode: function(callback){
        var size = "";
        var k = this.data.length/1204;
        if (k>1024){
            var m = k/1024;
            m = Math.round(m*100)/100;
            size = m+"M";
        }else{
            k = Math.round(k*100)/100;
            size = k+"K";
        }
        this.inforNode = new Element("div", {"styles": this.css.attachmentInforNode});
        var html = "<div style='overflow:hidden; font-weight: bold'>"+this.data.name+"</div>";
R
roo00 已提交
1267
        html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.uploader+": </div><div style='width:120px; float:left; margin-left:10px'>"+( this.data.person || this.data.creatorUid )+"</div></div>";
NoSubject's avatar
NoSubject 已提交
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
        html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.uploadTime+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.createTime+"</div></div>";
        html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.modifyTime+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.lastUpdateTime+"</div></div>";
        html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.uploadActivity+": </div><div style='width:120px; float:left; margin-left:10px'>"+(this.data.activityName || o2.LP.widget.unknow)+"</div></div>";
        html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.size+": </div><div style='width:120px; float:left; margin-left:10px'>"+size+"</div></div>";
        this.inforNode.set("html", html);

        if (callback) callback();
    },
    getIcon: function(){
        if (!this.data.extension) this.data.extension="unkonw";
R
roo00 已提交
1278

NoSubject's avatar
NoSubject 已提交
1279
        var iconName = this.controller.icons[this.data.extension.toLowerCase()] || this.controller.icons.unknow;
1280
        var iconFolderUrl = this.controller.options.iconFolderUrl ? this.controller.options.iconFolderUrl : "../x_component_File/$Main/default/file/";
R
roo00 已提交
1281
        return iconFolderUrl+iconName;
NoSubject's avatar
NoSubject 已提交
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
    },

    loadList: function(){
        this.node.setStyles(this.css.attachmentNode_list);
        if (this.isSelected) this.node.setStyles(this.css.attachmentNode_list_selected);

        this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node);
        this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode);
        this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode);
        this.iconImgNode.set({"src": this.getIcon(), "border": 0});

        this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_list}).inject(this.node);
        this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode);
        this.textTitleNode.set("text", this.data.name);

        var size = "";
        var k = this.data.length/1204;
        if (k>1024){
            var m = k/1024;
            m = Math.round(m*100)/100;
            size = m+"M";
        }else{
            k = Math.round(k*100)/100;
            size = k+"K";
        }
        this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode);
        this.textSizeNode.set("text", size);

        this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode);
R
roo00 已提交
1311
        this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid ));
NoSubject's avatar
NoSubject 已提交
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350

        this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
        this.textTimeNode.set("text", this.data.lastUpdateTime);

        this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
        this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow);

        this.custom_List();
    },
    custom_List: function(){},
    loadSequence: function(){
        this.node.setStyles(this.css.attachmentNode_sequence);
        if (this.isSelected) this.node.setStyles(this.css.attachmentNode_sequence_selected);

        this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node);

        this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node);
        this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode);
        this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode);
        this.iconImgNode.set({"src": this.getIcon(), "border": 0});

        this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_sequence}).inject(this.node);
        this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode);
        this.textTitleNode.set("text", this.data.name);

        var size = "";
        var k = this.data.length/1204;
        if (k>1024){
            var m = k/1024;
            m = Math.round(m*100)/100;
            size = m+"M";
        }else{
            k = Math.round(k*100)/100;
            size = k+"K";
        }
        this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode);
        this.textSizeNode.set("text", size);

        this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode);
R
roo00 已提交
1351
        this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid));
NoSubject's avatar
NoSubject 已提交
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563

        this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
        this.textTimeNode.set("text", this.data.lastUpdateTime);

        this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
        this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow);

        this.custom_Sequence();
    },
    custom_Sequence: function(){},

    loadIcon: function(){
        this.node.setStyles(this.css.attachmentNode_icon);
        if (this.isSelected) this.node.setStyles(this.css.attachmentNode_icon_selected);

        this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode}).inject(this.node);
        this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode}).inject(this.iconNode);
        this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode}).inject(this.iconImgAreaNode);
        this.iconImgNode.set({"src": this.getIcon(), "border": 0});

        this.textNode = new Element("div", {"styles": this.css.attachmentTextNode}).inject(this.node);
        this.textNode.set("text", this.data.name);
        this.custom_Icon();
    },
    custom_Icon: function(){},

    loadPreview: function(){
        this.node.setStyles(this.css.attachmentNode_preview);
        if (this.isSelected) this.node.setStyles(this.css.attachmentNode_preview_selected);

        this.iconNode = new Element("div", {"styles": this.css.attachmentPreviewIconNode}).inject(this.node);
        this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentPreviewIconImgAreaNode}).inject(this.iconNode);
        this.iconImgNode = new Element("img", {"styles": this.css.attachmentPreviewIconImgNode}).inject(this.iconImgAreaNode);

        var icon = this.getIcon();
        if (this.controller.options.images.indexOf(this.data.extension.toLowerCase())!==-1){
            this.controller.module.getAttachmentUrl(this, function(url){
                icon = url;
                this.getPreviewImgSize(icon, function(size){
                    this.iconImgNode.set({"src": icon, "border": 0});

                    this.iconImgAreaNode.setStyles({
                        "width": ""+size.x+"px",
                        "height": ""+size.y+"px"
                    });
                    this.iconImgNode.setStyles({
                        "width": ""+size.x+"px",
                        "height": ""+size.y+"px",
                        "margin-top": ""+size.top+"px"
                    });

                    window.setTimeout(function(){
                        this.getPreviewImgSize(icon, function(size){
                            if (this.iconImgAreaNode) this.iconImgAreaNode.setStyles({
                                "width": ""+size.x+"px",
                                "height": ""+size.y+"px"
                            });
                            if (this.iconImgNode) this.iconImgNode.setStyles({
                                "width": ""+size.x+"px",
                                "height": ""+size.y+"px",
                                "margin-top": ""+size.top+"px"
                            });
                        }.bind(this))
                    }.bind(this), 100);

                }.bind(this));
            }.bind(this));
            this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
            this.textNode.set("text", this.data.name);
        }else if (this.controller.options.audios.indexOf(this.data.extension.toLowerCase())!==-1){
            this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
            this.textNode.set("text", this.data.name);

            this.controller.module.getAttachmentUrl(this, function(url){
                this.iconImgNode.set({"src": icon, "border": 0});
                this.iconAudioNode = new Element("div", {
                    "styles": this.css.attachmentPreviewAudioNode,
                    "html": "<audio preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+url+"\" type=\"audio/mpeg\"></source></audio>"
                    //"html": "<audio controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+o2.session.path+"/xApplication/File/$Main/qnyh.mp3\"></source></audio>"
                }).inject(this.textNode, "after");
                this.iconAudioNode.addEvent("dblclick", function(e){e.stopPropagation();});
            }.bind(this));
        }else if (this.controller.options.videos.indexOf(this.data.extension.toLowerCase())!==-1){
            this.controller.module.getAttachmentUrl(this, function(url){
                this.iconNode.empty();
                this.iconVideoNode = new Element("div", {
                    "styles": this.css.attachmentPreviewVideoNode,
                    //"html": "<video preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+o2.session.path+"/xApplication/File/$Main/IMG_1615.MOV\"></source></video>"
                    "html": "<video preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+url+"\"></source></video>"
                }).inject(this.iconNode);
                this.iconVideoNode.addEvent("dblclick", function(e){e.stopPropagation();});

                this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
                this.textNode.set("text", this.data.name);
            }.bind(this));
        }else{
            this.iconImgNode.set({"src": icon, "border": 0});
            this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
            this.textNode.set("text", this.data.name);
        }
        this.custom_Preview();
    },
    custom_Preview: function(){},

    getPreviewImgSize: function(icon, callback){
        var areaSize = this.iconNode.getSize();
        var img = new Element("img", {"src": icon}).inject($(document.body));
        img.set("src", icon);
        var size = img.getSize();
        img.destroy();
        var x, y;
        var zoom = areaSize.x/size.x;
        var y = size.y*zoom;
        if (y<=areaSize.y){
            x = areaSize.x;
        }else{
            zoom = areaSize.y/size.y;
            x = size.x*zoom;
            y = areaSize.y;
        }
        var size = {"x": x, "y": y, "top": (areaSize.y-y)/2};
        if (callback) callback(size);
    },

    setEvent: function(){
        this.node.addEvents({
            "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"])}.bind(this),
            "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle])}.bind(this),
            "mousedown": function(e){this.selected(e);}.bind(this),
            "dblclick": function(e){this.openAttachment(e);}.bind(this)
        });
    },

    selected: function(e){
        if (!e.event.ctrlKey) this.controller.unSelectedAttachments();
        //if (!this.isSelected){
        this.controller.selectedAttachments.push(this);
        this.isSelected = true;
        this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_selected"]);
        //}
        if (e) e.stopPropagation();
        this.controller.checkActions();
    },

    unSelected: function(){
        this.isSelected = false;
        this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
        this.controller.selectedAttachments.erase(this);
    },

    changeListStyle: function(style){
        if (this.listStyle!=style){
            this.node.empty();
            switch (style){
                case "list":
                    this.loadList();
                    break;
                case "icon":
                    this.loadIcon();
                    break;
                case "preview":
                    this.loadPreview();
                    break;
                case "sequence":
                    this.loadSequence();
                    break;
            }
            this.listStyle = style;
        }
    },
    reload: function(){
        var node = new Element("div").inject(this.node, "after");

        this.inforNode.destroy();
        this.inforNode = null;
        if (this.tooltip) this.tooltip.destroy();
        this.tooltip = null;

        this.node.destroy();
        delete this.node;
        this.node = node;

        switch (this.listStyle){
            case "list":
                this.loadList();
                break;
            case "icon":
                this.loadIcon();
                break;
            case "preview":
                this.loadPreview();
                break;
            case "sequence":
                this.loadSequence();
                break;
        }

        this.createInforNode();
        if (!Browser.Platform.ios){
            this.tooltip = new mBox.Tooltip({
                content: this.inforNode,
                setStyles: {content: {padding: 15, lineHeight: 20}},
                attach: this.node,
                transition: 'flyin'
            });
        }


        this.setEvent();
    },
    openAttachment: function(e){
        if (this.controller.module) this.controller.module.openAttachment(e, null, [this]);
NoSubject's avatar
NoSubject 已提交
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592
    },
    setActionEnabled: function(action){
        if (action){
            action.setStyle("display","");
            action.store("disabled", false);
            //if (action.retrieve("disabled")){
            //    var iconNode = action.getFirst();
            //    var icon = iconNode.getStyle("background-image");
            //    var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
            //    icon = icon.substr(0, icon.lastIndexOf("_gray"))+"."+ext;
            //    iconNode.setStyle("background-image", icon);
            //    action.store("disabled", false);
            //}
        }
    },
    setActionDisabled: function(action){
        if (action){
            action.setStyle("display","none");
            action.store("disabled", true);
            //if (!action.retrieve("disabled")){
            //    var iconNode = action.getFirst();
            //    var icon = iconNode.getStyle("background-image");
            //    var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
            //    icon = icon.substr(0, icon.lastIndexOf("."))+"_gray."+ext;
            //    iconNode.setStyle("background-image", icon);
            //    action.store("disabled", true);
            //}
        }
    },
R
roo00 已提交
1593
    createAction: function(node, img, img_over, title, click, text){
NoSubject's avatar
NoSubject 已提交
1594

R
roo00 已提交
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
        var actionNode;

        if( this.controller.options.actionShowText ){
            actionNode = new Element("div", {"styles": this.controller.css.minActionNode, "text": text || title, "title" : title }).inject(node);

            var _self = this;
            actionNode.addEvents({
                "mouseover": function( e ){
                    if (!this.actionNode.retrieve("disabled") && _self.controller.css.minActionNode_over){
                        actionNode.setStyles( _self.controller.css.minActionNode_over );
                    }
                }.bind( { actionNode : actionNode } ),
                "mouseout": function(){
                    if (!this.actionNode.retrieve("disabled") && _self.controller.css.minActionNode_over ){
                        actionNode.setStyles( _self.controller.css.minActionNode );
                    }
                }.bind( { actionNode : actionNode } ),
                "click": function(e){
                    if (!this.retrieve("disabled")){
                        click.apply(_self.controller, [e, this]);
                    }
NoSubject's avatar
NoSubject 已提交
1616
                }
R
roo00 已提交
1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
            });
        }else{
            actionNode = new Element("div", {"styles": this.controller.css.minActionNode, "title": title}).inject(node);

            var actionIconNode = new Element("div", {"styles": this.controller.css.minActionIconNode}).inject(actionNode);
            actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+this.controller.options.style+"/icon/"+img+".png)");

            var _self = this;
            actionNode.addEvents({
                "mouseover": function( e ){
                    if (!this.actionNode.retrieve("disabled")){
                        this.actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.controller.options.style+"/icon/"+this.img+".png)");
                    }
                }.bind( { actionNode : actionNode, actionIconNode: actionIconNode, img : img_over } ),
                "mouseout": function(){
                    if (!this.actionNode.retrieve("disabled")){
                        this.actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.controller.options.style+"/icon/"+this.img+".png)");
                    }
                }.bind( { actionNode : actionNode, actionIconNode: actionIconNode,  img : img } ),
                "click": function(e){
                    if (!this.retrieve("disabled")){
                        click.apply(_self.controller, [e, this]);
                    }
NoSubject's avatar
NoSubject 已提交
1640
                }
R
roo00 已提交
1641 1642
            });
        }
NoSubject's avatar
NoSubject 已提交
1643 1644 1645
        if( !this.actions )this.actions = [];
        this.actions.push(actionNode);
        return actionNode;
NoSubject's avatar
NoSubject 已提交
1646 1647 1648 1649 1650 1651
    }
});

o2.widget.AttachmentController.AttachmentMin = new Class({
    Extends: o2.widget.AttachmentController.Attachment,

NoSubject's avatar
NoSubject 已提交
1652
    initialize: function(data, controller, messageId){
NoSubject's avatar
NoSubject 已提交
1653
        this.data = data;
R
roo00 已提交
1654 1655 1656

        if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;

NoSubject's avatar
NoSubject 已提交
1657 1658 1659 1660 1661
        this.controller = controller;
        this.css = this.controller.css;
        this.content = this.controller.minContent;
        this.isSelected = false;
        this.seq = this.controller.attachments.length+1;
NoSubject's avatar
NoSubject 已提交
1662 1663 1664 1665 1666

        if (messageId && this.controller.messageItemList) {
            this.message = this.controller.messageItemList[messageId];
        }

NoSubject's avatar
NoSubject 已提交
1667 1668 1669
        this.load();
    },
    load: function(){
NoSubject's avatar
NoSubject 已提交
1670 1671 1672 1673 1674 1675 1676 1677 1678
        if (this.message){
            this.node = new Element("div").inject(this.message.node, "after");
            this.message.node.destroy();
            delete this.controller.messageItemList[this.message.data.id];
        }else{
            this.node = new Element("div").inject(this.content);
        }

        //this.node = new Element("div").inject(this.content);
NoSubject's avatar
NoSubject 已提交
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695
        //this.loadList();
        switch (this.controller.options.listStyle){
            case "list":
                this.loadList();
                break;
            case "icon":
                this.loadIcon();
                break;
            case "preview":
                this.loadPreview();
                break;
            case "sequence":
                this.loadSequence();
                break;
        }

        this.createInforNode();
NoSubject's avatar
NoSubject 已提交
1696
        if (!Browser.Platform.ios && !layout.mobile){
NoSubject's avatar
NoSubject 已提交
1697 1698 1699 1700 1701 1702 1703 1704 1705
            this.tooltip = new mBox.Tooltip({
                content: this.inforNode,
                setStyles: {content: {padding: 15, lineHeight: 20}},
                attach: this.iconImgNode,
                transition: 'flyin'
            });
        }
        this.setEvent();
    },
R
roo00 已提交
1706
    loadList: function() {
NoSubject's avatar
NoSubject 已提交
1707 1708
        debugger;
        this.node.setStyles( layout.mobile ? this.css.minAttachmentNode_list_mobile : this.css.minAttachmentNode_list);
NoSubject's avatar
NoSubject 已提交
1709

NoSubject's avatar
NoSubject 已提交
1710 1711 1712
        if( !layout.mobile ){
            this.sepNode = new Element("div", {"styles": this.css.minAttachmentSepNode_list}).inject(this.node);
        }
NoSubject's avatar
NoSubject 已提交
1713

R
roo00 已提交
1714
        this.actionAreaNode = new Element("div", {"styles": this.css.minAttachmentActionAreaNode}).inject(this.node);
NoSubject's avatar
NoSubject 已提交
1715

R
roo00 已提交
1716 1717 1718 1719 1720
        if ( this.controller.isAttDownloadAvailable(this) ) {
            this.downloadAction = this.createAction(this.actionAreaNode, "download_single", "download_single_over", o2.LP.widget.download, function (e, node) {
                this.controller.downloadAttachment(e, node);
            }.bind(this));
        }
NoSubject's avatar
NoSubject 已提交
1721 1722
        //this.actions.push( this.downloadAction );

R
roo00 已提交
1723 1724 1725 1726 1727
        if ( this.controller.isAttDeleteAvailable(this) ) {
            this.deleteAction = this.createAction(this.actionAreaNode, "delete_single", "delete_single_over", o2.LP.widget["delete"], function (e, node) {
                this.controller.deleteAttachment(e, node);
            }.bind(this));
        }
NoSubject's avatar
NoSubject 已提交
1728 1729
        //this.actions.push( this.deleteAction );

R
roo00 已提交
1730 1731 1732 1733 1734 1735 1736
        if (this.controller.configAttachment) {
            if ( this.controller.isAttConfigAvailable(this) ) {
                this.configAction = this.createAction(this.actionAreaNode, "config_single", "config_single_over", o2.LP.widget.configAttachment, function (e, node) {
                    this.controller.configAttachment(e, node);
                }.bind(this), o2.LP.widget.configAttachmentText );
                //this.actions.push( this.configAction );
            }
NoSubject's avatar
NoSubject 已提交
1737 1738
        }

NoSubject's avatar
NoSubject 已提交
1739 1740 1741 1742 1743 1744 1745 1746 1747
        if (this.isSelected) this.node.setStyles(this.css.minAttachmentNode_list_selected);

        this.iconNode = new Element("div", {"styles": this.css.minAttachmentIconNode_list}).inject(this.node);
        this.iconImgAreaNode = new Element("div", {"styles": this.css.minAttachmentIconImgAreaNode_list}).inject(this.iconNode);
        this.iconImgNode = new Element("img", {"styles": this.css.minAttachmentIconImgNode_list}).inject(this.iconImgAreaNode);
        this.iconImgNode.set({"src": this.getIcon(), "border": 0});

        this.textNode = new Element("div", {"styles": this.css.minAttachmentTextNode_list}).inject(this.node);
        this.textNode.set("text", this.data.name);
NoSubject's avatar
NoSubject 已提交
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761

        var size = "";
        var k = this.data.length/1204;
        if (k>1024){
            var m = k/1024;
            m = Math.round(m*100)/100;
            size = m+"M";
        }else{
            k = Math.round(k*100)/100;
            size = k+"K";
        }
        this.textSizeNode = new Element("div", {"styles": this.css.minAttachmentSizeNode_list}).inject(this.textNode);
        this.textSizeNode.set("text", ""+size+"");

R
roo00 已提交
1762 1763
        this.node.set("title",this.data.name + ""+size+"");

NoSubject's avatar
NoSubject 已提交
1764 1765 1766
    },
    loadSequence: function(){
        this.node.setStyles(this.css.minAttachmentNode_sequence);
NoSubject's avatar
NoSubject 已提交
1767 1768 1769

        this.actionAreaNode = new Element("div", {"styles":this.css.minAttachmentActionAreaNode}).inject(this.node);

R
roo00 已提交
1770 1771 1772 1773 1774
        if ( this.controller.isAttDownloadAvailable(this) ) {
            this.downloadAction = this.createAction(this.actionAreaNode, "download_single", "download_single_over", o2.LP.widget.download, function (e, node) {
                this.controller.downloadAttachment(e, node);
            }.bind(this));
        }
NoSubject's avatar
NoSubject 已提交
1775 1776
        //this.actions.push( this.downloadAction );

R
roo00 已提交
1777 1778 1779 1780 1781
        if ( this.controller.isAttDeleteAvailable(this) ) {
            this.deleteAction = this.createAction(this.actionAreaNode, "delete_single", "delete_single_over", o2.LP.widget["delete"], function (e, node) {
                this.controller.deleteAttachment(e, node);
            }.bind(this));
        }
NoSubject's avatar
NoSubject 已提交
1782 1783
        //this.actions.push( this.deleteAction );

R
roo00 已提交
1784 1785 1786 1787 1788 1789 1790 1791

        if (this.controller.configAttachment) {
            if ( this.controller.isAttConfigAvailable(this) ) {
                this.configAction = this.createAction(this.actionAreaNode, "config_single", "config_single_over", MWF.LP.widget.configAttachment, function (e, node) {
                    this.controller.configAttachment(e, node);
                }.bind(this));
                //this.actions.push( this.configAction );
            }
NoSubject's avatar
NoSubject 已提交
1792 1793
        }

NoSubject's avatar
NoSubject 已提交
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803
        if (this.isSelected) this.node.setStyles(this.css.minAttachmentNode_list_selected);

        this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node);
        this.iconNode = new Element("div", {"styles": this.css.minAttachmentIconNode_list}).inject(this.node);
        this.iconImgAreaNode = new Element("div", {"styles": this.css.minAttachmentIconImgAreaNode_list}).inject(this.iconNode);
        this.iconImgNode = new Element("img", {"styles": this.css.minAttachmentIconImgNode_list}).inject(this.iconImgAreaNode);
        this.iconImgNode.set({"src": this.getIcon(), "border": 0});

        this.textNode = new Element("div", {"styles": this.css.minAttachmentTextNode_list}).inject(this.node);
        this.textNode.set("text", this.data.name);
NoSubject's avatar
NoSubject 已提交
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815
        var size = "";
        var k = this.data.length/1204;
        if (k>1024){
            var m = k/1024;
            m = Math.round(m*100)/100;
            size = m+"M";
        }else{
            k = Math.round(k*100)/100;
            size = k+"K";
        }
        this.textSizeNode = new Element("div", {"styles": this.css.minAttachmentSizeNode_list}).inject(this.textNode);
        this.textSizeNode.set("text", ""+size+"");
NoSubject's avatar
NoSubject 已提交
1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
    },
    setEvent: function(){
        this.node.addEvents({
            "mouseover": function(){
                if (!this.isSelected){
                    if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
                        this.node.setStyles(this.css["minAttachmentNode_"+this.controller.options.listStyle+"_over"]);
                    }else{
                        this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"]);
                    }
                }
            }.bind(this),
            "mouseout": function(){
                if (!this.isSelected){
                    if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
NoSubject's avatar
NoSubject 已提交
1831 1832
                        var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" );
                        this.node.setStyles(this.css[cssKey]);
NoSubject's avatar
NoSubject 已提交
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889
                    }else{
                        this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
                    }
                }
            }.bind(this),
            "mousedown": function(e){this.selected(e);}.bind(this),
            "dblclick": function(e){this.openAttachment(e);}.bind(this)
        });
    },

    selected: function(e){
        if (!e.event.ctrlKey) this.controller.unSelectedAttachments();
        //if (!this.isSelected){
        this.controller.selectedAttachments.push(this);
        this.isSelected = true;
        if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
            //this.node.setStyles(this.css["minAttachmentNode_list_selected"]);
            this.node.setStyles(this.css["minAttachmentNode_"+this.controller.options.listStyle+"_selected"]);
        }else{
            this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_selected"]);
            //this.node.setStyles(this.css["minAttachmentNode_list_selected"]);
        }

        //}
        if (e) e.stopPropagation();
        this.controller.checkActions();
    },
    reload: function(){
        var node = new Element("div").inject(this.node, "after");

        this.inforNode.destroy();
        this.inforNode = null;
        if (this.tooltip) this.tooltip.destroy();
        this.tooltip = null;

        this.node.destroy();
        delete this.node;
        this.node = node;

        this.loadList();

        this.createInforNode();
        if (!Browser.Platform.ios){
            this.tooltip = new mBox.Tooltip({
                content: this.inforNode,
                setStyles: {content: {padding: 15, lineHeight: 20}},
                attach: this.node,
                transition: 'flyin'
            });
        }

        this.setEvent();
    },
    unSelected: function(){
        this.isSelected = false;
        //this.node.setStyles(this.css["minAttachmentNode_list"]);
        if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
NoSubject's avatar
NoSubject 已提交
1890 1891
            var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" );
            this.node.setStyles(this.css[cssKey]);
NoSubject's avatar
NoSubject 已提交
1892 1893 1894 1895 1896 1897 1898
        }else{
            this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
        }

        this.controller.selectedAttachments.erase(this);
    }

1899
});
NoSubject's avatar
NoSubject 已提交
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170

o2.widget.AttachmentController.AttachmentMessage = new Class({
    Extends: o2.widget.AttachmentController.Attachment,
    Implements: [Events],
    initialize: function(file, controller){
        var d = (new Date).format("db");
        var extension = file.name.substring(file.name.lastIndexOf(".")+1, file.name.length);
        this.file = file;
        this.data = {
            activity: "",
            activityName: "",
            activityToken: "",
            activityType: "manual",
            application: "",
            completed: false,
            control: {allowRead:true, allowEdit:false, allowControl:false},
            controllerIdentityList: [],
            controllerUnitList: [],
            createTime: d,
            deepPath: false,
            divisionList: [],
            editIdentityList: [],
            editUnitList: [],
            extension: extension,
            id: (new o2.widget.UUID()).toString(),
            job: "",
            lastUpdatePerson: (layout) ? layout.session.user.name : "",
            lastUpdateTime: d,
            length: file.size,
            name: file.name,
            person: (layout) ? layout.session.user.name : "",
            process: "",
            readIdentityList: [],
            readUnitList: [],
            site: "$doc",
            storage: file.size,
            type: "",
            updateTime: d,
            workCreateTime: ""
        }


        if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;

        this.controller = controller;
        this.css = this.controller.css;
        this.listStyle = this.controller.options.listStyle;
        this.content = this.controller.content;
        this.isSelected = false;
        this.seq = this.controller.attachments.length+1;
        this.actions = [];
        this.load();
    },
    load: function(){
        this.node = new Element("div").inject(this.content);
        switch (this.controller.options.listStyle){
            case "list":
                this.loadList();
                break;
            case "icon":
                this.loadIcon();
                break;
            case "preview":
                this.loadPreview();
                break;
            case "sequence":
                this.loadSequence();
                break;
        }

        this.setEvent();
        this.loadMessage();
    },
    loadMessage: function(){
        var size = this.node.getSize();
        this.node.setStyle("position", "relative");

        this.messageMaskNode = new Element("div", { "styles": this.css.messageMaskNode }).inject(this.node);
        this.messageMaskNode.setStyles({
            "width": ""+size.x+"px",
            "height": ""+size.y+"px"
        });


        this.messageNode = new Element("div", { "styles": this.css.messageNode }).inject(this.node);
        switch (this.controller.options.listStyle){
            case "list":
            case "sequence":
                this.messageNode.setStyles({
                    "width": "0px",
                    "height": ""+size.y+"px"
                });
                break;
            case "icon":
            case "preview":
                this.messageNode.setStyles({
                    "width": ""+size.x+"px",
                    "height": ""+size.y+"px"
                });
                break;
        }

        this.messageText = new Element("div", {
            "styles": this.css.messageText,
            "text": "0%"
        }).inject(this.node);
        this.messageText.setStyles({
            "width": ""+size.x+"px",
            "height": ""+size.y+"px",
            "line-height": ""+size.y+"px"
        });
    },
    updateProgress: function(percent){
        var size = this.node.getSize();
        switch (this.controller.options.listStyle){
            case "list":
            case "sequence":
                var w = size.x*(percent/100);
                this.messageNode.setStyles({
                    "width":""+w+"px"
                });
                break;
            case "icon":
            case "preview":
                var h = size.y*(1-percent/100);
                this.messageNode.setStyle("height", ""+h+"px");
                break;
        }

        var p = (percent*100).toInt()/100;
        this.messageText.set("text", ""+p+"%")
    },
    transferComplete: function(){
        this.messageText.set("text", "loading...")
    }
});
o2.widget.AttachmentController.AttachmentMessageMin = new Class({
    Extends: o2.widget.AttachmentController.AttachmentMin,
    Implements: [Events],
    initialize: function(file, controller){
        var d = (new Date).format("db");
        var extension = file.name.substring(file.name.lastIndexOf(".")+1, file.name.length);
        this.file = file;
        this.data = {
            activity: "",
            activityName: "",
            activityToken: "",
            activityType: "manual",
            application: "",
            completed: false,
            control: {allowRead:true, allowEdit:false, allowControl:false},
            controllerIdentityList: [],
            controllerUnitList: [],
            createTime: d,
            deepPath: false,
            divisionList: [],
            editIdentityList: [],
            editUnitList: [],
            extension: extension,
            id: (new o2.widget.UUID()).toString(),
            job: "",
            lastUpdatePerson: (layout) ? layout.session.user.name : "",
            lastUpdateTime: d,
            length: file.size,
            name: file.name,
            person: (layout) ? layout.session.user.name : "",
            process: "",
            readIdentityList: [],
            readUnitList: [],
            site: "$doc",
            storage: file.size,
            type: "",
            updateTime: d,
            workCreateTime: ""
        }


        if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;

        this.controller = controller;
        this.css = this.controller.css;
        this.listStyle = this.controller.options.listStyle;
        this.content = this.controller.minContent;
        this.isSelected = false;
        this.seq = this.controller.attachments.length+1;
        this.actions = [];
        this.load();
    },
    load: function(){
        this.node = new Element("div").inject(this.content);
        switch (this.controller.options.listStyle){
            case "list":
                this.loadList();
                break;
            case "icon":
                this.loadIcon();
                break;
            case "preview":
                this.loadPreview();
                break;
            case "sequence":
                this.loadSequence();
                break;
        }

        this.setEvent();
        this.loadMessage();
    },
    loadMessage: function(){
        var size = this.node.getSize();
        this.node.setStyle("position", "relative");

        this.messageMaskNode = new Element("div", { "styles": this.css.messageMaskNode }).inject(this.node);
        this.messageMaskNode.setStyles({
            "width": ""+size.x+"px",
            "height": ""+size.y+"px"
        });


        this.messageNode = new Element("div", { "styles": this.css.messageNode }).inject(this.node);
        switch (this.controller.options.listStyle){
            case "list":
            case "sequence":
                this.messageNode.setStyles({
                    "width": "0px",
                    "height": ""+size.y+"px"
                });
                break;
            case "icon":
            case "preview":
                this.messageNode.setStyles({
                    "width": ""+size.x+"px",
                    "height": ""+size.y+"px"
                });
                break;
        }

        this.messageText = new Element("div", {
            "styles": this.css.messageText,
            "text": "0%"
        }).inject(this.node);
        this.messageText.setStyles({
            "width": ""+size.x+"px",
            "height": ""+size.y+"px",
            "line-height": ""+size.y+"px"
        });
    },
    updateProgress: function(percent){
        var size = this.node.getSize();
        switch (this.controller.options.listStyle){
            case "list":
            case "sequence":
                var w = size.x*(percent/100);
                this.messageNode.setStyles({
                    "width":""+w+"px"
                });
                break;
            case "icon":
            case "preview":
                var h = size.y*(1-percent/100);
                this.messageNode.setStyle("height", ""+h+"px");
                break;
        }

        var p = (percent*100).toInt()/100;
        this.messageText.set("text", ""+p+"%")
    },
    transferComplete: function(){
        this.messageText.set("text", "loading...")
    }
});