amélioration global admin, nouveau système d'upload.

This commit is contained in:
Nico 2013-01-12 01:22:51 +01:00
parent cb3c8cef19
commit 9484ad65f3
27 changed files with 1980 additions and 1950 deletions

View File

@ -18,5 +18,7 @@
*= require ./shared/raphael
*= require ./shared/morris
*= require_tree ./note_files
*/

View File

@ -1,4 +1,6 @@
jQuery ->
$(document).ready ->
if $("#sheets_chart").length > 0
Morris.Line
element: 'sheets_chart'
data: $('#sheets_chart').data('values')

View File

@ -0,0 +1,528 @@
/*
* jQuery UI Widget 1.9.1+amd
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*
* http://api.jqueryui.com/jQuery.widget/
*/
(function (factory) {
if (typeof define === "function" && define.amd) {
// Register as an anonymous AMD module:
define(["jquery"], factory);
} else {
// Browser globals:
factory(jQuery);
}
}(function( $, undefined ) {
var uuid = 0,
slice = Array.prototype.slice,
_cleanData = $.cleanData;
$.cleanData = function( elems ) {
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
try {
$( elem ).triggerHandler( "remove" );
// http://bugs.jquery.com/ticket/8235
} catch( e ) {}
}
_cleanData( elems );
};
$.widget = function( name, base, prototype ) {
var fullName, existingConstructor, constructor, basePrototype,
namespace = name.split( "." )[ 0 ];
name = name.split( "." )[ 1 ];
fullName = namespace + "-" + name;
if ( !prototype ) {
prototype = base;
base = $.Widget;
}
// create selector for plugin
$.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
return !!$.data( elem, fullName );
};
$[ namespace ] = $[ namespace ] || {};
existingConstructor = $[ namespace ][ name ];
constructor = $[ namespace ][ name ] = function( options, element ) {
// allow instantiation without "new" keyword
if ( !this._createWidget ) {
return new constructor( options, element );
}
// allow instantiation without initializing for simple inheritance
// must use "new" keyword (the code above always passes args)
if ( arguments.length ) {
this._createWidget( options, element );
}
};
// extend with the existing constructor to carry over any static properties
$.extend( constructor, existingConstructor, {
version: prototype.version,
// copy the object used to create the prototype in case we need to
// redefine the widget later
_proto: $.extend( {}, prototype ),
// track widgets that inherit from this widget in case this widget is
// redefined after a widget inherits from it
_childConstructors: []
});
basePrototype = new base();
// we need to make the options hash a property directly on the new instance
// otherwise we'll modify the options hash on the prototype that we're
// inheriting from
basePrototype.options = $.widget.extend( {}, basePrototype.options );
$.each( prototype, function( prop, value ) {
if ( $.isFunction( value ) ) {
prototype[ prop ] = (function() {
var _super = function() {
return base.prototype[ prop ].apply( this, arguments );
},
_superApply = function( args ) {
return base.prototype[ prop ].apply( this, args );
};
return function() {
var __super = this._super,
__superApply = this._superApply,
returnValue;
this._super = _super;
this._superApply = _superApply;
returnValue = value.apply( this, arguments );
this._super = __super;
this._superApply = __superApply;
return returnValue;
};
})();
}
});
constructor.prototype = $.widget.extend( basePrototype, {
// TODO: remove support for widgetEventPrefix
// always use the name + a colon as the prefix, e.g., draggable:start
// don't prefix for widgets that aren't DOM-based
widgetEventPrefix: basePrototype.widgetEventPrefix || name
}, prototype, {
constructor: constructor,
namespace: namespace,
widgetName: name,
// TODO remove widgetBaseClass, see #8155
widgetBaseClass: fullName,
widgetFullName: fullName
});
// If this widget is being redefined then we need to find all widgets that
// are inheriting from it and redefine all of them so that they inherit from
// the new version of this widget. We're essentially trying to replace one
// level in the prototype chain.
if ( existingConstructor ) {
$.each( existingConstructor._childConstructors, function( i, child ) {
var childPrototype = child.prototype;
// redefine the child widget using the same prototype that was
// originally used, but inherit from the new version of the base
$.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
});
// remove the list of existing child constructors from the old constructor
// so the old child constructors can be garbage collected
delete existingConstructor._childConstructors;
} else {
base._childConstructors.push( constructor );
}
$.widget.bridge( name, constructor );
};
$.widget.extend = function( target ) {
var input = slice.call( arguments, 1 ),
inputIndex = 0,
inputLength = input.length,
key,
value;
for ( ; inputIndex < inputLength; inputIndex++ ) {
for ( key in input[ inputIndex ] ) {
value = input[ inputIndex ][ key ];
if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
// Clone objects
if ( $.isPlainObject( value ) ) {
target[ key ] = $.isPlainObject( target[ key ] ) ?
$.widget.extend( {}, target[ key ], value ) :
// Don't extend strings, arrays, etc. with objects
$.widget.extend( {}, value );
// Copy everything else by reference
} else {
target[ key ] = value;
}
}
}
}
return target;
};
$.widget.bridge = function( name, object ) {
var fullName = object.prototype.widgetFullName;
$.fn[ name ] = function( options ) {
var isMethodCall = typeof options === "string",
args = slice.call( arguments, 1 ),
returnValue = this;
// allow multiple hashes to be passed on init
options = !isMethodCall && args.length ?
$.widget.extend.apply( null, [ options ].concat(args) ) :
options;
if ( isMethodCall ) {
this.each(function() {
var methodValue,
instance = $.data( this, fullName );
if ( !instance ) {
return $.error( "cannot call methods on " + name + " prior to initialization; " +
"attempted to call method '" + options + "'" );
}
if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
}
methodValue = instance[ options ].apply( instance, args );
if ( methodValue !== instance && methodValue !== undefined ) {
returnValue = methodValue && methodValue.jquery ?
returnValue.pushStack( methodValue.get() ) :
methodValue;
return false;
}
});
} else {
this.each(function() {
var instance = $.data( this, fullName );
if ( instance ) {
instance.option( options || {} )._init();
} else {
new object( options, this );
}
});
}
return returnValue;
};
};
$.Widget = function( /* options, element */ ) {};
$.Widget._childConstructors = [];
$.Widget.prototype = {
widgetName: "widget",
widgetEventPrefix: "",
defaultElement: "<div>",
options: {
disabled: false,
// callbacks
create: null
},
_createWidget: function( options, element ) {
element = $( element || this.defaultElement || this )[ 0 ];
this.element = $( element );
this.uuid = uuid++;
this.eventNamespace = "." + this.widgetName + this.uuid;
this.options = $.widget.extend( {},
this.options,
this._getCreateOptions(),
options );
this.bindings = $();
this.hoverable = $();
this.focusable = $();
if ( element !== this ) {
// 1.9 BC for #7810
// TODO remove dual storage
$.data( element, this.widgetName, this );
$.data( element, this.widgetFullName, this );
this._on( this.element, {
remove: function( event ) {
if ( event.target === element ) {
this.destroy();
}
}
});
this.document = $( element.style ?
// element within the document
element.ownerDocument :
// element is window or document
element.document || element );
this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
}
this._create();
this._trigger( "create", null, this._getCreateEventData() );
this._init();
},
_getCreateOptions: $.noop,
_getCreateEventData: $.noop,
_create: $.noop,
_init: $.noop,
destroy: function() {
this._destroy();
// we can probably remove the unbind calls in 2.0
// all event bindings should go through this._on()
this.element
.unbind( this.eventNamespace )
// 1.9 BC for #7810
// TODO remove dual storage
.removeData( this.widgetName )
.removeData( this.widgetFullName )
// support: jquery <1.6.3
// http://bugs.jquery.com/ticket/9413
.removeData( $.camelCase( this.widgetFullName ) );
this.widget()
.unbind( this.eventNamespace )
.removeAttr( "aria-disabled" )
.removeClass(
this.widgetFullName + "-disabled " +
"ui-state-disabled" );
// clean up events and states
this.bindings.unbind( this.eventNamespace );
this.hoverable.removeClass( "ui-state-hover" );
this.focusable.removeClass( "ui-state-focus" );
},
_destroy: $.noop,
widget: function() {
return this.element;
},
option: function( key, value ) {
var options = key,
parts,
curOption,
i;
if ( arguments.length === 0 ) {
// don't return a reference to the internal hash
return $.widget.extend( {}, this.options );
}
if ( typeof key === "string" ) {
// handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
options = {};
parts = key.split( "." );
key = parts.shift();
if ( parts.length ) {
curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
for ( i = 0; i < parts.length - 1; i++ ) {
curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
curOption = curOption[ parts[ i ] ];
}
key = parts.pop();
if ( value === undefined ) {
return curOption[ key ] === undefined ? null : curOption[ key ];
}
curOption[ key ] = value;
} else {
if ( value === undefined ) {
return this.options[ key ] === undefined ? null : this.options[ key ];
}
options[ key ] = value;
}
}
this._setOptions( options );
return this;
},
_setOptions: function( options ) {
var key;
for ( key in options ) {
this._setOption( key, options[ key ] );
}
return this;
},
_setOption: function( key, value ) {
this.options[ key ] = value;
if ( key === "disabled" ) {
this.widget()
.toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
.attr( "aria-disabled", value );
this.hoverable.removeClass( "ui-state-hover" );
this.focusable.removeClass( "ui-state-focus" );
}
return this;
},
enable: function() {
return this._setOption( "disabled", false );
},
disable: function() {
return this._setOption( "disabled", true );
},
_on: function( element, handlers ) {
var delegateElement,
instance = this;
// no element argument, shuffle and use this.element
if ( !handlers ) {
handlers = element;
element = this.element;
delegateElement = this.widget();
} else {
// accept selectors, DOM elements
element = delegateElement = $( element );
this.bindings = this.bindings.add( element );
}
$.each( handlers, function( event, handler ) {
function handlerProxy() {
// allow widgets to customize the disabled handling
// - disabled as an array instead of boolean
// - disabled class as method for disabling individual parts
if ( instance.options.disabled === true ||
$( this ).hasClass( "ui-state-disabled" ) ) {
return;
}
return ( typeof handler === "string" ? instance[ handler ] : handler )
.apply( instance, arguments );
}
// copy the guid so direct unbinding works
if ( typeof handler !== "string" ) {
handlerProxy.guid = handler.guid =
handler.guid || handlerProxy.guid || $.guid++;
}
var match = event.match( /^(\w+)\s*(.*)$/ ),
eventName = match[1] + instance.eventNamespace,
selector = match[2];
if ( selector ) {
delegateElement.delegate( selector, eventName, handlerProxy );
} else {
element.bind( eventName, handlerProxy );
}
});
},
_off: function( element, eventName ) {
eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
element.unbind( eventName ).undelegate( eventName );
},
_delay: function( handler, delay ) {
function handlerProxy() {
return ( typeof handler === "string" ? instance[ handler ] : handler )
.apply( instance, arguments );
}
var instance = this;
return setTimeout( handlerProxy, delay || 0 );
},
_hoverable: function( element ) {
this.hoverable = this.hoverable.add( element );
this._on( element, {
mouseenter: function( event ) {
$( event.currentTarget ).addClass( "ui-state-hover" );
},
mouseleave: function( event ) {
$( event.currentTarget ).removeClass( "ui-state-hover" );
}
});
},
_focusable: function( element ) {
this.focusable = this.focusable.add( element );
this._on( element, {
focusin: function( event ) {
$( event.currentTarget ).addClass( "ui-state-focus" );
},
focusout: function( event ) {
$( event.currentTarget ).removeClass( "ui-state-focus" );
}
});
},
_trigger: function( type, event, data ) {
var prop, orig,
callback = this.options[ type ];
data = data || {};
event = $.Event( event );
event.type = ( type === this.widgetEventPrefix ?
type :
this.widgetEventPrefix + type ).toLowerCase();
// the original event may come from any element
// so we need to reset the target on the new event
event.target = this.element[ 0 ];
// copy original event properties over to the new event
orig = event.originalEvent;
if ( orig ) {
for ( prop in orig ) {
if ( !( prop in event ) ) {
event[ prop ] = orig[ prop ];
}
}
}
this.element.trigger( event, data );
return !( $.isFunction( callback ) &&
callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
event.isDefaultPrevented() );
}
};
$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
$.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
if ( typeof options === "string" ) {
options = { effect: options };
}
var hasOptions,
effectName = !options ?
method :
options === true || typeof options === "number" ?
defaultEffect :
options.effect || defaultEffect;
options = options || {};
if ( typeof options === "number" ) {
options = { duration: options };
}
hasOptions = !$.isEmptyObject( options );
options.complete = callback;
if ( options.delay ) {
element.delay( options.delay );
}
if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) {
element[ method ]( options );
} else if ( effectName !== method && element[ effectName ] ) {
element[ effectName ]( options.duration, options.easing, callback );
} else {
element.queue(function( next ) {
$( this )[ method ]();
if ( callback ) {
callback.call( element[ 0 ] );
}
next();
});
}
};
});
// DEPRECATED
if ( $.uiBackCompat !== false ) {
$.Widget.prototype._getCreateOptions = function() {
return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
};
}
}));

