data import and upload issues

This commit is contained in:
Rushabh Mehta 2012-05-10 19:07:53 +05:30
parent 03262e0c12
commit ea7ba72397
6 changed files with 62 additions and 51 deletions

View File

@ -108,44 +108,42 @@ MyProfile = function(wrapper) {
this.change_image = function() {
var d = new wn.widgets.Dialog({
title: 'Set your Profile'
})
me.uploader = new Uploader(d.body, {
modulename:'home.page.profile_settings.profile_settings',
method: 'set_user_image'
},
pscript.user_image_upload, 1)
});
wn.upload.make({
parent: d.body,
args: {
method: 'home.page.profile_settings.profile_settings.set_user_image'
},
callback: function(fid) {
if(fid) {
d.hide();
wn.boot.user_info[user].image = 'files/' + fid;
pscript.myprofile.img.src = 'files/' + fid;
}
}
});
d.show();
pscript.open_dialog = d;
}
this.change_background = function() {
var d = new wn.widgets.Dialog({
title: 'Set Background Image'
})
me.uploader = new Uploader(d.body, {
modulename:'home.page.profile_settings.profile_settings',
method: 'set_user_background'
},
pscript.background_change, 1)
wn.upload.make({
parent: d.body,
args: {
method: 'home.page.profile_settings.profile_settings.set_user_background'
},
callback: function(fid) {
if(fid) {
d.hide();
erpnext.set_user_background(fid);
}
}
});
d.show();
pscript.open_dialog = d;
}
this.make();
}
pscript.background_change = function(fid) {
msgprint('File Uploaded');
if(fid) {
erpnext.set_user_background(fid);
pscript.open_dialog.hide();
}
}
pscript.user_image_upload = function(fid) {
msgprint('File Uploaded');
if(fid) {
pscript.open_dialog.hide();
wn.boot.user_info[user].image = 'files/' + fid;
pscript.myprofile.img.src = 'files/' + fid;
}
}
}

View File

@ -64,14 +64,16 @@ def set_user_details(arg=None):
webnotes.msgprint('Updated')
@webnotes.whitelist()
def set_user_image(fid, fname):
def set_user_image():
"""
Set uploaded image as user image
"""
check_demo()
from webnotes.utils.file_manager import add_file_list, remove_file
from webnotes.utils.file_manager import add_file_list, remove_file, save_uploaded
user = webnotes.session['user']
fid, fname = save_uploaded()
# remove old file
old_image = webnotes.conn.get_value('Profile', user, 'user_image')
if old_image:
@ -80,15 +82,19 @@ def set_user_image(fid, fname):
# add new file
add_file_list('Profile', user, fname, fid)
webnotes.conn.set_value('Profile', user, 'user_image', fid)
return fid
@webnotes.whitelist()
def set_user_background(fid, fname):
def set_user_background():
"""
Set uploaded image as user image
"""
check_demo()
from webnotes.utils.file_manager import add_file_list, remove_file
from webnotes.utils.file_manager import add_file_list, remove_file, save_uploaded
user = webnotes.session['user']
fid, fname = save_uploaded()
# remove old file
old_image = webnotes.conn.get_value('Profile', user, 'background_image')
@ -98,3 +104,5 @@ def set_user_background(fid, fname):
# add new file
add_file_list('Profile', user, fname, fid)
webnotes.conn.set_value('Profile', user, 'background_image', fid)
return fid

View File

@ -3686,7 +3686,7 @@ div.stat-item {
margin-bottom: 7px;
background-color: #fff;
height: 18px;
border: 2px solid #aaa;
border: 1px solid #aaa;
border-radius: 9px;
overflow: hidden;
}

View File

@ -2438,7 +2438,7 @@ div.stat-item {
margin-bottom: 7px;
background-color: #fff;
height: 18px;
border: 2px solid #aaa;
border: 1px solid #aaa;
border-radius: 9px;
overflow: hidden;
}

View File

