123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541 |
- o2.widget = o2.widget || {};
- if( !o2.widget.UUID )o2.require("o2.widget.UUID", null, false);
- 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,
- "isPreviewAtt": true,
- "isPreviewAtt": true,
- "isSizeChange": true,
- "isConfig": true,
- "isOrder": true,
- "readonly": false,
- "availableListStyles" : ["list","seq","icon","preview"],
- "toolbarGroupHidden" : [], //edit read list view
- "images": ["bmp", "gif", "png", "jpeg", "jpg", "jpe", "ico"],
- "audios": ["mp3", "wav", "wma", "wmv"],
- "videos": ["avi", "mkv", "mov", "ogg", "mp4", "mpa", "mpe", "mpeg", "mpg", "rmvb"],
- "actionShowText" : false
- },
- 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();
- var iconUrl = this.options.iconConfigUrl ? this.options.iconConfigUrl : "../x_component_File/$Main/icon.json";
- o2.getJSON(iconUrl, function(json){
- this.icons = json;
- }.bind(this), 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();
- // }
- },
- 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();
- },
- getAttachmentById: function(attId){
- for( var i=0; i<this.attachments.length; i++ ){
- if( this.attachments[i].data.id === attId ){
- return this.attachments[i];
- }
- }
- return null;
- },
- loadMax: function(){
- if (!this.node) this.node = new Element("div", {"styles": this.css.container});
- this.createTopNode();
- if (!this.contentScrollNode){
- //this.createTopNode();
- 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");
- this.contentScrollNode.show();
- if (this.bottomNode) this.bottomNode.show();
- if (this.titleNode) this.titleNode.show();
- //this.topNode.setStyle("display", "block");
- 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();
- //this.attachments = atts;
- if( layout.mobile ){
- this.checkActionsZoom();
- }
- },
- loadMin: function(){
- if (!this.node) this.node = new Element("div", {"styles": this.css.container_min});
- if (!this.minActionAreaNode){
- this.minActionAreaNode = new Element("div", {"styles": this.css.minActionAreaNode }).inject(this.node);
- //this.minContent = new Element("div", {"styles": this.css.minContentNode}).inject(this.node);
- this.loadMinActions();
- this.node.inject(this.container);
- //if (this.options.readonly) this.setReadonly();
- //this.checkActions();
- this.setEvent();
- }else{
- this.minActionAreaNode.show();
- //this.minContent.setStyle("display", "block");
- //this.minContent.empty();
- this.minActionAreaNode.empty();
- this.loadMinActions();
- this.setEvent();
- }
- 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 ){
- 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");
- }
- }else{
- this.minContent.setStyle("display", "block");
- 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));
- }
- this.checkActions();
- //this.attachments = atts;
- },
- loadMobile: function(){
- },
- loadMinActions: function(){
- 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));
- this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", o2.LP.widget["delete"], function (e, node) {
- this.deleteAttachment(e, node);
- }.bind(this));
- 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));
- }
- }
- 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));
- }
- var hasChangeSize = this.options.isSizeChange && !hiddenGroup.contains("view");
- if( (!hiddenGroup.contains("edit") || !hiddenGroup.contains("read")) && hasChangeSize ) {
- this.createSeparate(this.minActionAreaNode);
- }
- if (hasChangeSize){
- this.sizeAction = this.createAction(this.minActionAreaNode, "max", o2.LP.widget.min, function () {
- this.changeControllerSize();
- }.bind(this));
- }
- },
- setEvent: function(){
- if (this.contentScrollNode && !this.isContentSetEvent){
- this.contentScrollNode.addEventListener("dragover", function( e ) {
- e.preventDefault();
- e.stopPropagation();
- }, false);
- this.contentScrollNode.addEventListener("drop", function( e ) {
- this.uploadAttachment(e, null, e.dataTransfer.files);
- event.preventDefault();
- }.bind(this), false);
- this.contentScrollNode.addEvents({
- "mousedown": this.unSelectedAttachments.bind(this)
- });
- this.isContentSetEvent = true;
- }
- if (this.minContent && !this.isMinContentSetEvent){
- this.minContent.addEventListener("dragover", function( e ) {
- e.preventDefault();
- e.stopPropagation();
- }, false);
- this.minContent.addEventListener("drop", function (e) {
- this.uploadAttachment(e, null, e.dataTransfer.files);
- event.preventDefault();
- }.bind(this), false);
- this.minContent.addEvents({
- "mousedown": this.unSelectedAttachments.bind(this)
- });
- this.isMinContentSetEvent = true;
- }
- },
- 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();
- }
- },
- 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);
- var scrollFlag = this.contentScrollNode.getStyle("overflow-y");
- if (scrollFlag!=="auto" && scrollFlag!=="scroll"){
- 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);
- 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() : "");
- if (!this.nodeHeight){
- this.nodeHeight = minHeight.toFloat();
- }
- }.bind(this),
- "onDrag": function(el, e){
- var y = el.retrieve("startY");
- var nodeHeight = el.retrieve("nodeHeight");
- var nodeMinHeight = el.retrieve("nodeMinHeight");
- var contentScrollNodeMinHeight = el.retrieve("contentScrollNodeMinHeight");
- var setY = (e.event.y-y)+nodeHeight;
- if( nodeMinHeight && setY < nodeMinHeight && e.event.y<y)return;
- if (setY<this.nodeHeight) setY = this.nodeHeight;
- var setContentY = setY-81;
- if( contentScrollNodeMinHeight && setContentY < contentScrollNodeMinHeight && e.event.y<y )return;
- 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);
- }
- 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","");
- this.topNode.show();
- 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();
- if( layout.mobile ){
- this.checkActionsZoom();
- }
- //this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
- //this.createEditGroupActions();
- //this.createReadGroupActions();
- //this.createListGroupActions();
- //this.createViewGroupActions();
- //this.createConfigGroupActions();
- },
- checkActionsZoom: function(){
- var width = 0;
- this.topNode.getChildren().each(function( node ){
- if(node.offsetParent)width = width + node.getSize().x + this.getOffsetX(node)
- }.bind(this));
- var topSize = this.topNode.getSize();
- if( (topSize.x - 5) < width ){
- var zoom = this.getDecimals((topSize.x - 5) / width);
- this.topNode.setStyle( "zoom", zoom*100+"%" );
- }
- },
- getDecimals: function(v){ //截取两位小数
- var decimals = 4;
- var p = Math.pow(10,decimals);
- var f_x = Math.round(v*p)/p;
- var str = f_x.toString();
- if (decimals>0){
- var pos_decimal = str.indexOf('.');
- if (pos_decimal < 0){
- pos_decimal = str.length;
- str += '.';
- }
- var decimalStr = (str).substr(pos_decimal+1, (str).length);
- while (decimalStr.length < decimals){
- str += '0';
- decimalStr += 0;
- }
- }
- return str;
- },
- getOffsetX : function(node){
- return (node.getStyle("margin-left").toInt() || 0 ) +
- (node.getStyle("margin-right").toInt() || 0 ) +
- (node.getStyle("padding-left").toInt() || 0 ) +
- (node.getStyle("padding-right").toInt() || 0 )+
- (node.getStyle("border-left-width").toInt() || 0 ) +
- (node.getStyle("border-right-width").toInt() || 0 );
- },
- reloadTopNode : function(){
- this.createTopNode();
- },
- createEditGroupActions: function(){
- 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);
- 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));
- if( !this.options.isReplaceHidden ){
- this.replaceAction = this.createAction(this.editActionsGroupNode, "replace", o2.LP.widget.replace, function(e, node){
- this.replaceAttachment(e, node);
- }.bind(this));
- }
- // this.officeAction = this.createAction(this.editActionsGroupNode, "office", o2.LP.widget.office, function(e, node){
- // this.openInOfficeControl(e, node);
- // }.bind(this));
- if( !this.options.toolbarGroupHidden.contains("read") )this.editActionSeparateNode = this.createSeparate(this.editActionsGroupNode);
- },
- 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);
- 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);
- 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(){
- 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));
- }
- if( availableListStyles.contains("seq") ) {
- this.sequenceAction = this.createAction(this.listActionsGroupNode, "seq", o2.LP.widget.sequence, function () {
- this.changeListStyle("sequence");
- }.bind(this));
- }
- if( availableListStyles.contains("icon") ) {
- this.iconAction = this.createAction(this.listActionsGroupNode, "icon", o2.LP.widget.icon, function () {
- this.changeListStyle("icon");
- }.bind(this));
- }
- if( availableListStyles.contains("preview") ) {
- this.previewAction = this.createAction(this.listActionsGroupNode, "preview", o2.LP.widget.preview, function () {
- this.changeListStyle("preview");
- }.bind(this));
- }
- }
- },
- createViewGroupActions: function(){
- 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));
- }
- },
- createSeparate: function(groupNode){
- var separateNode = new Element("div.separateNode", {"styles": this.css.separateNode}).inject(groupNode);
- 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);
- e.stopPropagation();
- }
- });
- this.actions.push(actionNode);
- return actionNode;
- },
- checkActions: function(){
- // if (this.options.readonly){
- // this.setReadonly();
- // }else{
- this.checkUploadAction();
- this.checkDeleteAction();
- this.checkReplaceAction();
- //this.checkOfficeAction();
- this.checkDownloadAction();
- this.checkSizeAction();
- this.checkListStyleAction();
- if( this.options.size === "max" ){
- this.checkEditActionBox();
- }
- },
- checkEditActionBox: function(){
- var isShowEdit = false;
- ["isUpload", "isDelete", "isReplace"].each(function( key ){
- if( key === "isReplace" && this.options.isReplaceHidden )return;
- if( this.options[key] !== "hidden" )isShowEdit = true;
- }.bind(this));
- var isShowRead = false;
- ["isDownload"].each(function( key ){
- if( this.options[key] !== "hidden" )isShowRead = true;
- }.bind(this));
- if(this.editActionSeparateNode)this.editActionSeparateNode.setStyle( "display", isShowEdit && isShowRead ? "" : "none" );
- if(this.editActionBoxNode )this.editActionBoxNode.setStyle( "display", isShowEdit || isShowRead ? "" : "none" );
- },
- checkUploadAction: function(){
- if (this.options.readonly) {
- if (this.options.isUpload === "hidden") {
- this.setActionHidden(this.uploadAction);
- this.setActionHidden(this.min_uploadAction);
- } else {
- this.setActionDisabled(this.uploadAction);
- this.setActionDisabled(this.min_uploadAction);
- }
- return false;
- }
- if (this.options.isUpload === "hidden" ){
- this.setActionHidden(this.uploadAction);
- this.setActionHidden(this.min_uploadAction);
- }else if (!this.options.isUpload){
- this.setActionDisabled(this.uploadAction);
- this.setActionDisabled(this.min_uploadAction);
- }else{
- if (this.options.attachmentCount.toInt() > 0){
- if (this.attachments.length>=this.options.attachmentCount.toInt()){
- 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){
- if (this.options.isDelete === "hidden") {
- this.setActionHidden(this.deleteAction);
- this.setActionHidden(this.min_deleteAction);
- } else {
- this.setActionDisabled(this.deleteAction);
- this.setActionDisabled(this.min_deleteAction);
- }
- this.setAttachmentsAction("delete", false );
- return false;
- }
- if (this.options.isDelete === "hidden") {
- this.setActionHidden(this.deleteAction);
- this.setActionHidden(this.min_deleteAction);
- this.setAttachmentsAction("delete", false );
- } else if (!this.options.isDelete){
- this.setActionDisabled(this.deleteAction);
- this.setActionDisabled(this.min_deleteAction);
- this.setAttachmentsAction("delete", false );
- }else{
- if (this.selectedAttachments.length){
- this.setActionEnabled(this.deleteAction);
- this.setActionEnabled(this.min_deleteAction);
- }else{
- this.setActionDisabled(this.deleteAction);
- this.setActionDisabled(this.min_deleteAction);
- }
- this.setAttachmentsAction("delete", true );
- }
- },
- isAttDeleteAvailable : function( att ){
- if (this.options.readonly)return false;
- if( this.options.toolbarGroupHidden.contains("edit") )return false;
- return this.options.isDelete && this.options.isDelete !== "hidden";
- },
- isAttEditAvailable : function( att ){
- if (this.options.readonly)return false;
- if( this.options.toolbarGroupHidden.contains("edit") )return false;
- return this.options.isEditAtt && this.options.isEditAtt !== "hidden";
- },
- // checkOfficeAction: function(){
- // if (this.officeAction) this.officeAction.setStyle("display", "none");
- // if (this.min_officeAction) this.min_officeAction.setStyle("display", "none");
- // },
- checkReplaceAction: function(){
- if( this.options.isReplaceHidden )return;
- if (this.options.readonly){
- if( this.options.isReplace === "hidden" ){
- this.setActionHidden(this.replaceAction);
- this.setActionHidden(this.min_replaceAction);
- }else{
- this.setActionDisabled(this.replaceAction);
- this.setActionDisabled(this.min_replaceAction);
- }
- this.setAttachmentsAction("replace", false );
- return false;
- }
- if( this.options.isReplace === "hidden" ){
- this.setActionHidden(this.replaceAction);
- this.setActionHidden(this.min_replaceAction);
- this.setAttachmentsAction("replace", false );
- }else if (!this.options.isReplace){
- this.setActionDisabled(this.replaceAction);
- this.setActionDisabled(this.min_replaceAction);
- this.setAttachmentsAction("replace", false );
- }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);
- }
- this.setAttachmentsAction("replace", true );
- }
- },
- isAttReplaceAvailable : function( att ){
- if (this.options.readonly)return false;
- if( this.options.toolbarGroupHidden.contains("edit") )return false;
- return this.options.isReplace && this.options.isReplace !== "hidden";
- },
- checkDownloadAction: function(){
- if( this.options.isDownload === "hidden" ){
- this.setActionHidden(this.downloadAction);
- this.setActionHidden(this.min_downloadAction);
- this.setActionHidden(this.downloadAllAction);
- this.setAttachmentsAction("download", false );
- }else if (!this.options.isDownload){
- this.setActionDisabled(this.downloadAction);
- this.setActionDisabled(this.min_downloadAction);
- this.setActionDisabled(this.downloadAllAction);
- this.setAttachmentsAction("download", false );
- }else{
- if (this.selectedAttachments.length){
- this.setActionEnabled(this.downloadAction);
- this.setActionEnabled(this.min_downloadAction);
- }else{
- this.setActionDisabled(this.downloadAction);
- this.setActionDisabled(this.min_downloadAction);
- }
- this.setActionEnabled(this.downloadAllAction);
- this.setAttachmentsAction("download", true );
- }
- },
- isAttDblclickAvailable : function( att ){
- return this.options.dblclick && this.options.dblclick !== "hidden";
- },
- isAttDownloadAvailable : function( att ){
- if( this.options.toolbarGroupHidden.contains("read") )return false;
- return this.options.isDownload && this.options.isDownload !== "hidden";
- },
- checkSizeAction: function(){
- if( this.sizeAction ){
- if (this.options.isSizeChange){
- this.setActionEnabled(this.sizeAction);
- }else{
- this.setActionDisabled(this.sizeAction);
- }
- }
- },
- 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){
- action.show();
- 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);
- }
- }
- },
- setActionHidden: function(action){
- if (action)action.hide();
- },
- setReadonly: function() {
- this.actions.each(function(action){
- this.setActionDisabled(action);
- this.setAttachmentsAction("all", false );
- }.bind(this));
- },
- 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;
- if( !att.data.person && att.data.creatorUid )att.data.person = att.data.creatorUid;
- if ((!att.data.control.allowControl ) && att.data.person!==user){ //|| !att.data.control.allowEdit
- flag = false;
- }
- }
- att[ flag ? "setActionEnabled" : "setActionDisabled" ](action);
- }else{
- att[ enable ? "setActionEnabled" : "setActionDisabled" ](action);
- }
- }
- },
- doAction: function(e, node, action){
- if (action){
- action.apply(this, [e, node]);
- }
- },
- uploadAttachment: function(e, node, files){
- debugger;
- if (this.module) this.module.uploadAttachment(e, node, files);
- },
- doUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files){
- if ( !this.options.readonly && ( this.options.isUpload && this.options.isUpload !== "hidden") ){
- if (FormData.expiredIE){
- this.doInputUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery);
- }else{
- this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files);
- }
- }else{
- var text = o2.LP.widget.notUploadNotice;
- if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
- }
- },
- 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, failureEvery){
- 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();
- // if(failureEvery)failureEvery(json);
- 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));
- },
- doFormDataUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files){
- var uploadChange = function(uploadfiles){
- var files = uploadfiles || this.fileUploadNode.files;
- if (files.length){
- var count = files.length;
- var current = 0;
- var hasFailUpload = false;
- 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( hasFailUpload );
- }
- };
- var isContinue = true;
- if (beforeUpload) isContinue = beforeUpload(files);
- if (isContinue){
- var accepts = (accept) ? accept.split(o2.splitStr) : null;
- for (var i = 0; i < files.length; i++) {
- var file = files.item(i);
- var ext = file.name.substr(file.name.lastIndexOf("."), file.name.length);
- ext = ext.toLowerCase();
- if (accepts && (accepts.indexOf(ext)===-1 && accepts.indexOf("*")===-1 && accepts.indexOf("*/*")===-1)){
- var msg = {
- "subject": o2.LP.widget.refuseUpload,
- "content": o2.LP.widget.refuseUploadHTML.replace("{filename}", file.name)
- };
- if (layout.desktop.message) layout.desktop.message.addTooltip(msg);
- if (layout.desktop.message) layout.desktop.message.addMessage(msg);
- var text = o2.LP.widget.refuseUploadNotice.replace("{filename}", file.name);
- if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
- }else if (size && file.size> size*1024*1024){
- var msg = {
- "subject": o2.LP.widget.refuseUpload,
- "content": o2.LP.widget.refuseUploadHTML_size.replace("{filename}", file.name).replace("{size}", size)
- };
- if (layout.desktop.message) layout.desktop.message.addTooltip(msg);
- if (layout.desktop.message) layout.desktop.message.addMessage(msg);
- var text = o2.LP.widget.refuseUploadNotice_size.replace("{filename}", file.name).replace("{size}", size);
- if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
- }else{
- var formData = new FormData();
- Object.each(obj, function(v, k){
- formData.append(k, v)
- });
- formData.append('file', file);
- if(parameter.fileMd5){
- o2.load("../o2_lib/CryptoJS/components/spark-md5-min.js", function(){
- 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();
- },
- "failure": function (xhr) {
- var json = JSON.decode(xhr.responseText);
- if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
- current++;
- hasFailUpload = true;
- if (failureEvery) failureEvery(xhr, 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();
- },
- "failure": function (xhr) {
- var json = JSON.decode(xhr.responseText);
- if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
- current++;
- hasFailUpload = true;
- if (failureEvery) failureEvery(xhr, 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{
- restActions.targetModule = {"module": this, "file": file};
- restActions.invoke({
- "name": invokeUrl,
- "async": true,
- "data": formData,
- "file": file,
- "parameter": parameter,
- "success": function(json){
- current++;
- if (every) every(json, current, count);
- callback();
- },
- "failure": function (xhr) {
- var json = JSON.decode(xhr.responseText);
- if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
- current++;
- hasFailUpload = true;
- if (failureEvery) failureEvery(xhr, current, count);
- callback();
- }
- });
- }
- }
- }
- }
- this.uploadFileAreaNode.destroy();
- this.uploadFileAreaNode = null;
- }
- }.bind(this);
- 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(){
- uploadChange();
- });
- }
- this.fileUploadNode.set("accept", accept || "*/*");
- this.fileUploadNode.set("multiple", (multiple!==false));
- if (!files || !files.length){
- this.fileUploadNode.click();
- }else{
- uploadChange(files)
- }
- },
- 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;
- },
- 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]);
- }
- },
- doReplaceAttachment: function(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size){
- if (FormData.expiredIE){
- this.doInputUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size);
- }else{
- this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size);
- }
- },
- previewAttachment: function(e, node){
- if (this.selectedAttachments.length){
- if (this.module) this.module.previewAttachment(this.selectedAttachments);
- }
- },
- editAttachment: function(e, node){
- if (this.selectedAttachments.length){
- if (this.module) this.module.editAttachment(this.selectedAttachments);
- }
- },
- downloadAttachment: function(e, node){
- if (this.selectedAttachments.length){
- if (this.module) this.module.downloadAttachment(e, node, this.selectedAttachments);
- }
- },
- openAttachment: function(e, node, attachment){
- if( !this.options.dblclick ){
- if( !this.options.isDownload || this.options.isDownload === "hidden" )return; //兼容以前的配置
- }
- if (attachment){
- if (this.module) this.module.openAttachment(e, node, attachment);
- }
- },
- dblclickAttachment: function(e, node, attachment){
- if( !attachment || !this.module || this.options.dblclick === "disable" ){
- return;
- }else if( this.options.dblclick === "preview" ){
- if( this.checkPreviewAttachment ){
- this.checkPreviewAttachment(e, node, attachment);
- }else{
- this.module.openAttachment(e, node, attachment);
- }
- }else{
- 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.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.contentScrollNode) this.contentScrollNode.hide();
- if (this.bottomNode) this.bottomNode.hide();
- if (this.topNode) this.topNode.hide();
- if (this.titleNode) this.titleNode.hide();
- 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(){
- debugger;
- if (this.options.size!="max") {
- // if (this.minActionAreaNode) this.minActionAreaNode.setStyle("display", "none");
- // if (this.minContent) this.minContent.setStyle("display", "none");
- if (this.minActionAreaNode) this.minActionAreaNode.hide();
- if (this.minContent) this.minContent.hide();
- 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;
- },
- addAttachment: function(data, messageId, isCheckPosition){
- if (this.options.size=="min"){
- this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(data, this, messageId, isCheckPosition));
- }else{
- this.attachments.push(new o2.widget.AttachmentController.Attachment(data, this, messageId, isCheckPosition));
- }
- this.checkActions();
- },
- 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 = [];
- var content = (this.minContent || this.content);
- if (content) content.empty();
- }
- });
- o2.widget.AttachmentController.Attachment = new Class({
- Implements: [Events],
- initialize: function(data, controller, messageId, isCheckPosition){
- this.data = data;
- 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.isCheckPosition = isCheckPosition;
- this.actions = [];
- if (messageId && this.controller.messageItemList) {
- this.message = this.controller.messageItemList[messageId];
- }
- this.load();
- },
- _getLnkPar: function(url){
- return {
- "icon": this.getIcon(),
- "title": this.data.name,
- "par": "@url#"+url
- };
- },
- isNumber : function( d ){
- return parseFloat(d).toString() !== "NaN"
- },
- load: function(){
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("beforeLoadAttachment", [this]);
- }
- 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);
- }
- if( this.isCheckPosition && this.isNumber(this.data.orderNumber) ){
- var attList = this.controller.attachments;
- for( var i=0; i<attList.length; i++ ){
- var att = attList[i];
- if( !this.isNumber(att.data.orderNumber) || this.data.orderNumber < att.data.orderNumber ){
- this.node.inject( att.node, "before" );
- break;
- }
- }
- }
- 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.controller.module.getAttachmentUrl(this, function(url){
- this.node.makeLnk({
- "par": this._getLnkPar(url)
- });
- }.bind(this));
- 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();
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("loadAttachment", [this]);
- }
- },
- createInforNode: function(callback){
- var size = "";
- var k = this.data.length/1024;
- 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>";
- 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>";
- 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>";
- if(this.data.activityName)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";
- var iconName = this.controller.icons[this.data.extension.toLowerCase()] || this.controller.icons.unknow;
- var iconFolderUrl = this.controller.options.iconFolderUrl ? this.controller.options.iconFolderUrl : "../x_component_File/$Main/default/file/";
- return iconFolderUrl+iconName;
- },
- 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);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textTitleNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textTitleNode.set("text", this.data.name);
- }
- var size = "";
- var k = this.data.length/1024;
- 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);
- this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid ));
- this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
- this.textTimeNode.set("text", this.data.lastUpdateTime);
- if(this.data.activityName){
- 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_sequence || 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);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textTitleNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textTitleNode.set("text", this.data.name);
- }
- var size = "";
- var k = this.data.length/1024;
- 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);
- this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid));
- this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
- this.textTimeNode.set("text", this.data.lastUpdateTime);
- if(this.data.activityName){
- 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);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- 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){
- if (this.type!=="message") this.controller.module.getAttachmentUrl(this, function(url){
- this.iconImgAreaNode.hide();
- this.iconImgNode.hide();
- this.iconNode.setStyles({
- "background-image": "url("+url+")",
- });
- }.bind(this));
- this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // 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);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // 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);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // 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);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // 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); e.stopPropagation();}.bind(this),
- "click": function(e){e.stopPropagation();}.bind(this),
- "dblclick": function(e){
- if( this.controller.options.dblclick ){
- this.controller.dblclickAttachment(e, null, [this]);
- }else{
- this.openAttachment(e);
- }
- }.bind(this)
- });
- if (this.iconImgNode){
- this.iconImgNode.set("draggable", false);
- }
- },
- 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( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("select", [this]);
- }
- 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);
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("unselect", [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.options.dblclick ){
- if (!this.controller.options.isDownload || this.controller.options.isDownload === "hidden") return; //兼容以前的配置
- }
- if (this.controller.module) this.controller.module.openAttachment(e, null, [this]);
- },
- 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);
- //}
- }
- },
- createAction: function(node, img, img_over, title, click, text){
- 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]);
- e.stopPropagation();
- }
- }
- });
- }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]);
- e.stopPropagation();
- }
- }
- });
- }
- if( !this.actions )this.actions = [];
- this.actions.push(actionNode);
- return actionNode;
- }
- });
- o2.widget.AttachmentController.AttachmentMin = new Class({
- Extends: o2.widget.AttachmentController.Attachment,
- initialize: function(data, controller, messageId, isCheckPosition){
- this.data = data;
- 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.isCheckPosition = isCheckPosition;
- this.seq = this.controller.attachments.length+1;
- if (messageId && this.controller.messageItemList) {
- this.message = this.controller.messageItemList[messageId];
- }
- this.load();
- },
- load: function(){
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("beforeLoadAttachment", [this]);
- }
- 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);
- }
- if( this.isCheckPosition && this.isNumber(this.data.orderNumber) ){
- var attList = this.controller.attachments;
- for( var i=0; i<attList.length; i++ ){
- var att = attList[i];
- if( !this.isNumber(att.data.orderNumber) || this.data.orderNumber < att.data.orderNumber ){
- this.node.inject( att.node, "before" );
- break;
- }
- }
- }
- //this.node = new Element("div").inject(this.content);
- //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();
- if (!Browser.Platform.ios && !layout.mobile){
- this.tooltip = new mBox.Tooltip({
- content: this.inforNode,
- setStyles: {content: {padding: 15, lineHeight: 20}},
- attach: this.iconImgNode,
- transition: 'flyin'
- });
- }
- this.setEvent();
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("loadAttachment", [this]);
- }
- },
- loadList: function() {
- this.node.setStyles( layout.mobile ? this.css.minAttachmentNode_list_mobile : this.css.minAttachmentNode_list);
- if( !layout.mobile ){
- this.sepNode = new Element("div", {"styles": this.css.minAttachmentSepNode_list}).inject(this.node);
- }
- this.actionAreaNode = new Element("div", {"styles": this.css.minAttachmentActionAreaNode}).inject(this.node);
- if( this.controller.isAttDblclickAvailable(this) ){
- this.openAction = this.createAction(this.actionAreaNode, "open_single", "open_single_over", o2.LP.widget.open, function (e, node) {
- this.controller.dblclickAttachment(e, node, [this]);
- }.bind(this));
- }
- 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));
- }
- //this.actions.push( this.downloadAction );
- 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));
- }
- if ( this.controller.isAttEditAvailable(this) ) {
- this.editAction = this.createAction(this.actionAreaNode, "edit_single", "edit_single_over", o2.LP.widget["editAtt"], function (e, node) {
- this.controller.editAttachment(e, node);
- }.bind(this));
- }
- //this.actions.push( this.deleteAction );
- 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 );
- }
- }
- 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);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // this.textNode.set("text", this.data.name);
- var size = "";
- var k = this.data.length/1024;
- 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+")");
- this.node.set("title",this.data.name + "("+size+")");
- },
- loadSequence: function(){
- this.node.setStyles(this.css.minAttachmentNode_sequence);
- this.actionAreaNode = new Element("div", {"styles":this.css.minAttachmentActionAreaNode}).inject(this.node);
- if( this.controller.isAttDblclickAvailable(this) ){
- this.openAction = this.createAction(this.actionAreaNode, "open_single", "open_single_over", o2.LP.widget.open, function (e, node) {
- this.controller.dblclickAttachment(e, node, [this]);
- }.bind(this));
- }
- 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));
- }
- //this.actions.push( this.downloadAction );
- 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));
- }
- if ( this.controller.isAttEditAvailable(this) ) {
- this.editAction = this.createAction(this.actionAreaNode, "edit_single", "edit_single_over", o2.LP.widget["editAtt"], function (e, node) {
- this.controller.editAttachment(e, node);
- }.bind(this));
- }
- //this.actions.push( this.deleteAction );
- 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 );
- }
- }
- 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);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // this.textNode.set("text", this.data.name);
- var size = "";
- var k = this.data.length/1024;
- 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+")");
- },
- 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"){
- var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" );
- this.node.setStyles(this.css[cssKey]);
- }else{
- this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
- }
- }
- }.bind(this),
- "mousedown": function(e){this.selected(e);e.stopPropagation();}.bind(this),
- "click": function(e){e.stopPropagation();}.bind(this),
- "dblclick": function(e){
- if( this.controller.options.dblclick ){
- this.controller.dblclickAttachment(e, null, [this]);
- }else{
- this.openAttachment(e);
- }
- }.bind(this)
- });
- if (this.iconImgNode){
- this.iconImgNode.set("draggable", false);
- }
- },
- 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( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("select", [this]);
- }
- //}
- 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;
- debugger;
- 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();
- },
- unSelected: function(){
- this.isSelected = false;
- //this.node.setStyles(this.css["minAttachmentNode_list"]);
- if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
- var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" );
- this.node.setStyles(this.css[cssKey]);
- }else{
- this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
- }
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("unselect", [this]);
- }
- this.controller.selectedAttachments.erase(this);
- }
- });
- 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.type = "message";
- 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...")
- }
- });
|