View File

@ -1,51 +0,0 @@
function init_upload_fields(id)
{
$('#note_file_upload_field_'+id).fileUploadUI({
uploadTable: $('#files_'+id),
namespace : "note_file_upload_"+id,
downloadTable: $('#files'+id),
dragDropSupport : true,
onLoad : function (event, files, index, xhr, handler){
var json;
if (typeof xhr.responseText !== "undefinied") {
eval(xhr.responseText);
} else {
eval(xhr.contents().text());
}
handler.uploadRow.remove();
},
onLoadAll: function (){
$('#data_files_'+id+' .new').each(function (){
$(this).removeClass("new");
});
},
buildUploadRow: function (files, index) {
return $('<tr><td>' + files[index].name + '<\/td>' +
'<td class="file_upload_progress"><div><\/div><\/td>' +
'<td class="file_upload_cancel">' +
'annuler' +
'<\/td><\/tr>');
}
});
}
$(document).ready(function ($) {
//init_upload_fields();
});

View File

@ -1,490 +0,0 @@
/*
* jQuery File Upload User Interface Plugin 4.2.1
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://creativecommons.org/licenses/MIT/
*/
/*jslint browser: true */
/*global jQuery, FileReader, URL, webkitURL */
(function ($) {
var undef = 'undefined',
func = 'function',
UploadHandler,
methods,
MultiLoader = function (callBack) {
var loaded = 0,
list = [];
this.complete = function () {
loaded += 1;
if (loaded === list.length + 1) {
// list.length * onComplete + 1 * onLoadAll
callBack(list);
loaded = 0;
list = [];
}
};
this.push = function (item) {
list.push(item);
};
this.getList = function () {
return list;
};
};
UploadHandler = function (container, options) {
var uploadHandler = this,
dragOverTimeout,
isDropZoneEnlarged,
multiLoader = new MultiLoader(function (list) {
uploadHandler.hideProgressBarAll(function () {
uploadHandler.resetProgressBarAll();
if (typeof uploadHandler.onCompleteAll === func) {
uploadHandler.onCompleteAll(list);
}
});
}),
getUploadTable = function (handler) {
return typeof handler.uploadTable === func ?
handler.uploadTable(handler) : handler.uploadTable;
},
getDownloadTable = function (handler) {
return typeof handler.downloadTable === func ?
handler.downloadTable(handler) : handler.downloadTable;
};
this.requestHeaders = {'Accept': 'application/json, text/javascript, */*; q=0.01'};
this.dropZone = container;
this.imageTypes = /^image\/(gif|jpeg|png)$/;
this.previewMaxWidth = this.previewMaxHeight = 80;
this.previewLoadDelay = 100;
this.previewAsCanvas = true;
this.previewSelector = '.file_upload_preview';
this.progressSelector = '.file_upload_progress div';
this.cancelSelector = '.file_upload_cancel img';
this.cssClassSmall = 'file_upload_small';
this.cssClassLarge = 'file_upload_large';
this.cssClassHighlight = 'file_upload_highlight';
this.dropEffect = 'highlight';
this.uploadTable = this.downloadTable = null;
this.buildUploadRow = this.buildDownloadRow = null;
this.progressAllNode = null;
this.loadImage = function (file, callBack, maxWidth, maxHeight, imageTypes, noCanvas) {
var img,
scaleImage,
urlAPI,
fileReader;
if (imageTypes && !imageTypes.test(file.type)) {
return null;
}
scaleImage = function (img) {
var canvas = document.createElement('canvas'),
scale = Math.min(
(maxWidth || img.width) / img.width,
(maxHeight || img.height) / img.height
);
if (scale > 1) {
scale = 1;
}
img.width = parseInt(img.width * scale, 10);
img.height = parseInt(img.height * scale, 10);
if (noCanvas || typeof canvas.getContext !== func) {
return img;
}
canvas.width = img.width;
canvas.height = img.height;
canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
return canvas;
};
img = document.createElement('img');
urlAPI = typeof URL !== undef ? URL : typeof webkitURL !== undef ? webkitURL : null;
if (urlAPI && typeof urlAPI.createObjectURL === func) {
img.onload = function () {
urlAPI.revokeObjectURL(this.src);
callBack(scaleImage(img));
};
img.src = urlAPI.createObjectURL(file);
} else if (typeof FileReader !== undef &&
typeof FileReader.prototype.readAsDataURL === func) {
img.onload = function () {
callBack(scaleImage(img));
};
fileReader = new FileReader();
fileReader.onload = function (e) {
img.src = e.target.result;
};
fileReader.readAsDataURL(file);
} else {
callBack(null);
}
};
this.addNode = function (parentNode, node, callBack) {
if (parentNode && node) {
node.css('display', 'none').appendTo(parentNode).fadeIn(function () {
if (typeof callBack === func) {
try {
callBack();
} catch (e) {
// Fix endless exception loop:
node.stop();
throw e;
}
}
});
} else if (typeof callBack === func) {
callBack();
}
};
this.removeNode = function (node, callBack) {
if (node) {
node.fadeOut(function () {
node.remove();
if (typeof callBack === func) {
try {
callBack();
} catch (e) {
// Fix endless exception loop:
node.stop();
throw e;
}
}
});
} else if (typeof callBack === func) {
callBack();
}
};
this.replaceNode = function (oldNode, newNode, callBack) {
if (oldNode && newNode) {
oldNode.fadeOut(function () {
newNode.css('display', 'none');
oldNode.replaceWith(newNode);
newNode.fadeIn(function () {
if (typeof callBack === func) {
try {
callBack();
} catch (e) {
// Fix endless exception loop:
oldNode.stop();
newNode.stop();
throw e;
}
}
});
});
} else if (typeof callBack === func) {
callBack();
}
};
this.resetProgressBarAll = function () {
if (uploadHandler.progressbarAll) {
uploadHandler.progressbarAll.progressbar(
'value',
0
);
}
};
this.hideProgressBarAll = function (callBack) {
if (uploadHandler.progressbarAll && !$(getUploadTable(uploadHandler))
.find(uploadHandler.progressSelector + ':visible:first').length) {
uploadHandler.progressbarAll.fadeOut(callBack);
} else if (typeof callBack === func) {
callBack();
}
};
this.onAbort = function (event, files, index, xhr, handler) {
handler.removeNode(handler.uploadRow, handler.hideProgressBarAll);
};
this.cancelUpload = function (event, files, index, xhr, handler) {
var readyState = xhr.readyState;
xhr.abort();
// If readyState is below 2, abort() has no effect:
if (typeof readyState !== 'number' || readyState < 2) {
handler.onAbort(event, files, index, xhr, handler);
}
};
this.initProgressBar = function (node, value) {
if (!node || !node.length) {
return null;
}
if (typeof node.progressbar === func) {
return node.progressbar({
value: value
});
} else {
var progressbar = $('<progress value="' + value + '" max="100"/>').appendTo(node);
progressbar.progressbar = function (key, value) {
progressbar.attr('value', value);
};
return progressbar;
}
};
this.initUploadProgress = function (xhr, handler) {
if (!xhr.upload && handler.progressbar) {
handler.progressbar.progressbar(
'value',
100 // indeterminate progress displayed by a full animated progress bar
);
}
};
this.onSend = function (event, files, index, xhr, handler) {
handler.initUploadProgress(xhr, handler);
};
this.onProgressAll = function (event, list) {
if (uploadHandler.progressbarAll && event.lengthComputable) {
uploadHandler.progressbarAll.progressbar(
'value',
parseInt(event.loaded / event.total * 100, 10)
);
}
};
this.onProgress = function (event, files, index, xhr, handler) {
if (handler.progressbar && event.lengthComputable) {
handler.progressbar.progressbar(
'value',
parseInt(event.loaded / event.total * 100, 10)
);
}
};
this.onLoadAll = function (list) {
multiLoader.complete();
};
this.initProgressBarAll = function () {
if (!uploadHandler.progressbarAll) {
uploadHandler.progressbarAll = uploadHandler.initProgressBar(
(typeof uploadHandler.progressAllNode === func ?
uploadHandler.progressAllNode(uploadHandler) : uploadHandler.progressAllNode),
0
);
}
if (uploadHandler.progressbarAll && uploadHandler.progressbarAll.is(':hidden')) {
uploadHandler.progressbarAll.fadeIn();
}
};
this.initUploadRow = function (event, files, index, xhr, handler) {
var uploadRow = handler.uploadRow = (typeof handler.buildUploadRow === func ?
handler.buildUploadRow(files, index, handler) : null);
if (uploadRow) {
handler.progressbar = handler.initProgressBar(
uploadRow.find(handler.progressSelector),
0
);
uploadRow.find(handler.cancelSelector).click(function (e) {
handler.cancelUpload(e, files, index, xhr, handler);
return false;
});
uploadRow.find(handler.previewSelector).each(function () {
var previewNode = $(this),
file = files[index];
if (file) {
setTimeout(function () {
handler.loadImage(
file,
function (img) {
handler.addNode(
previewNode,
$(img)
);
},
handler.previewMaxWidth,
handler.previewMaxHeight,
handler.imageTypes,
!handler.previewAsCanvas
);
}, handler.previewLoadDelay);
}
});
}
};
this.initUpload = function (event, files, index, xhr, handler, callBack) {
handler.initUploadRow(event, files, index, xhr, handler);
handler.addNode(
getUploadTable(handler),
handler.uploadRow,
function () {
if (typeof handler.beforeSend === func) {
handler.beforeSend(event, files, index, xhr, handler, callBack);
} else {
callBack();
}
}
);
handler.initProgressBarAll();
};
this.parseResponse = function (xhr) {
if (typeof xhr.responseText !== undef) {
return $.parseJSON(xhr.responseText);
} else {
// Instead of an XHR object, an iframe is used for legacy browsers:
return $.parseJSON(xhr.contents().text());
}
};
this.initDownloadRow = function (event, files, index, xhr, handler) {
var json, downloadRow;
try {
json = handler.response = handler.parseResponse(xhr);
downloadRow = handler.downloadRow = (typeof handler.buildDownloadRow === func ?
handler.buildDownloadRow(json, handler) : null);
} catch (e) {
if (typeof handler.onError === func) {
handler.originalEvent = event;
handler.onError(e, files, index, xhr, handler);
} else {
throw e;
}
}
};
this.onLoad = function (event, files, index, xhr, handler) {
var uploadTable = getUploadTable(handler),
downloadTable = getDownloadTable(handler),
callBack = function () {
if (typeof handler.onComplete === func) {
handler.onComplete(event, files, index, xhr, handler);
}
multiLoader.complete();
};
multiLoader.push(Array.prototype.slice.call(arguments, 1));
handler.initDownloadRow(event, files, index, xhr, handler);
if (uploadTable && (!downloadTable || uploadTable.get(0) === downloadTable.get(0))) {
handler.replaceNode(handler.uploadRow, handler.downloadRow, callBack);
} else {
handler.removeNode(handler.uploadRow, function () {
handler.addNode(
downloadTable,
handler.downloadRow,
callBack
);
});
}
};
this.dropZoneEnlarge = function () {
if (!isDropZoneEnlarged) {
if (typeof uploadHandler.dropZone.switchClass === func) {
uploadHandler.dropZone.switchClass(
uploadHandler.cssClassSmall,
uploadHandler.cssClassLarge
);
} else {
uploadHandler.dropZone.addClass(uploadHandler.cssClassLarge);
uploadHandler.dropZone.removeClass(uploadHandler.cssClassSmall);
}
isDropZoneEnlarged = true;
}
};
this.dropZoneReduce = function () {
if (typeof uploadHandler.dropZone.switchClass === func) {
uploadHandler.dropZone.switchClass(
uploadHandler.cssClassLarge,
uploadHandler.cssClassSmall
);
} else {
uploadHandler.dropZone.addClass(uploadHandler.cssClassSmall);
uploadHandler.dropZone.removeClass(uploadHandler.cssClassLarge);
}
isDropZoneEnlarged = false;
};
this.onDocumentDragEnter = function (event) {
uploadHandler.dropZoneEnlarge();
};
this.onDocumentDragOver = function (event) {
if (dragOverTimeout) {
clearTimeout(dragOverTimeout);
}
dragOverTimeout = setTimeout(function () {
uploadHandler.dropZoneReduce();
}, 200);
};
this.onDragEnter = this.onDragLeave = function (event) {
uploadHandler.dropZone.toggleClass(uploadHandler.cssClassHighlight);
};
this.onDrop = function (event) {
if (dragOverTimeout) {
clearTimeout(dragOverTimeout);
}
if (uploadHandler.dropEffect && typeof uploadHandler.dropZone.effect === func) {
//uploadHandler.dropZone.effect(uploadHandler.dropEffect, function () {
//uploadHandler.dropZone.removeClass(uploadHandler.cssClassHighlight);
uploadHandler.dropZoneReduce();
uploadHandler.dropZone.toggleClass(uploadHandler.cssClassHighlight);
//});
} else {
//uploadHandler.dropZone.removeClass(uploadHandler.cssClassHighlight);
uploadHandler.dropZoneReduce();
}
};
$.extend(this, options);
};
methods = {
init : function (options) {
return this.each(function () {
$(this).fileUpload(new UploadHandler($(this), options));
});
},
option: function (option, value, namespace) {
if (!option || (typeof option === 'string' && typeof value === undef)) {
return $(this).fileUpload('option', option, value, namespace);
}
return this.each(function () {
$(this).fileUpload('option', option, value, namespace);
});
},
destroy : function (namespace) {
return this.each(function () {
$(this).fileUpload('destroy', namespace);
});
},
upload: function (files, namespace) {
return this.each(function () {
$(this).fileUpload('upload', files, namespace);
});
}
};
$.fn.fileUploadUI = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method "' + method + '" does not exist on jQuery.fileUploadUI');
}
};
}(jQuery));

