1 WCF
.Attachment
={};WCF
.Attachment
.Upload
=WCF
.Upload
.extend({_objectType
:"",_objectID
:0,_tmpHash
:"",_parentObjectID
:0,_wysiwygContainerID
:"",init:function(c
,g
,a
,h
,d
,e
,f
,b
){this._super(c
,g
,"wcf\\data\\attachment\\AttachmentAction",{multiple
:true,maxUploads
:f
});this._objectType
=a
;this._objectID
=h
;this._tmpHash
=d
;this._parentObjectID
=e
;this._wysiwygContainerID
=b
;this._buttonSelector
.children("p.button").click($.proxy(this._validateLimit
,this));this._fileListSelector
.find(".jsButtonInsertAttachment").click($.proxy(this._insert
,this));WCF
.DOMNodeRemovedHandler
.addCallback("WCF.Attachment.Upload",$.proxy(this._removeLimitError
,this))},_validateLimit:function(){var c
=this._buttonSelector
.next("small.innerError");var a
=this._options
.maxUploads
-this._fileListSelector
.children("li:not(.uploadFailed)").length
;var d
=(this._fileUpload
)?this._fileUpload
.prop("files").length
:0;if(a
<=0||a
<d
){var b
=(a
<=0)?WCF
.Language
.get("wcf.attachment.upload.error.reachedLimit"):WCF
.Language
.get("wcf.attachment.upload.error.reachedRemainingLimit").replace(/#remaining#/,a
);if(!c
.length
){c
=$('<small class="innerError" />').insertAfter(this._buttonSelector
)}c
.html(b
);return false}c
.remove();return true},_removeLimitError:function(b
){var a
=$(b
.target
);if(a
.is("li.box48")&&a
.parent().wcfIdentify()===this._fileListSelector
.wcfIdentify()){this._buttonSelector
.next("small.innerError").remove()}},_upload:function(){if(this._validateLimit()){this._super()}if(this._fileUpload
){this._removeButton();this._createButton()}},_createUploadMatrix:function(a
){this._fileListSelector
.children("li.uploadFailed").remove();return this._super(a
)},_getParameters:function(){return{objectType
:this._objectType
,objectID
:this._objectID
,tmpHash
:this._tmpHash
,parentObjectID
:this._parentObjectID
}},_initFile:function(a
){var b
=$('<li class="box48"><span class="icon icon48 icon-spinner" /><div><div><p>'+a
.name
+'</p><small><progress max="100"></progress></small></div><ul></ul></div></li>').data("filename",a
.name
);this._fileListSelector
.append(b
);this._fileListSelector
.show();if(this._buttonSelector
.data("maxSize")<a
.size
){b
.find("progress").remove();b
.children(".icon-spinner").removeClass("icon-spinner").addClass("icon-ban-circle");b
.find("div > div").append($('<small class="innerError">'+WCF
.Language
.get("wcf.attachment.upload.error.tooLarge")+"</small>"));b
.addClass("uploadFailed")}return b
},_success:function(b
,c
){for(var i
in this._uploadMatrix
[b
]){var g
=this._uploadMatrix
[b
][i
];g
.find("progress").remove();var h
=g
.data("filename");var j
=g
.data("internalFileID");if(c
.returnValues
&&c
.returnValues
.attachments
[j
]){if(c
.returnValues
.attachments
[j
]["tinyURL"]){g
.children(".icon-spinner").replaceWith($('<img src="'+c
.returnValues
.attachments
[j
]["tinyURL"]+'" alt="" class="attachmentTinyThumbnail" />'))}else{g
.children(".icon-spinner").removeClass("icon-spinner").addClass("icon-paper-clip")}var e
=$('<a href=""></a>');e
.text(h
).attr("href",c
.returnValues
.attachments
[j
]["url"]);if(c
.returnValues
.attachments
[j
]["isImage"]!=0){e
.addClass("jsImageViewer").attr("title",h
)}g
.find("p").empty().append(e
);g
.find("small").append(c
.returnValues
.attachments
[j
]["formattedFilesize"]);var f
=$('<li><span class="icon icon16 icon-remove pointer jsTooltip jsDeleteButton" title="'+WCF
.Language
.get("wcf.global.button.delete")+'" data-object-id="'+c
.returnValues
.attachments
[j
]["attachmentID"]+'" data-confirm-message="'+WCF
.Language
.get("wcf.attachment.delete.sure")+'" /></li>');g
.find("ul").append(f
);if(this._wysiwygContainerID
){var a
=$('<li><span class="icon icon16 icon-paste pointer jsTooltip jsButtonInsertAttachment" title="'+WCF
.Language
.get("wcf.attachment.insert")+'" data-object-id="'+c
.returnValues
.attachments
[j
]["attachmentID"]+'" /></li>');a
.children(".jsButtonInsertAttachment").click($.proxy(this._insert
,this));g
.find("ul").append(a
)}}else{g
.children(".icon-spinner").removeClass("icon-spinner").addClass("icon-ban-circle");var d
="";if(c
.returnValues
&&c
.returnValues
.errors
[j
]){d
=c
.returnValues
.errors
[j
]["errorType"]}else{d
="uploadFailed"}g
.find("div > div").append($('<small class="innerError">'+WCF
.Language
.get("wcf.attachment.upload.error."+d
)+"</small>"));g
.addClass("uploadFailed")}g
.css("display","block")}WCF
.DOMNodeInsertedHandler
.execute()},_insert:function(e
){var d
=$(e
.currentTarget
).data("objectID");var c
="[attach="+d
+"][/attach]";var a
=($.browser
.mobile
)?null:$("#"+this._wysiwygContainerID
).ckeditorGet();if(a
!==null&&a
.mode
==="wysiwyg"){a
.insertText(c
)}else{var g
=($.browser
.mobile
)?$("#"+this._wysiwygContainerID
):$("#"+this._wysiwygContainerID
).next(".cke_editor_text").find("textarea");var b
=g
.val();if(b
.length
==0){g
.val(c
)}else{var f
=g
.getCaret();g
.val(b
.substr(0,f
)+c
+b
.substr(f
))}}},_error:function(a
){this._fileListSelector
.find("li").each(function(b
,d
){var c
=$(d
);if(c
.children(".icon-spinner").length
){c
.addClass("uploadFailed").children(".icon-spinner").removeClass("icon-spinner").addClass("icon-ban-circle");c
.find("div > div").append($('<small class="innerError">'+(a
.responseJSON
&&a
.responseJSON
.message
?a
.responseJSON
.message
:WCF
.Language
.get("wcf.attachment.upload.error.uploadFailed"))+"</small>"))}})}});