@ -153,7 +153,8 @@ var l=items.length;for(var i=0;i<l;i++){var src=items[i];wn.assets.execute(src);
/*
* lib/js/wn/dom.js
*/
wn.provide('wn.dom');wn.dom={id_count:0,by_id:function(id){return document.getElementById(id);},set_unique_id:function(ele){var id='unique-'+wn.dom.id_count;ele.setAttribute('id',id);wn.dom.id_count++;return id;},eval:function(txt){if(!txt)return;var el=document.createElement('script');el.appendChild(document.createTextNode(txt));document.getElementsByTagName('head')[0].appendChild(el);},set_style:function(txt){if(!txt)return;var se=document.createElement('style');se.type="text/css";if(se.styleSheet){se.styleSheet.cssText=txt;}else{se.appendChild(document.createTextNode(txt));}
wn.provide('wn.dom');wn.dom={id_count:0,by_id:function(id){return document.getElementById(id);},set_unique_id:function(ele){var id='unique-'+wn.dom.id_count;if(ele)
ele.setAttribute('id',id);wn.dom.id_count++;return id;},eval:function(txt){if(!txt)return;var el=document.createElement('script');el.appendChild(document.createTextNode(txt));document.getElementsByTagName('head')[0].appendChild(el);},set_style:function(txt){if(!txt)return;var se=document.createElement('style');se.type="text/css";if(se.styleSheet){se.styleSheet.cssText=txt;}else{se.appendChild(document.createTextNode(txt));}
document.getElementsByTagName('head')[0].appendChild(se);},add:function(parent,newtag,className,cs,innerHTML,onclick){if(parent&&parent.substr)parent=wn.dom.by_id(parent);var c=document.createElement(newtag);if(parent)
parent.appendChild(c);if(className){if(newtag.toLowerCase()=='img')
c.src=className
@ -930,6 +931,17 @@ this.tree.$w.find('a.selected').removeClass('selected');this.$a.toggleClass('sel
if(this.$ul){this.$ul.empty();}
this.load();},addnode:function(label,expandable){if(!this.$ul){this.$ul=$('<ul>').toggle(false).appendTo(this.parent);}
return new wn.ui.TreeNode({tree:this.tree,parent:$('<li>').appendTo(this.$ul),label:label,expandable:expandable});},load:function(){var me=this;args=$.extend(this.tree.args,{parent:this.label});$(me.$a).set_working();wn.call({method:this.tree.method,args:args,callback:function(r){$(me.$a).done_working();$.each(r.message,function(i,v){node=me.addnode(v.value||v,v.expandable);node.$a.data('node-data',v);});me.loaded=true;me.selectnode();}})}})
/*
* lib/js/wn/upload.js
*/
wn.upload={make:function(opts){var id=wn.dom.set_unique_id();$(opts.parent).append(repl('<iframe id="%(id)s" name="%(id)s" src="blank.html" \
style="width:0px; height:0px; border:0px"></iframe>\
<form method="POST" enctype="multipart/form-data" \
action="%(action)s" target="%(id)s">\
<input type="file" name="filedata" /><br>\
<input type="submit" class="btn btn-small" value="Upload" />\
</form>',{id:id,action:wn.request.url}));opts.args.cmd='uploadfile';opts.args._id=id;for(key in opts.args){if(opts.args[key]){$('<input type="hidden">').attr('name',key).attr('value',opts.args[key]).appendTo($(opts.parent).find('form'));}}
$('#'+id).get(0).callback=opts.callback},callback:function(id,file_id,args){$('#'+id).get(0).callback(file_id,args);}}
/*
* lib/js/wn/misc/about.js
*/
@ -1272,14 +1284,6 @@ function loaddoc(doctype,name,onload){wn.model.with_doctype(doctype,function(){i
var load_doc=loaddoc;function new_doc(doctype,onload,in_dialog,on_save_callback,cdt,cdn,cnic){doctype=get_label_doctype(doctype);wn.model.with_doctype(doctype,function(){if(locals.DocType[doctype].in_dialog){var new_name=LocalDB.create(doctype);_f.edit_record(doctype,new_name);}else{wn.views.formview.create(doctype);}})}
var newdoc=new_doc;var pscript={};function loadpage(page_name,call_back,no_history){wn.set_route(page_name);}
function loaddocbrowser(dt){wn.set_route('List',dt);}
/*
* lib/js/legacy/webpage/uploader.js
*/
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="blank.html" \
style="width:0px; height:0px; border:0px"></iframe>';var div=$a(parent,'div');div.innerHTML='<form method="POST" enctype="multipart/form-data" action="'+wn.request.url+'" 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);}
/*
* lib/js/legacy/wn/page_layout.js
*/
@ -1412,7 +1416,7 @@ wn.ui.toolbar.Search=wn.ui.toolbar.SelectorDialog.extend({init:function(){this._
/*
* lib/js/wn/ui/toolbar/report.js
*/
wn.ui.toolbar.Report=wn.ui.toolbar.SelectorDialog.extend({init:function(){this._super({title:"Start Report For",execute:function(val){loadreport(val,null,null,null,1);},});this.set_values(profile.can_get_report.join(',').split(','));}});
wn.ui.toolbar.Report=wn.ui.toolbar.SelectorDialog.extend({init:function(){this._super({title:"Start Report For",execute:function(val){wn.set_route('Report2',val);},});this.set_values(profile.can_get_report.join(',').split(','));}});
/*
* lib/js/wn/ui/toolbar/recent.js
*/
@ -2211,7 +2215,7 @@ var doc=locals[me.frm.doctype][me.frm.docname];var fl=doc.file_list?doc.file_lis
this.add_attachment=function(){if(!this.dialog){this.dialog=new wn.widgets.Dialog({title:'Add Attachment',width:400})
$y(this.dialog.body,{margin:'13px'})
this.dialog.make();}
this.dialog.body.innerHTML='';this.dialog.show();this.uploader=new Uploader(this.dialog.body,{from_form:1,doctype:doctype,docname:docname,at_id:this.at_id},wn.widgets.form.file_upload_done);}
this.dialog.body.innerHTML='';this.dialog.show();wn.upload.make({parent:this.dialog.body,args:{from_form:1,doctype:doctype,docname:docname},callback:wn.widgets.form.file_upload_done});}
this.make();}
wn.widgets.form.sidebar.Attachment=function(parent,filedet,frm){filedet=filedet.split(',')
this.filename=filedet[0];this.fileid=filedet[1];this.frm=frm;var me=this;this.wrapper=$a(parent,'div','sidebar-comment-message');this.remove_fileid=function(){var doc=locals[me.frm.doctype][me.frm.docname];var fl=doc.file_list.split('\n');new_fl=[];for(var i=0;i<fl.length;i++){if(fl[i].split(',')[1]!=me.fileid)new_fl.push(fl[i]);}
@ -2220,7 +2224,7 @@ var display_name=this.fileid;if(this.fileid.substr(0,8)=='FileData')
display_name=this.filename;this.ln=$a(this.wrapper,'a','link_type small',{},display_name);this.ln.href='files/'+this.fileid;this.ln.target='_blank';this.del=$a(this.wrapper,'span','close','','&#215;');this.del.onclick=function(){var yn=confirm("Are you sure you want to delete the attachment?")
if(yn){var callback=function(r,rt){locals[me.frm.doctype][me.frm.docname].modified=r.message;$dh(me.wrapper);me.remove_fileid();frm.refresh();}
$c('webnotes.widgets.form.utils.remove_attach',args={'fid':me.fileid,dt:me.frm.doctype,dn:me.frm.docname},callback);}}}
wn.widgets.form.file_upload_done=function(doctype,docname,fileid,filename,at_id,new_timestamp){var at_id=cint(at_id);var doc=locals[doctype][docname];if(doc.file_list){var fl=doc.file_list.split('\n')
wn.widgets.form.file_upload_done=function(doctype,docname,fileid,filename,at_id,new_timestamp){var doc=locals[doctype][docname];if(doc.file_list){var fl=doc.file_list.split('\n')
fl.push(filename+','+fileid)
doc.file_list=fl.join('\n');}
else

View File

@ -40,7 +40,8 @@ var l=items.length;for(var i=0;i<l;i++){var src=items[i];wn.assets.execute(src);
/*
* lib/js/wn/dom.js
*/
wn.provide('wn.dom');wn.dom={id_count:0,by_id:function(id){return document.getElementById(id);},set_unique_id:function(ele){var id='unique-'+wn.dom.id_count;ele.setAttribute('id',id);wn.dom.id_count++;return id;},eval:function(txt){if(!txt)return;var el=document.createElement('script');el.appendChild(document.createTextNode(txt));document.getElementsByTagName('head')[0].appendChild(el);},set_style:function(txt){if(!txt)return;var se=document.createElement('style');se.type="text/css";if(se.styleSheet){se.styleSheet.cssText=txt;}else{se.appendChild(document.createTextNode(txt));}
wn.provide('wn.dom');wn.dom={id_count:0,by_id:function(id){return document.getElementById(id);},set_unique_id:function(ele){var id='unique-'+wn.dom.id_count;if(ele)
ele.setAttribute('id',id);wn.dom.id_count++;return id;},eval:function(txt){if(!txt)return;var el=document.createElement('script');el.appendChild(document.createTextNode(txt));document.getElementsByTagName('head')[0].appendChild(el);},set_style:function(txt){if(!txt)return;var se=document.createElement('style');se.type="text/css";if(se.styleSheet){se.styleSheet.cssText=txt;}else{se.appendChild(document.createTextNode(txt));}
document.getElementsByTagName('head')[0].appendChild(se);},add:function(parent,newtag,className,cs,innerHTML,onclick){if(parent&&parent.substr)parent=wn.dom.by_id(parent);var c=document.createElement(newtag);if(parent)
parent.appendChild(c);if(className){if(newtag.toLowerCase()=='img')
c.src=className