View File

@ -1,906 +0,0 @@
/*
* jQuery File Upload Plugin 4.2.1
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://creativecommons.org/licenses/MIT/
*/
/*jslint browser: true */
/*global XMLHttpRequestUpload, File, FileReader, FormData, ProgressEvent, unescape, jQuery, upload */
(function ($) {
var defaultNamespace = 'file_upload',
undef = 'undefined',
func = 'function',
FileUpload,
methods,
MultiLoader = function (callBack, numOrList) {
var loaded = 0,
list = [];
if (numOrList) {
if (numOrList.length) {
list = numOrList;
} else {
list[numOrList - 1] = null;
}
}
this.complete = function () {
loaded += 1;
if (loaded === list.length) {
callBack(list);
loaded = 0;
list = [];
}
};
this.push = function (item) {
list.push(item);
};
this.getList = function () {
return list;
};
},
SequenceHandler = function () {
var sequence = [];
this.push = function (callBack) {
sequence.push(callBack);
if (sequence.length === 1) {
callBack();
}
};
this.next = function () {
sequence.shift();
if (sequence.length) {
sequence[0]();
}
};
};
FileUpload = function (container) {
var fileUpload = this,
uploadForm,
fileInput,
settings = {
namespace: defaultNamespace,
uploadFormFilter: function (index) {
return true;
},
fileInputFilter: function (index) {
return true;
},
cssClass: defaultNamespace,
dragDropSupport: true,
dropZone: container,
url: function (form) {
return form.attr('action');
},
method: function (form) {
return form.attr('method');
},
fieldName: function (input) {
return input.attr('name');
},
formData: function (form) {
return form.serializeArray();
},
requestHeaders: null,
multipart: true,
multiFileRequest: false,
withCredentials: false,
forceIframeUpload: false,
sequentialUploads: false,
maxChunkSize: null
},
multiLoader = new MultiLoader(function (list) {
if (typeof settings.onLoadAll === func) {
settings.onLoadAll(list);
}
}),
sequenceHandler = new SequenceHandler(),
documentListeners = {},
dropZoneListeners = {},
protocolRegExp = /^http(s)?:\/\//,
optionsReference,
isXHRUploadCapable = function () {
return typeof XMLHttpRequest !== undef && typeof XMLHttpRequestUpload !== undef &&
typeof File !== undef && (!settings.multipart || typeof FormData !== undef ||
(typeof FileReader !== undef && typeof XMLHttpRequest.prototype.sendAsBinary === func));
},
initEventHandlers = function () {
if (settings.dragDropSupport) {
if (typeof settings.onDocumentDragEnter === func) {
documentListeners['dragenter.' + settings.namespace] = function (e) {
settings.onDocumentDragEnter(e);
};
}
if (typeof settings.onDocumentDragLeave === func) {
documentListeners['dragleave.' + settings.namespace] = function (e) {
settings.onDocumentDragLeave(e);
};
}
documentListeners['dragover.' + settings.namespace] = fileUpload.onDocumentDragOver;
documentListeners['drop.' + settings.namespace] = fileUpload.onDocumentDrop;
$(document).bind(documentListeners);
if (typeof settings.onDragEnter === func) {
dropZoneListeners['dragenter.' + settings.namespace] = function (e) {
settings.onDragEnter(e);
};
}
if (typeof settings.onDragLeave === func) {
dropZoneListeners['dragleave.' + settings.namespace] = function (e) {
settings.onDragLeave(e);
};
}
dropZoneListeners['dragover.' + settings.namespace] = fileUpload.onDragOver;
dropZoneListeners['drop.' + settings.namespace] = fileUpload.onDrop;
settings.dropZone.bind(dropZoneListeners);
}
fileInput.bind('change.' + settings.namespace, fileUpload.onChange);
},
removeEventHandlers = function () {
$.each(documentListeners, function (key, value) {
$(document).unbind(key, value);
});
$.each(dropZoneListeners, function (key, value) {
settings.dropZone.unbind(key, value);
});
fileInput.unbind('change.' + settings.namespace);
},
isChunkedUpload = function (settings) {
return typeof settings.uploadedBytes !== undef;
},
createProgressEvent = function (lengthComputable, loaded, total) {
var event;
if (typeof document.createEvent === func && typeof ProgressEvent !== undef) {
event = document.createEvent('ProgressEvent');
event.initProgressEvent(
'progress',
false,
false,
lengthComputable,
loaded,
total
);
} else {
event = {
lengthComputable: true,
loaded: loaded,
total: total
};
}
return event;
},
getProgressTotal = function (files, index, settings) {
var i,
total;
if (typeof settings.progressTotal === undef) {
if (files[index]) {
total = files[index].size;
settings.progressTotal = total ? total : 1;
} else {
total = 0;
for (i = 0; i < files.length; i += 1) {
total += files[i].size;
}
settings.progressTotal = total;
}
}
return settings.progressTotal;
},
handleGlobalProgress = function (event, files, index, xhr, settings) {
var progressEvent,
loaderList,
globalLoaded = 0,
globalTotal = 0;
if (event.lengthComputable && typeof settings.onProgressAll === func) {
settings.progressLoaded = parseInt(
event.loaded / event.total * getProgressTotal(files, index, settings),
10
);
loaderList = multiLoader.getList();
$.each(loaderList, function (index, item) {
// item is an array with [files, index, xhr, settings]
globalLoaded += item[3].progressLoaded || 0;
globalTotal += getProgressTotal(item[0], item[1], item[3]);
});
progressEvent = createProgressEvent(
true,
globalLoaded,
globalTotal
);
settings.onProgressAll(progressEvent, loaderList);
}
},
handleLoadEvent = function (event, files, index, xhr, settings) {
var progressEvent;
if (isChunkedUpload(settings)) {
settings.uploadedBytes = settings.uploadedBytes + settings.chunkSize;
progressEvent = createProgressEvent(
true,
settings.uploadedBytes,
files[index].size
);
if (typeof settings.onProgress === func) {
settings.onProgress(progressEvent, files, index, xhr, settings);
}
handleGlobalProgress(progressEvent, files, index, xhr, settings);
if (settings.uploadedBytes < files[index].size) {
if (typeof settings.resumeUpload === func) {
settings.resumeUpload(
event,
files,
index,
xhr,
settings,
function () {
upload(event, files, index, xhr, settings, true);
}
);
} else {
upload(event, files, index, xhr, settings, true);
}
return;
}
}
settings.progressLoaded = getProgressTotal(files, index, settings);
if (typeof settings.onLoad === func) {
settings.onLoad(event, files, index, xhr, settings);
}
multiLoader.complete();
sequenceHandler.next();
},
handleProgressEvent = function (event, files, index, xhr, settings) {
var progressEvent = event;
if (isChunkedUpload(settings) && event.lengthComputable) {
progressEvent = createProgressEvent(
true,
settings.uploadedBytes + parseInt(event.loaded / event.total * settings.chunkSize, 10),
files[index].size
);
}
if (typeof settings.onProgress === func) {
settings.onProgress(progressEvent, files, index, xhr, settings);
}
handleGlobalProgress(progressEvent, files, index, xhr, settings);
},
initUploadEventHandlers = function (files, index, xhr, settings) {
if (xhr.upload) {
xhr.upload.onprogress = function (e) {
handleProgressEvent(e, files, index, xhr, settings);
};
}
xhr.onload = function (e) {
handleLoadEvent(e, files, index, xhr, settings);
};
xhr.onabort = function (e) {
settings.progressTotal = settings.progressLoaded;
if (typeof settings.onAbort === func) {
settings.onAbort(e, files, index, xhr, settings);
}
multiLoader.complete();
sequenceHandler.next();
};
xhr.onerror = function (e) {
settings.progressTotal = settings.progressLoaded;
if (typeof settings.onError === func) {
settings.onError(e, files, index, xhr, settings);
}
multiLoader.complete();
sequenceHandler.next();
};
},
getUrl = function (settings) {
if (typeof settings.url === func) {
return settings.url(settings.uploadForm || uploadForm);
}
return settings.url;
},
getMethod = function (settings) {
if (typeof settings.method === func) {
return settings.method(settings.uploadForm || uploadForm);
}
return settings.method;
},
getFieldName = function (settings) {
if (typeof settings.fieldName === func) {
return settings.fieldName(settings.fileInput || fileInput);
}
return settings.fieldName;
},
getFormData = function (settings) {
var formData;
if (typeof settings.formData === func) {
return settings.formData(settings.uploadForm || uploadForm);
} else if ($.isArray(settings.formData)) {
return settings.formData;
} else if (settings.formData) {
formData = [];
$.each(settings.formData, function (name, value) {
formData.push({name: name, value: value});
});
return formData;
}
return [];
},
isSameDomain = function (url) {
if (protocolRegExp.test(url)) {
var host = location.host,
indexStart = location.protocol.length + 2,
index = url.indexOf(host, indexStart),
pathIndex = index + host.length;
if ((index === indexStart || index === url.indexOf('@', indexStart) + 1) &&
(url.length === pathIndex || $.inArray(url.charAt(pathIndex), ['/', '?', '#']) !== -1)) {
return true;
}
return false;
}
return true;
},
initUploadRequest = function (files, index, xhr, settings) {
var file = files[index],
url = getUrl(settings),
sameDomain = isSameDomain(url);
xhr.open(getMethod(settings), url, true);
if (sameDomain) {
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
if (!settings.multipart || isChunkedUpload(settings)) {
xhr.setRequestHeader('X-File-Name', file.name);
xhr.setRequestHeader('X-File-Type', file.type);
xhr.setRequestHeader('X-File-Size', file.size);
if (!isChunkedUpload(settings)) {
xhr.setRequestHeader('Content-Type', file.type);
} else if (!settings.multipart) {
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
}
}
} else if (settings.withCredentials) {
xhr.withCredentials = true;
}
if ($.isArray(settings.requestHeaders)) {
$.each(settings.requestHeaders, function (index, header) {
xhr.setRequestHeader(header.name, header.value);
});
} else if (settings.requestHeaders) {
$.each(settings.requestHeaders, function (name, value) {
xhr.setRequestHeader(name, value);
});
}
},
formDataUpload = function (files, xhr, settings) {
var formData = new FormData(),
i;
$.each(getFormData(settings), function (index, field) {
formData.append(field.name, field.value);
});
for (i = 0; i < files.length; i += 1) {
formData.append(getFieldName(settings), files[i]);
}
xhr.send(formData);
},
loadFileContent = function (file, callBack) {
var fileReader = new FileReader();
fileReader.onload = function (e) {
file.content = e.target.result;
callBack();
};
fileReader.readAsBinaryString(file);
},
utf8encode = function (str) {
return unescape(encodeURIComponent(str));
},
buildMultiPartFormData = function (boundary, files, filesFieldName, fields) {
var doubleDash = '--',
crlf = '\r\n',
formData = '';
$.each(fields, function (index, field) {
formData += doubleDash + boundary + crlf +
'Content-Disposition: form-data; name="' +
utf8encode(field.name) +
'"' + crlf + crlf +
utf8encode(field.value) + crlf;
});
$.each(files, function (index, file) {
formData += doubleDash + boundary + crlf +
'Content-Disposition: form-data; name="' +
utf8encode(filesFieldName) +
'"; filename="' + utf8encode(file.name) + '"' + crlf +
'Content-Type: ' + utf8encode(file.type) + crlf + crlf +
file.content + crlf;
});
formData += doubleDash + boundary + doubleDash + crlf;
return formData;
},
fileReaderUpload = function (files, xhr, settings) {
var boundary = '----MultiPartFormBoundary' + (new Date()).getTime(),
loader,
i;
xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
loader = new MultiLoader(function () {
xhr.sendAsBinary(buildMultiPartFormData(
boundary,
files,
getFieldName(settings),
getFormData(settings)
));
}, files.length);
for (i = 0; i < files.length; i += 1) {
loadFileContent(files[i], loader.complete);
}
},
getBlob = function (file, settings) {
var blob,
ub = settings.uploadedBytes,
mcs = settings.maxChunkSize;
if (file && typeof file.slice === func && (ub || (mcs && mcs < file.size))) {
settings.uploadedBytes = ub = ub || 0;
blob = file.slice(ub, mcs || file.size - ub);
settings.chunkSize = blob.size;
return blob;
}
return file;
},
upload = function (event, files, index, xhr, settings, nextChunk) {
var send;
if (!nextChunk) {
if (typeof settings.onSend === func &&
settings.onSend(event, files, index, xhr, settings) === false) {
return;
}
multiLoader.push(Array.prototype.slice.call(arguments, 1));
}
send = function () {
var blob = getBlob(files[index], settings),
filesToUpload;
initUploadEventHandlers(files, index, xhr, settings);
initUploadRequest(files, index, xhr, settings);
if (!settings.multipart) {
if (xhr.upload) {
xhr.send(blob);
} else {
$.error('Browser does not support XHR file uploads');
}
} else {
filesToUpload = (typeof index === 'number') ? [blob] : files;
if (typeof FormData !== undef) {
formDataUpload(filesToUpload, xhr, settings);
} else if (typeof FileReader !== undef && typeof xhr.sendAsBinary === func) {
fileReaderUpload(filesToUpload, xhr, settings);
} else {
$.error('Browser does not support multipart/form-data XHR file uploads');
}
}
};
if (!nextChunk && settings.sequentialUploads) {
sequenceHandler.push(send);
} else {
send();
}
},
handleUpload = function (event, files, input, form, index) {
var xhr = new XMLHttpRequest(),
uploadSettings = $.extend({}, settings);
uploadSettings.fileInput = input;
uploadSettings.uploadForm = form;
if (typeof uploadSettings.initUpload === func) {
uploadSettings.initUpload(
event,
files,
index,
xhr,
uploadSettings,
function () {
upload(event, files, index, xhr, uploadSettings);
}
);
} else {
upload(event, files, index, xhr, uploadSettings);
}
},
handleFiles = function (event, files, input, form) {
var i;
files = Array.prototype.slice.call(files, 0);
if (settings.multiFileRequest && settings.multipart && files.length) {
handleUpload(event, files, input, form);
} else {
for (i = 0; i < files.length; i += 1) {
handleUpload(event, files, input, form, i);
}
}
},
handleLegacyGlobalProgress = function (event, files, index, iframe, settings) {
var total = files[index].size ? files[index].size : 1,
progressEvent = createProgressEvent(true, total, total);
settings.progressLoaded = total;
handleGlobalProgress(progressEvent, files, index, iframe, settings);
},
legacyUploadFormDataInit = function (input, form, settings) {
var formData = getFormData(settings);
form.find(':input').not(':disabled')
.attr('disabled', true)
.addClass(settings.namespace + '_disabled');
$.each(formData, function (index, field) {
$('<input type="hidden"/>')
.attr('name', field.name)
.val(field.value)
.addClass(settings.namespace + '_form_data')
.appendTo(form);
});
input
.attr('name', getFieldName(settings))
.appendTo(form);
},
legacyUploadFormDataReset = function (input, form, settings) {
input.detach();
form.find('.' + settings.namespace + '_disabled')
.removeAttr('disabled')
.removeClass(settings.namespace + '_disabled');
form.find('.' + settings.namespace + '_form_data').remove();
},
legacyUpload = function (event, files, input, form, iframe, settings) {
var send;
if (typeof settings.onSend === func && settings.onSend(event, files, 0, iframe, settings) === false) {
return;
}
multiLoader.push([files, 0, iframe, settings]);
send = function () {
var originalAction = form.attr('action'),
originalMethod = form.attr('method'),
originalTarget = form.attr('target');
iframe
.unbind('abort')
.bind('abort', function (e) {
iframe.readyState = 0;
// javascript:false as iframe src prevents warning popups on HTTPS in IE6
// concat is used here to prevent the "Script URL" JSLint error:
iframe.unbind('load').attr('src', 'javascript'.concat(':false;'));
handleLegacyGlobalProgress(e, files, 0, iframe, settings);
if (typeof settings.onAbort === func) {
settings.onAbort(e, files, 0, iframe, settings);
}
multiLoader.complete();
sequenceHandler.next();
})
.unbind('load')
.bind('load', function (e) {
iframe.readyState = 4;
handleLegacyGlobalProgress(e, files, 0, iframe, settings);
if (typeof settings.onLoad === func) {
settings.onLoad(e, files, 0, iframe, settings);
}
multiLoader.complete();
sequenceHandler.next();
// Fix for IE endless progress bar activity bug
// (happens on form submits to iframe targets):
$('<iframe src="javascript:false;" style="display:none"></iframe>')
.appendTo(form).remove();
});
form
.attr('action', getUrl(settings))
.attr('method', getMethod(settings))
.attr('target', iframe.attr('name'));
legacyUploadFormDataInit(input, form, settings);
iframe.readyState = 2;
form.get(0).submit();
legacyUploadFormDataReset(input, form, settings);
form
.attr('action', originalAction)
.attr('method', originalMethod)
.attr('target', originalTarget);
};
if (settings.sequentialUploads) {
sequenceHandler.push(send);
} else {
send();
}
},
handleLegacyUpload = function (event, input, form) {
// javascript:false as iframe src prevents warning popups on HTTPS in IE6:
var iframe = $('<iframe src="javascript:false;" style="display:none" name="iframe_' +
settings.namespace + '_' + (new Date()).getTime() + '"></iframe>'),
uploadSettings = $.extend({}, settings),
files = event.target.files;
files = files ? Array.prototype.slice.call(files, 0) : [{name: input.val(), type: null, size: null}];
uploadSettings.fileInput = input;
uploadSettings.uploadForm = form;
iframe.readyState = 0;
iframe.abort = function () {
iframe.trigger('abort');
};
iframe.bind('load', function () {
iframe.unbind('load');
if (typeof uploadSettings.initUpload === func) {
uploadSettings.initUpload(
event,
files,
0,
iframe,
uploadSettings,
function () {
legacyUpload(event, files, input, form, iframe, uploadSettings);
}
);
} else {
legacyUpload(event, files, input, form, iframe, uploadSettings);
}
}).appendTo(form);
},
initUploadForm = function () {
uploadForm = (container.is('form') ? container : container.find('form'))
.filter(settings.uploadFormFilter);
},
initFileInput = function () {
fileInput = (uploadForm.length ? uploadForm : container).find('input:file')
.filter(settings.fileInputFilter);
},
replaceFileInput = function (input) {
var inputClone = input.clone(true);
$('<form/>').append(inputClone).get(0).reset();
input.after(inputClone).detach();
initFileInput();
};
this.onDocumentDragOver = function (e) {
if (typeof settings.onDocumentDragOver === func &&
settings.onDocumentDragOver(e) === false) {
return false;
}
e.preventDefault();
};
this.onDocumentDrop = function (e) {
if (typeof settings.onDocumentDrop === func &&
settings.onDocumentDrop(e) === false) {
return false;
}
e.preventDefault();
};
this.onDragOver = function (e) {
if (typeof settings.onDragOver === func &&
settings.onDragOver(e) === false) {
return false;
}
var dataTransfer = e.originalEvent.dataTransfer;
if (dataTransfer && dataTransfer.files) {
dataTransfer.dropEffect = dataTransfer.effectAllowed = 'copy';
e.preventDefault();
}
};
this.onDrop = function (e) {
if (typeof settings.onDrop === func &&
settings.onDrop(e) === false) {
return false;
}
var dataTransfer = e.originalEvent.dataTransfer;
if (dataTransfer && dataTransfer.files && isXHRUploadCapable()) {
handleFiles(e, dataTransfer.files);
}
e.preventDefault();
};
this.onChange = function (e) {
if (typeof settings.onChange === func &&
settings.onChange(e) === false) {
return false;
}
var input = $(e.target),
form = $(e.target.form);
if (form.length === 1) {
input.data(defaultNamespace + '_form', form);
replaceFileInput(input);
} else {
form = input.data(defaultNamespace + '_form');
}
if (!settings.forceIframeUpload && e.target.files && isXHRUploadCapable()) {
handleFiles(e, e.target.files, input, form);
} else {
handleLegacyUpload(e, input, form);
}
};
this.init = function (options) {
if (options) {
$.extend(settings, options);
optionsReference = options;
}
initUploadForm();
initFileInput();
if (container.data(settings.namespace)) {
$.error('FileUpload with namespace "' + settings.namespace + '" already assigned to this element');
return;
}
container
.data(settings.namespace, fileUpload)
.addClass(settings.cssClass);
settings.dropZone.not(container).addClass(settings.cssClass);
initEventHandlers();
};
this.options = function (options) {
var oldCssClass,
oldDropZone,
uploadFormFilterUpdate,
fileInputFilterUpdate;
if (typeof options === undef) {
return $.extend({}, settings);
}
if (optionsReference) {
$.extend(optionsReference, options);
}
removeEventHandlers();
$.each(options, function (name, value) {
switch (name) {
case 'namespace':
$.error('The FileUpload namespace cannot be updated.');
return;
case 'uploadFormFilter':
uploadFormFilterUpdate = true;
fileInputFilterUpdate = true;
break;
case 'fileInputFilter':
fileInputFilterUpdate = true;
break;
case 'cssClass':
oldCssClass = settings.cssClass;
break;
case 'dropZone':
oldDropZone = settings.dropZone;
break;
}
settings[name] = value;
});
if (uploadFormFilterUpdate) {
initUploadForm();
}
if (fileInputFilterUpdate) {
initFileInput();
}
if (typeof oldCssClass !== undef) {
container
.removeClass(oldCssClass)
.addClass(settings.cssClass);
(oldDropZone ? oldDropZone : settings.dropZone).not(container)
.removeClass(oldCssClass);
settings.dropZone.not(container).addClass(settings.cssClass);
} else if (oldDropZone) {
oldDropZone.not(container).removeClass(settings.cssClass);
settings.dropZone.not(container).addClass(settings.cssClass);
}
initEventHandlers();
};
this.option = function (name, value) {
var options;
if (typeof value === undef) {
return settings[name];
}
options = {};
options[name] = value;
fileUpload.options(options);
};
this.destroy = function () {
removeEventHandlers();
container
.removeData(settings.namespace)
.removeClass(settings.cssClass);
settings.dropZone.not(container).removeClass(settings.cssClass);
};
this.upload = function (files) {
if (typeof files.length === undef) {
files = [files];
}
handleFiles(null, files);
};
};
methods = {
init : function (options) {
return this.each(function () {
(new FileUpload($(this))).init(options);
});
},
option: function (option, value, namespace) {
namespace = namespace ? namespace : defaultNamespace;
var fileUpload = $(this).data(namespace);
if (fileUpload) {
if (!option) {
return fileUpload.options();
} else if (typeof option === 'string' && typeof value === undef) {
return fileUpload.option(option);
}
} else {
$.error('No FileUpload with namespace "' + namespace + '" assigned to this element');
}
return this.each(function () {
var fu = $(this).data(namespace);
if (fu) {
if (typeof option === 'string') {
fu.option(option, value);
} else {
fu.options(option);
}
} else {
$.error('No FileUpload with namespace "' + namespace + '" assigned to this element');
}
});
},
destroy: function (namespace) {
namespace = namespace ? namespace : defaultNamespace;
return this.each(function () {
var fileUpload = $(this).data(namespace);
if (fileUpload) {
fileUpload.destroy();
} else {
$.error('No FileUpload with namespace "' + namespace + '" assigned to this element');
}
});
},
upload: function (files, namespace) {
namespace = namespace ? namespace : defaultNamespace;
return this.each(function () {
var fileUpload = $(this).data(namespace);
if (fileUpload) {
fileUpload.upload(files);
} else {
$.error('No FileUpload with namespace "' + namespace + '" assigned to this element');
}
});
}
};
$.fn.fileUpload = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method "' + method + '" does not exist on jQuery.fileUpload');
}
};
}(jQuery));

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,43 @@
function init_note_upload_fields(note_id){
drop = $('#note_'+note_id+' .fileupload').closest(".bottom")
$('#note_'+note_id+' .fileupload').fileupload({
url: $(this).attr("action"),
dropZone: drop,
autoUpload: true,
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$(this).find('.progress .bar').html(progress + '% téléchargé.');
},
always: function (e, data) {
$(this).find('.progress .bar').html("");
},
drop: function (e, data) {
$('#note_'+note_id+' .fileupload').closest(".bottom").css("background", "rgb(255, 255, 204)");
}
});
$(".note .bottom").bind('dragover', function (e) {
$(this).css("background", "green");
});
$(".note .bottom").bind('dragleave', function (e) {
$(this).css("background", "rgb(255, 255, 204)");
});
}
$(document).ready(function () {
});

View File

@ -1,10 +0,0 @@
//= require jquery
//= require jquery_ujs
//= require_tree ./note_files
$('#left .header').live("click",function(){
$('#left').toggleClass("hide");
});

View File

@ -37,7 +37,6 @@
@import "admin/sheets";
@import "notes";
@import "topics";
@ -65,46 +64,6 @@ ol {
.text_panel{
@include border-radius(5px);
color:black;
background: white;
padding: 10px;
margin:20px;
position:relative;
&:before,
&:after {
content:"";
position:absolute;
z-index:-1;
bottom:15px;
left:10px;
width:50%;
height:20%;
max-width:300px;
@include box-shadow(rgba(0, 0, 0, 0.7) 0 20px 15px );
@include transform(rotate(-3deg));
}
&:after{
right:10px;
left:auto;
@include transform(rotate(3deg));
}
}
/* Dashboard */
#dashboard_menu{

View File

@ -404,8 +404,8 @@ body {
background-repeat:no-repeat;
background-size: contain;
-moz-background-size: contain; /* Gecko 1.9.2 (Firefox 3.6) */
-webkit-background-size: contain;/* Safari 3.0 */
-moz-background-size: contain;
-webkit-background-size: contain;
}

View File

@ -1,183 +0,0 @@
// Place all the styles related to the notes controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.note{
//@include box-shadow(0 0 5px rgba(0,0,0,0.5) inset);
@include border-radius(5px);
@include box-shadow(0px 0px 5px rgba(0,0,0,0.5) inset);
position:relative;
margin-bottom:1em;
min-height:120px;
.left{
@include box-shadow(0px 0px 5px rgba(0,0,0,0.5));
@include border-radius(3px 0px 0px 3px);
position:absolute;
top:0px;
left:0px;
bottom:0px;
width:100px;
background:rgba(0,0,0,0.8);
text-align:center;
padding:10px;
color:rgba(255,255,255,0.9);
*{
text-align:center;
}
.avatar{
width:70px;
height:70px;
@include border-radius(50%);
margin:auto;
}
}
.right{
min-height:150px;
margin-left:120px;
padding:10px;
line-height:1.1em;
img{
max-width:100%;
max-height:99%;
}
p,ul{
max-width:600px;
margin-left:100px;
p,ul{
margin-left:0px;
max-width:inherit;
}
}
.large{
max-width:100%;
margin-left:0px;
}
.links{
float:right;
}
}
.bottom{
background:rgb(255, 255, 204);
position:relative;
margin-left:120px;
@include border-radius(0px 0px 3px 0px);
@include box-shadow(0px 0px 2px rgba(0,0,0,0.3),-1px -1px 5px rgba(0,0,0,0.2) inset);
padding:10px;
min-height:1em;
.note_file{
margin:8px 0px;
}
.note_file_queue{
position:absolute;
top:1em;
right:0em;
.file_upload_progress{
width:100px;
}
}
.note_file_form{
float:right;
input[type=file]{
display:none;
}
label{
color: #17b;
cursor:pointer;
&:hover, &:active {
color: #39e;
background-color: none;
outline: none; }
&:link, &:visited, &:hover {
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease; }
&:active {
color: #b41;
-webkit-transition: none;
-moz-transition: none;
-o-transition: none;
transition: none; }
}
}
}
}
#file_prev{
position:absolute;
top:10px;
bottom:10px;
background:rgba(0,0,0,0.9);
width:98%;
right:-50%;
@include border-radius(5px);
@include transition(all 1s ease);
&:hover{
right:1%;
}
iframe{
position:absolute;
width:96%;
height:95%;
top:20px;
left:0px;
right:0px;
bottom:0px;
margin:auto;
}
}

