[IMP] edi: improve EDI preview sidebar

bzr revid: odo@openerp.com-20111028113357-ymc6amfurpyo17e9
This commit is contained in:
Olivier Dony
2011-10-28 13:33:57 +02:00
parent 000f3cad33
commit 5fa1a6dd06
3 changed files with 88 additions and 32 deletions
+31 -3
View File
@@ -31,7 +31,7 @@ button.oe_edi_action_print img {
font-size: 1.3em;
}
.oe_edi_nested_block {
margin-left: 25px;
margin: 0px 40px;
padding: 0px;
display: none; /* made visible by click on parent input/label */
}
@@ -51,7 +51,10 @@ button.oe_edi_action_print img {
background: #e8e8e8;
}
.oe_edi_import_button {
margin: 1em 2em;
margin: 2px 10px;
}
.oe_edi_small, .oe_edi_small input {
font-size: 90%;
}
/** Paperbox, from http://www.sitepoint.com/pure-css3-paper-curl/ **/
@@ -166,4 +169,29 @@ table.oe_edi_data, .oe_edi_doc_title {
}
.oe_edi_summary_value {
float: right;
}
}
/** Python code highlighting **/
/* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
(http://qbnz.com/highlighter/ and http://geshi.org/) */
.python .de1, .python .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.python {font-family:monospace;}
.python .imp {font-weight: bold; color: red;}
.python li, .python .li1 {background: #ffffff; list-style: none;}
.python .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.python .li2 {background: #f8f8f8;}
.python .kw1 {color: #ff7700;font-weight:bold;}
.python .kw2 {color: #008000;}
.python .kw3 {color: #dc143c;}
.python .kw4 {color: #0000cd;}
.python .co1 {color: #808080; font-style: italic;}
.python .coMULTI {color: #808080; font-style: italic;}
.python .es0 {color: #000099; font-weight: bold;}
.python .br0 {color: black;}
.python .sy0 {color: #66cc66;}
.python .st0 {color: #483d8b;}
.python .nu0 {color: #ff4500;}
.python .me1 {color: black;}
.python span.xtra { display:block; }
.python ol { padding: 0px; }
+30 -14
View File
@@ -36,25 +36,41 @@ openerp.edi.EdiView = openerp.web.Widget.extend({
console.log("sidebar",this.sidebar);
this.$element.html(openerp.web.qweb.render("EdiView", param));
this.$element.find('button.oe_edi_action_print').bind('click', this.do_print);
this.$element.find('button.oe_edi_import_button').bind('click', this.do_import);
this.$element.find('button#oe_edi_import_existing').bind('click', this.do_import_existing);
this.$element.find('button#oe_edi_import_create').bind('click', this.do_import_create);
this.$element.find('button#oe_edi_download').bind('click', this.do_download);
this.$element.find('.oe_edi_import_choice, .oe_edi_import_choice_label').bind('click', this.toggle_choice);
this.$element.find('#oe_edi_download_show_code').bind('click', this.show_code);
},
show_code: function($event) {
$('#oe_edi_download_code').show();
return false;
},
get_download_url: function() {
var l = window.location;
var url_prefix = l.protocol + '//' + l.host;
return url_prefix +'/edi/download?db=' + this.db + '&token=' + this.token;
},
toggle_choice: function($e) {
$('.oe_edi_nested_block').hide();
$('.'+$e.target.id+'_nested').show();
return true;
},
do_print: function(e){
var l = window.location;
window.location = l.protocol + '//' + l.host + "/edi/download_attachment?db=" + this.db + "&token=" + this.token;
},
do_import: function(e){
var l = window.location;
var url_prefix = l.protocol + '//' + l.host;
var url_download = url_prefix +'/edi/download?db=' + this.db + '&token=' + this.token;
if (this.$element.find('#oe_edi_import_openerp').attr('checked') == 'checked') {
var server_url = this.$element.find('#oe_edi_txt_server_url').val()
window.location = 'http://' + server_url + '/edi/import_url?url=' + encodeURIComponent(url_download);
} else if (this.$element.find('#oe_edi_import_saas').attr('checked') == 'checked') {
window.location = "https://cc.my.openerp.com/odms/create_edi?url=" + encodeURIComponent(url_download);
} else if (this.$element.find('#oe_edi_import_download').attr('checked') == 'checked') {
window.location = url_download
}
do_import_existing: function(e) {
var url_download = this.get_download_url();
var server_url = this.$element.find('#oe_edi_txt_server_url').val()
window.location = 'http://' + server_url + '/edi/import_url?url=' + encodeURIComponent(url_download);
},
do_import_create: function(e){
var url_download = this.get_download_url();
window.location = "https://cc.my.openerp.com/odms/create_edi?url=" + encodeURIComponent(url_download);
},
do_download: function(e){
window.location = this.get_download_url();
}
});
+27 -15
View File
@@ -29,38 +29,50 @@
<input type="radio" id="oe_edi_import_openerp" name="oe_edi_import" class="oe_edi_import_choice"/>
<label for="oe_edi_import_openerp" id="oe_edi_import_openerp" class="oe_edi_import_choice_label">Import it into an existing OpenERP instance</label>
</div>
<p class="oe_edi_nested_block" id="oe_edi_import_openerp_nested">
<p class="oe_edi_nested_block oe_edi_import_openerp_nested">
<label for="oe_edi_txt_server_url">OpenERP instance address:</label>
<br/>
http://<input type="text" id="oe_edi_txt_server_url"/>
http://<input type="text" id="oe_edi_txt_server_url"/><br/>
<button type="button" class="oe_edi_import_button" id="oe_edi_import_existing">Import</button>
</p>
<div class="oe_edi_option">
<input type="radio" id="oe_edi_import_saas" name="oe_edi_import" class="oe_edi_import_choice"/>
<label for="oe_edi_import_saas" id="oe_edi_import_saas" class="oe_edi_import_choice_label">Import it into a new OpenERP Online instance:</label>
</div>
<p class="oe_edi_nested_block oe_edi_import_saas_nested">
<button type="button" class="oe_edi_import_button" id="oe_edi_import_create">Create my new OpenERP instance</button>
</p>
<div class="oe_edi_option">
<input type="radio" id="oe_edi_import_download" name="oe_edi_import" class="oe_edi_import_choice"/>
<label for="oe_edi_import_download" id="oe_edi_import_download" class="oe_edi_import_choice_label">Import into another application</label>
</div>
<button type="button" class="oe_edi_import_button">Continue</button>
<p class="oe_edi_nested_block oe_edi_small oe_edi_import_download_nested">
OpenERP's Electronic Data Interchange documents are based on a generic and language
independent <a href="http://json.org">JSON</a> serialization of the document's attribute.
It is usually very quick and straightforward to create a small plug-in for your preferred
application that will be capable of importing any OpenERP EDI document.
You can find out more details about how to do this and what the content of OpenERP EDI documents
is like in the <a href="http://doc.openerp.com/search.html?q=edi">OpenERP documentation</a>.
<br/>
To get started immediately, <a href="#" id="oe_edi_download_show_code">see is all it takes to use this EDI document in Python</a>.
</p>
<div class="python oe_edi_nested_block oe_edi_small" id="oe_edi_download_code">
<ol><li class="li1"><div class="de1"><span class="kw1">import</span> <span class="kw3">urllib2</span><span class="sy0">,</span> simplejson</div></li>
<li class="li1"><div class="de1">edi_document <span class="sy0">=</span> <span class="kw3">urllib2</span>.<span class="me1">urlopen</span><span class="br0">(</span><span class="st0">'<t t-esc="widget.get_download_url()"/>'</span><span class="br0">)</span>.<span class="me1">read</span><span class="br0">(</span><span class="br0">)</span></div></li>
<li class="li2"><div class="de2">document_data <span class="sy0">=</span> simplejson.<span class="me1">loads</span><span class="br0">(</span>edi_document<span class="br0">)</span><span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span></div></li>
<li class="li1"><div class="de1"><span class="kw1">print</span> <span class="st0">"Amount: "</span><span class="sy0">,</span> document_data<span class="br0">[</span><span class="st0">'amount_total'</span><span class="br0">]</span></div></li>
</ol></div>
<p class="oe_edi_nested_block oe_edi_small oe_edi_import_download_nested">
You can download the raw EDI document here:<br/>
<input type="text" readonly="readonly" t-att-value="widget.get_download_url()"/>
<button type="button" class="oe_edi_import_button" id="oe_edi_download">Download</button>
</p>
<div class="oe_edi_right_bottom">
<t t-raw="widget.sidebar"/>
</div>
<script type="text/javascript">
$(document).ready(function() {
console.log('installing');
$('.oe_edi_import_choice, .oe_edi_import_choice_label').click(function($event) {
$('.oe_edi_nested_block').hide();
$('#'+$event.target.id+'_nested').show();
return true;
});
});
</script>
</td>
</tr>
</table>