ClientScript register
This commit is contained in:
1 parent
2a60a4eaa3
commit
0672e120a0
19 files changed
+514
-15
No files matched your search
@@ -1,6 +1,6 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.event import addEvent, fireEvent
|
||||
from couchpotato.core.helpers.variable import md5, getExt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
@@ -22,6 +22,9 @@ class FileManager(Plugin):
|
||||
|
||||
addApiView('file.cache/<path:file>', self.showImage)
|
||||
|
||||
path = self.registerStatic(__file__)
|
||||
fireEvent('register_script', path + 'file.js')
|
||||
|
||||
def showImage(self, file = ''):
|
||||
|
||||
cache_dir = Env.get('cache_dir')
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
var File = new Class({
|
||||
|
||||
initialize: function(file){
|
||||
var self = this;
|
||||
|
||||
self.data = file;
|
||||
self.type = File.Type.get(file.type_id);
|
||||
|
||||
self['create'+(self.type.type).capitalize()]()
|
||||
|
||||
},
|
||||
|
||||
createImage: function(){
|
||||
var self = this;
|
||||
|
||||
self.el = new Element('div', {
|
||||
'class': 'type_image ' + self.type.identifier
|
||||
}).adopt(
|
||||
new Element('img', {
|
||||
'src': Api.createUrl('file.cache') + self.data.path.substring(1) + '/'
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
toElement: function(){
|
||||
return this.el;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var FileSelect = new Class({
|
||||
|
||||
multiple: function(type, files, single){
|
||||
|
||||
var results = files.filter(function(file){
|
||||
return file.type_id == File.Type.get(type).id;
|
||||
});
|
||||
|
||||
if(single){
|
||||
results = new File(results.pop());
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
},
|
||||
|
||||
single: function(type, files){
|
||||
return this.multiple(type, files, true);
|
||||
}
|
||||
|
||||
});
|
||||
window.File.Select = new FileSelect();
|
||||
|
||||
var FileTypeBase = new Class({
|
||||
|
||||
setup: function(types){
|
||||
var self = this;
|
||||
|
||||
self.typesById = {};
|
||||
self.typesByKey = {};
|
||||
Object.each(types, function(type){
|
||||
self.typesByKey[type.identifier] = type;
|
||||
self.typesById[type.id] = type;
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
get: function(identifier){
|
||||
if(typeOf(identifier) == 'number')
|
||||
return this.typesById[identifier]
|
||||
else
|
||||
return this.typesByKey[identifier]
|
||||
}
|
||||
|
||||
});
|
||||
window.File.Type = new FileTypeBase();
|
||||
Reference in new issue
Block a user