[web page] make editable for logged in user (alpha)

This commit is contained in:
Rushabh Mehta 2013-10-14 18:14:41 +05:30
parent bc8a0685de
commit b0a45c4865
6 changed files with 25 additions and 6 deletions

View file

@ -22,7 +22,13 @@ jQuery(function ($) {
};
$.fn.cleanHtml = function () {
var html = $(this).html();
return html && html.replace(/(<br>|\s|<div><br><\/div>|&nbsp;)*$/, '');
html = html && html.replace(/(<br>|\s|<div><br><\/div>|&nbsp;)*$/, '');
// remove custom typography (use CSS!)
html = html && html.replace(/(font-family|font-size|line-height):[^;]*;/g, '');
html = html && html.replace(/<[^>]*(font=['"][^'"]*['"])>/g, function(a,b) { return a.replace(b, ''); });
html = html && html.replace(/\s*style\s*=\s*["']\s*["']/g, '');
return html;
};
$.fn.wysiwyg = function (userOptions) {
var editor = this,

View file

@ -157,7 +157,6 @@ wn.editors.BootstrapWYSIWYG = Class.extend({
me.$textarea.val(html_beautify(me.$editor.cleanHtml()));
me.$parent.find(".for-rich-text").toggle(false);
me.$parent.find(".for-html").toggle(true);
console.log(me.$parent.find(".btn-html"));
me.$parent.find(".btn-html").attr("disabled", "disabled");
me.$parent.find(".btn-rich-text").attr("disabled", false);
me.current_editor = me.$textarea;

View file

@ -287,7 +287,7 @@ wn.views.ReportView = wn.ui.Listing.extend({
method: "webnotes.client.set_value",
args: {
doctype: docfield.parent,
docname: row[docfield.parent===me.doctype ? "name" : docfield.parent+":name"],
name: row[docfield.parent===me.doctype ? "name" : docfield.parent+":name"],
fieldname: docfield.fieldname,
value: d.get_value(docfield.fieldname)
},

View file

@ -25,17 +25,17 @@ def get_value(doctype, fieldname, filters=None, as_dict=True, debug=False):
return webnotes.conn.get_value(doctype, json.loads(filters), fieldname, as_dict=as_dict, debug=debug)
@webnotes.whitelist()
def set_value(doctype, docname, fieldname, value):
def set_value(doctype, name, fieldname, value):
if fieldname in webnotes.model.default_fields:
webnotes.throw(_("Cannot edit standard fields"))
doc = webnotes.conn.get_value(doctype, docname, ["parenttype", "parent"], as_dict=True)
doc = webnotes.conn.get_value(doctype, name, ["parenttype", "parent"], as_dict=True)
if doc and doc.parent:
bean = webnotes.bean(doc.parenttype, doc.parent)
child = bean.doclist.getone({"doctype": doctype, "name": docname})
child.fields[fieldname] = value
else:
bean = webnotes.bean(doctype, docname)
bean = webnotes.bean(doctype, name)
bean.doc.fields[fieldname] = value
bean.save()

View file

@ -191,4 +191,10 @@ fieldset {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.web-page-editable {
margin: -15px;
padding: 15px;
border-radius: 4px;
}

View file

@ -3,6 +3,14 @@
{% block content %}
<div class="col-md-12" style="margin-top: 15px;">
{% include "lib/website/doctype/website_slideshow/templates/includes/slideshow.html" %}
<div class="web-page-content">
{{ main_section }}
</div>
</div>
<script>
$(function() {
window.name = "{{ name }}";
if(getCookie("full_name")) { $.get("app/js/web_page_editable.js"); };
})
</script>
{% endblock %}