View File

@ -1,106 +1,233 @@
@import "admin/general";
@import "compass";
@import "notes";
#topic_app_index{
body{
#login,.login{
@include border-radius(7px);
@include box-shadow(0px 0px 5px rgba(0,0,0,0.5));
position:absolute;
top:50px;
left:0px;
right:0px;
bottom:0px;
background:white;
padding:2em;
width:400px;
margin:auto;
}
#app_index{
#left{
background:rgba(0,0,0,0.9);
position:fixed;
background:rgba(0,0,0,0.8);
position:absolute;
top:0px;
left:0px;
height:500px;
right:0px;
z-index:2;
@include transition(all 1s);
&.hide{
margin-top:-470px;
.header{
@include transition(all 0.5s);
&:hover{
bottom:-10px;
}
}
}
.header{
cursor:pointer;
background:rgba(0,0,0,0.8);
color:rgba(250,250,250,0.9);
position:absolute;
width:300px;
bottom:0px;
left:0px;
right:0px;
font-size:15px;
text-align:center;
padding:5px;
padding-bottom:10px;
}
}
#topic_show{
padding-top:40px;
position:absolute;
top:0px;
left:300px;
right:0px;
bottom:0px;
background:rgba(250,250,250,0.9);
overflow:auto;
}
.note{
@include border-radius(5px);
@include box-shadow(0px 0px 5px rgba(0,0,0,0.5) inset);
position:relative;
margin-bottom:1em;
min-height:120px;
.left{
@include box-shadow(0px 0px 5px rgba(0,0,0,0.5));
@include border-radius(3px 0px 0px 3px);
position:absolute;
top:0px;
left:0px;
bottom:0px;
width:100px;
background:rgba(0,0,0,0.8);
text-align:center;
padding:10px;
color:rgba(255,255,255,0.9);
*{
text-align:center;
}
.avatar{
width:70px;
height:70px;
@include border-radius(50%);
margin:auto;
}
}
.right{
min-height:150px;
margin-left:120px;
padding:10px;
line-height:1.1em;
float:none;
img{
max-width:100%;
max-height:99%;
}
p,ul, h1,h2,h3{
max-width:600px;
margin-left:5%;
p,ul{
margin-left:0px;
max-width:inherit;
}
}
.large{
max-width:100%;
margin-left:0px;
}
.links{
float:right;
}
}
.bottom{
background:rgb(255, 255, 204);
position:relative;
margin-left:120px;
@include border-radius(0px 0px 3px 0px);
@include box-shadow(0px 0px 2px rgba(0,0,0,0.3),-1px -1px 5px rgba(0,0,0,0.2) inset);
padding:10px;
min-height:1em;
.note_file{
margin:8px 0px;
}
.note_file_queue{
position:absolute;
top:1em;
right:0em;
.file_upload_progress{
width:100px;
}
}
.note_file_form{
float:right;
input[type=file]{
display:none;
}
label{
color: #17b;
cursor:pointer;
&:hover, &:active {
color: #39e;
background-color: none;
outline: none; }
&:link, &:visited, &:hover {
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease; }
&:active {
color: #b41;
-webkit-transition: none;
-moz-transition: none;
-o-transition: none;
transition: none; }
}
}
}
}
#file_prev{
position:absolute;
top:10px;
bottom:10px;
background:rgba(0,0,0,0.9);
width:98%;
right:-50%;
@include border-radius(5px);
@include transition(all 1s ease);
&:hover{
right:1%;
}
iframe{
position:absolute;
width:96%;
height:95%;
top:20px;
left:0px;
right:0px;
bottom:0px;
margin:auto;
}
}
textarea.markdown{
}
textarea.markdown{
display:block;
width:97%;
margin:1% auto;
min-height:400px;
}
}
#add_topic{
display:block;
color:rgba(250,250,250,0.9);
color:rgba(250,250,250,0.8);
text-decoration:none;
margin-left:5px;
margin-top:2px;
padding:5px 10px;
float:right;
@ -108,20 +235,23 @@ body{
#topics{
margin-top:5px;
clear:both;
padding:1em;
@include column-count(3);
border-top:1px solid rgba(250,250,250,0.1);
overflow:auto;
position:absolute;
top:2em;
bottom:5px;
left:0px;
right:0px;
a{
color:white;
display:block;
padding:6px 10px;
color:rgba(250,250,250,0.9);
border-bottom:1px solid rgba(250,250,250,0.1);
color:rgba(250,250,250,0.8);
text-decoration:none;
margin-left:5px;
margin-top:2px;
@include border-radius(5px 0px 0px 5px);
&.active, &:hover{
background:rgba(250,250,250,0.9);
@ -133,8 +263,6 @@ body{
}
}

View File

@ -0,0 +1,12 @@
# -*- encoding : utf-8 -*-
class Admin::DashboardController < ApplicationController
#navigation :dahsboard
before_filter :authenticate_admin!
layout "admin"
def index
end
end

View File

@ -44,8 +44,10 @@ class NoteFilesController < ApplicationController
# POST /note_files
# POST /note_files.json
def create
@note_file = NoteFile.new(:original_filename => params[:note_file][:file][0].original_filename ,:name => params[:note_file][:file][0].original_filename, :note_id => params[:note_file][:note_id], :file =>params[:note_file][:file][0])
puts "AAAAAAAAAAAAAAAA"
puts params[:files][0].original_filename
puts "AAAAAAAAAAAAAAAA"
@note_file = NoteFile.new(:original_filename => params[:files][0].original_filename ,:name => params[:files][0].original_filename, :note_id => params[:note_id], :file =>params[:files][0])
if @note_file.save

View File

@ -1,7 +1,7 @@
# -*- encoding : utf-8 -*-
class TopicsController < ApplicationController
before_filter :authenticate_admin!
layout "topics"
layout "admin"
def index
@topics = Topic.all

View File

@ -1,4 +1,5 @@
%tr#admin_row.admin_row.row{:id => admin.id, :class => (cycle("row_1", "row_2", :name => "admins"))}
%td=image_tag (admin.file? ? admin.file.square.url : ""), :class => "avatar", :style => "width:30px; border-radius:50%;"
%td=admin.username
%td=admin.email
%td=admin.name

View File

@ -9,6 +9,8 @@
%thead#Admin_rows_header.rows_header
%tr
%td
%td
Nom d'utilisateur
%td

View File

@ -0,0 +1,19 @@
#welcome
=image_tag (current_admin.file? ? current_admin.file.square.url : ""), :class => "avatar", :style => "width:150px; border-radius:50%;float:left"
%p
="Bonjour #{current_admin.firstname},"
%p
=" votre dernière connexion à été effectuée le #{l(current_admin.last_sign_in_at)} depuis l'adresse ip #{current_admin.last_sign_in_ip}"
#rapid_links
=link_to "notes", topics_path
=link_to "admins (internet)", admin_admins_path
=link_to "urls courtes", tiny_urls_path

View File

@ -30,18 +30,15 @@
#breadcrumb
=image_tag (current_admin.file? ? current_admin.file.square.url : ""), :class => "avatar", :style => "width:30px; border-radius:50%;"
=link_to "Dashboard", "/admin"
=link_to "Se déconnecter", destroy_admin_session_path, :class => "logout_link"
.page_slide#main_slide
.page_slide_content
.container_12
= yield
.clear

View File

@ -1,20 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>InfineetyNotes</title>
<%= stylesheet_link_tag "topics", :media => "all" %>
<%= javascript_include_tag "topics" %>
<%= csrf_meta_tags %>
<style>
<%=Pygments.css('.highlight') %>
</style>
</head>
<body>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
</body>
</html>

View File

@ -1,19 +1,15 @@
-r = rand(99999999)
.note_file_form#note_file_form{:id => r}
-note_file = note_file || NoteFile.new(:note_id => note.id)
= form_for note_file, :url => note_files_path(), :html => { :id => "note_file_upload_field_#{r}", :multipart => true } do |f|
=f.label :file, "Selectionner des fichiers"
= f.file_field :file, :multiple => true
= f.hidden_field :note_id
= f.hidden_field :file_cache
%form.fileupload{:action => note_files_path(:note_id => note.id), :enctype => "multipart/form-data", :method => "POST"}
%input{:multiple => "", :name => "files[]", :type => "file", :style => "float:right;"}
.note_file_queue#note_file_queue{:id => r}
%table#files{:id => r}
.progress
.bar{:style => "height:1em;"}
.note_file_queue#note_file_queue
%table#files
%script
="init_upload_fields(#{r});"
="init_note_upload_fields("+note.id.to_s+");"

View File

@ -1 +1 @@
= link_to topic.title, topic, :remote => true, :id => "topic_line_#{topic.id}"
= link_to topic.title, topic, :class => "topic_line", :remote => true, :id => "topic_line_#{topic.id}"

View File

@ -1,16 +1,24 @@
#app_index
#topic_app_index
#left
= link_to '+ ajouter un topic', new_topic_path, :remote => true, :id => "add_topic"
#topics=render @topics
.header
Liste des topics
#topic_show
%form.fileupload{:action => note_files_path(), :enctype => "multipart/form-data", :method => "POST", :style => "border:1px solid black"}
.progress
.bar{:style => "background:red;width: 0%;"}
%input{:multiple => "", :name => "files[]", :type => "file"}
%form.fileupload{:action => "http://localhost:3000/1.html", :enctype => "multipart/form-data", :method => "POST", :style => "border:1px solid black"}
.progress
.bar{:style => "background:red;width: 0%;"}
%input{:multiple => "", :name => "files[]", :type => "file"}

View File

@ -1,3 +1,5 @@
$('#topic_show').html("<%= escape_javascript(render(:partial => "show")) %>");
$('.topic_line').removeClass("active");
$('#left').addClass("hide");
$('#topic_line_<%= @topic.id %>').addClass("active");
$('#topic_show').html("<%= escape_javascript(render(:partial => "show")) %>");

View File

@ -3,6 +3,7 @@ Survey::Application.routes.draw do
namespace :admin do
root :to => "dashboard#index"
resources :admins
end