Merge branch 'master' into patch_system
This commit is contained in:
commit
2002a6df12
4 changed files with 29 additions and 18 deletions
|
|
@ -23,7 +23,7 @@ Uploader = function(parent, args, callback) {
|
|||
// file data
|
||||
var inp_fdata = $a_input($a(ul_form,'span'),'file',{name:'filedata'},{marginLeft:'7px'});
|
||||
|
||||
var inp = $a_input($a(ul_form,'span'),'hidden',{name:'cmd'}); inp.value = 'uploadfile';
|
||||
if(!('cmd' in args)) { var inp = $a_input($a(ul_form,'span'),'hidden',{name:'cmd'}); inp.value = 'uploadfile'; }
|
||||
var inp = $a_input($a(ul_form,'span'),'hidden',{name:'uploader_id'}); inp.value = id;
|
||||
var inp = $a_input($a(ul_form,'span'),'submit',null,{marginLeft:'7px'}); inp.value = 'Upload';
|
||||
|
||||
|
|
@ -39,4 +39,4 @@ Uploader = function(parent, args, callback) {
|
|||
|
||||
function upload_callback(id, fid) {
|
||||
uploaders[id].callback(fid);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -738,7 +738,8 @@ function loadscript(src,call_back){set_loading();var script=$a('head','script');
|
|||
script.onreadystatechange=function(){if(this.readyState=='complete'||this.readyState=='loaded'){hide_loading();call_back();}}}
|
||||
var doc_browser_page;function loaddocbrowser(dt,label,fields){wn.require('lib/js/legacy/widgets/form/fields.js');wn.require('lib/js/legacy/webpage/docbrowser.js');dt=get_label_doctype(dt);if(!doc_browser_page)
|
||||
doc_browser_page=new ItemBrowserPage();doc_browser_page.show(dt,label,fields);nav_obj.open_notify('List',dt,'');}
|
||||
var uploaders={};var upload_frame_count=0;Uploader=function(parent,args,callback){var id='frame'+upload_frame_count;upload_frame_count++;this.callback=callback;var div=$a(parent,'div');div.innerHTML='<iframe id="'+id+'" name="'+id+'" src="blank1.html" style="width:0px; height:0px; border:0px"></iframe>';var div=$a(parent,'div');div.innerHTML='<form method="POST" enctype="multipart/form-data" action="'+outUrl+'" target="'+id+'"></form>';var ul_form=div.childNodes[0];var f_list=[];var inp_fdata=$a_input($a(ul_form,'span'),'file',{name:'filedata'},{marginLeft:'7px'});var inp=$a_input($a(ul_form,'span'),'hidden',{name:'cmd'});inp.value='uploadfile';var inp=$a_input($a(ul_form,'span'),'hidden',{name:'uploader_id'});inp.value=id;var inp=$a_input($a(ul_form,'span'),'submit',null,{marginLeft:'7px'});inp.value='Upload';$y(inp,{width:'80px'});for(var key in args){var inp=$a_input($a(ul_form,'span'),'hidden',{name:key});inp.value=args[key];}
|
||||
var uploaders={};var upload_frame_count=0;Uploader=function(parent,args,callback){var id='frame'+upload_frame_count;upload_frame_count++;this.callback=callback;var div=$a(parent,'div');div.innerHTML='<iframe id="'+id+'" name="'+id+'" src="blank1.html" style="width:0px; height:0px; border:0px"></iframe>';var div=$a(parent,'div');div.innerHTML='<form method="POST" enctype="multipart/form-data" action="'+outUrl+'" target="'+id+'"></form>';var ul_form=div.childNodes[0];var f_list=[];var inp_fdata=$a_input($a(ul_form,'span'),'file',{name:'filedata'},{marginLeft:'7px'});if(!('cmd'in args)){var inp=$a_input($a(ul_form,'span'),'hidden',{name:'cmd'});inp.value='uploadfile';}
|
||||
var inp=$a_input($a(ul_form,'span'),'hidden',{name:'uploader_id'});inp.value=id;var inp=$a_input($a(ul_form,'span'),'submit',null,{marginLeft:'7px'});inp.value='Upload';$y(inp,{width:'80px'});for(var key in args){var inp=$a_input($a(ul_form,'span'),'hidden',{name:key});inp.value=args[key];}
|
||||
uploaders[id]=this;}
|
||||
function upload_callback(id,fid){uploaders[id].callback(fid);}
|
||||
var pages=[];var stylesheets=[];function Page(page_name,content){var me=this;this.name=page_name;this.onshow=function(){set_title(me.doc.page_title?me.doc.page_title:me.name);try{if(pscript['onshow_'+me.name])pscript['onshow_'+me.name]();}catch(e){submit_error(e);}
|
||||
|
|
|
|||
|
|
@ -116,12 +116,19 @@ def uploadfile():
|
|||
fid, fname = webnotes.utils.file_manager.save_uploaded()
|
||||
|
||||
# do something with the uploaded file
|
||||
if fid and webnotes.form_dict.get('server_obj'):
|
||||
from webnotes.model.code import get_obj
|
||||
getattr(get_obj(webnotes.form_dict.get('server_obj')), webnotes.form_dict.get('method'))(fid, fname)
|
||||
|
||||
# return the upload
|
||||
if fid:
|
||||
if webnotes.form_dict.get('server_obj'):
|
||||
from webnotes.model.code import get_obj
|
||||
getattr(get_obj(webnotes.form_dict.get('server_obj')), webnotes.form_dict.get('method'))(fid, fname)
|
||||
|
||||
elif webnotes.form_dict.get('modulename'):
|
||||
# calls a python module to handle the script
|
||||
__import__(webnotes.form_dict['modulename'])
|
||||
import sys
|
||||
moduleobj = sys.modules[webnotes.form_dict['modulename']]
|
||||
getattr(moduleobj, webnotes.form_dict['method'])(fid, fname)
|
||||
|
||||
|
||||
webnotes.response['result'] = '<script>window.parent.upload_callback("'+webnotes.form_dict.get('uploader_id')+'", "'+fid+'")</script>'
|
||||
|
||||
# File upload (from scripts)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import webnotes
|
||||
|
||||
def upload():
|
||||
import webnotes
|
||||
form = webnotes.form
|
||||
|
||||
# get record details
|
||||
|
|
@ -47,7 +48,6 @@ def add_file_list(dt, dn, fname, fid):
|
|||
"""
|
||||
udpate file_list attribute of the record
|
||||
"""
|
||||
import webnotes
|
||||
try:
|
||||
# get the old file_list
|
||||
fl = webnotes.conn.get_value(dt, dn, 'file_list') or ''
|
||||
|
|
@ -69,11 +69,19 @@ window.parent.msgprint("Error while uploading: %s");
|
|||
</script>""" % str(e)
|
||||
|
||||
|
||||
def remove_all(dt, dn):
|
||||
"""remove all files in a transaction"""
|
||||
file_list = webnotes.conn.get_value(dt, dn, 'file_list') or ''
|
||||
for afile in file_list.split('\n'):
|
||||
if afile:
|
||||
fname, fid = afile.split(',')
|
||||
remove_file_list(dt, dn, fid)
|
||||
delete_file(fid)
|
||||
|
||||
def remove_file_list(dt, dn, fid):
|
||||
"""
|
||||
Remove fid from the give file_list
|
||||
"""
|
||||
import webnotes
|
||||
|
||||
# get the old file_list
|
||||
fl = webnotes.conn.get_value(dt, dn, 'file_list') or ''
|
||||
|
|
@ -105,7 +113,6 @@ def make_thumbnail(blob, size):
|
|||
|
||||
|
||||
def save_uploaded(js_okay='window.parent.msgprint("File Upload Successful")', js_fail=''):
|
||||
import webnotes
|
||||
import webnotes.utils
|
||||
|
||||
webnotes.response['type'] = 'iframe'
|
||||
|
|
@ -144,7 +151,6 @@ def save_uploaded(js_okay='window.parent.msgprint("File Upload Successful")', js
|
|||
# -------------------------------------------------------
|
||||
|
||||
def save_file(fname, content, module=None):
|
||||
import webnotes
|
||||
from webnotes.model.doc import Document
|
||||
|
||||
# some browsers return the full path
|
||||
|
|
@ -167,7 +173,7 @@ def save_file(fname, content, module=None):
|
|||
# -------------------------------------------------------
|
||||
|
||||
def write_file(fid, content):
|
||||
import webnotes, os, webnotes.defs
|
||||
import os, webnotes.defs
|
||||
|
||||
# test size
|
||||
max_file_size = 1000000
|
||||
|
|
@ -195,12 +201,11 @@ def write_file(fid, content):
|
|||
# -------------------------------------------------------
|
||||
def get_file_system_name(fname):
|
||||
# get system name from File Data table
|
||||
import webnotes
|
||||
return webnotes.conn.sql("select name, file_name from `tabFile Data` where name=%s or file_name=%s", (fname, fname))
|
||||
|
||||
# -------------------------------------------------------
|
||||
def delete_file(fname, verbose=0):
|
||||
import webnotes, os
|
||||
import os
|
||||
|
||||
for f in get_file_system_name(fname):
|
||||
webnotes.conn.sql("delete from `tabFile Data` where name=%s", f[0])
|
||||
|
|
@ -219,7 +224,6 @@ def delete_file(fname, verbose=0):
|
|||
# -------------------------------------------------------
|
||||
|
||||
def get_file(fname):
|
||||
import webnotes
|
||||
in_fname = fname
|
||||
|
||||
# from the "File" table
|
||||
|
|
@ -248,7 +252,6 @@ def get_file(fname):
|
|||
# -------------------------------------------------------
|
||||
|
||||
def convert_to_files(verbose=0):
|
||||
import webnotes
|
||||
|
||||
# nfiles
|
||||
fl = webnotes.conn.sql("select name from `tabFile Data`")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue