@hglibrary
def read(self, request, form, docid, lib):
"""Read document's meta data"""
- log.info(u"User '%s' wants to %s(%s) as %s" % \
+ log.info(u"User '%s' wants to edit %s(%s) as %s" % \
(request.user.username, docid, form.cleaned_data['revision'], form.cleaned_data['user']) )
user = form.cleaned_data['user'] or request.user.username
'reason': 'not-found', 'message': e.message})
except librarian.ValidationError, e:
return response.InternalError().django_response({
- 'reason': 'xml-non-valid', 'message': e.message })
+ 'reason': 'xml-non-valid', 'message': e.message or u''})
except librarian.ParseError, e:
return response.InternalError().django_response({
- 'reason': 'xml-parse-error', 'message': e.message })
+ 'reason': 'xml-parse-error', 'message': e.message or u'' })
#
# Image Gallery
user = form.cleaned_data['user'] or request.user.username
format = form.cleaned_data['format']
- document = lib.document_for_rev(revision)
+ document = lib.document_for_revision(revision)
if document.id != docid:
return response.BadRequest().django_response({
@validate_form(forms.TextUpdateForm, 'POST')
@hglibrary
def create(self, request, form, docid, lib):
+ lock = lib.lock();
try:
revision = form.cleaned_data['revision']
msg = form.cleaned_data['message']
# do not allow changing not owned documents
# (for now... )
-
if user != request.user.username:
return response.AccessDenied().django_response({
'reason': 'insufficient-priviliges',
})
current = lib.document(docid, user)
- orig = lib.document_for_rev(revision)
+ orig = lib.document_for_revision(revision)
if current != orig:
return response.EntityConflict().django_response({
"provided_revision": orig.revision,
"latest_revision": current.revision })
- if form.cleaned_data.has_key('contents'):
+ if form.cleaned_data['contents']:
data = form.cleaned_data['contents']
else:
chunks = form.cleaned_data['chunks']
- xdoc = parser.WLDocument.from_string(current.data('xml'))
+ data = current.data('xml')
+ log.info(data[:600])
+ log.info(chunks)
+
+ xdoc = parser.WLDocument.from_string(data)
errors = xdoc.merge_chunks(chunks)
if len(errors):
data = xdoc.serialize()
+
# try to find any Xinclude tags
includes = [m.groupdict()['link'] for m in (re.finditer(\
XINCLUDE_REGEXP, data, flags=re.UNICODE) or []) ]
except RevisionNotFound, e:
return response.EntityNotFound(mimetype="text/plain").\
django_response(e.message)
+ finally:
+ lock.release()
self.invoke_and_commit(take_action, \
lambda d: ("$AUTO$ File checkout.", user) )
- return self._library.document_for_rev(fullid)
+ return self._library.document_for_revision(fullid)
def up_to_date(self):
if self.ismain():
return fulldocid
def has_revision(self, revid):
+ revid = self._sanitize_string(revid)
+
try:
self._hgrepo[revid]
return True
counter-increment: main;
}
+.htmlview .annotation:hover {
+ background-color: #dfdfdf;
+}
+
+.parse-warning .message {
+ color: purple;
+ font-weight: bold;
+}
+
+
+/*
+ * EDITABLE ELEMENTS
+ */
+
.htmlview *[x-editable] {
border: 2px solid white;
padding: 5px;
}
/* focused editable element */
-.htmlview *[x-editable]:hover,
-.htmlview *[x-editable][x-open]
+.htmlview *[x-editable]:hover
{
background-color: #dfdfdf;
border: 2px solid black;
+ z-index: 100;
}
-.htmlview *[x-editable] *.context-menu {
+.htmlview *[x-editable][x-open]
+{
+ visibility: hidden;
+}
+
+.htmlview *[x-editable] .context-menu {
position: absolute;
- top: -24px;
+ top: -28px;
left: -2px;
height: 24px;
border-right: 2px solid black;
display: none;
+ visibility: visible;
overflow: hidden;
-moz-border-radius-topright: 5px;
-webkit-border-top-right-radius: 5px;
-webkit-border-top-left-radius: 5px;
+
+ z-index: 3000;
}
.htmlview *[x-editable] *.context-menu * {
.htmlview *[x-editable] *.context-menu *:hover {
background-color: yellow;
+ z-index: 3100;
}
-.htmlview *[x-editable]:hover *.context-menu {
+/*
+ * VISIBILITY RULES
+ */
+.htmlview *[x-editable]:hover *.default-menu {
display: block;
}
-.htmlview *[x-editable][x-open] *.context-menu {
+.htmlview *[x-editable][x-open] *.default-menu {
display: none;
}
-.htmlview .annotation:hover {
- background-color: #dfdfdf;
+.htmlview *[x-editable][x-open] *.edit-menu {
+ display: block;
}
-.parse-warning .message {
- color: purple;
- font-weight: bold;
+.html-editarea {
+ border: 2px solid black;
+ background-color: gray;
+ padding: 1px;
+
+ z-index: 2000;
+}
+
+.html-editarea textarea
+{
+ border: 0px;
+ margin: 0px;
+ padding: 0px;
+
+ width: 100%;
+ height: 100%;
+
+ z-index: 0;
+ font-size: 10pt;
+ background-color: ivory;
}
+
+.html-editarea p.html-editarea-toolbar {
+ position: absolute;
+ background: gray;
+
+ bottom: -26px;
+ height: 24px;
+
+ left: 0px;
+ right: 0px;
+
+ border: 2px solid black;
+
+ margin: 0px;
+ padding: 0px;
+
+ z-index: 100;
+}
+
+
border-right: 1px solid #999;
height: 100%;
background-color: #CCC;
- z-index: 100;
+ z-index: 5100;
}
.splitview-overlay {
- z-index: 90;
+ z-index: 5000;
background: #FFF;
opacity: 0.5;
}
background-color: #EEE;
}
-/* HTML editor interactive elements */
-
-.html-editarea {
- border: 2px solid black;
- background-color: gray;
- padding: 1px;
-
- z-index: 2000;
-}
-
-.html-editarea textarea
-{
-
- border: 0px;
- margin: 0px;
- padding: 0px;
-
- width: 100%;
- height: 100%;
-
- z-index: 0;
- font-size: 10pt;
- background-color: ivory;
-}
-
-.html-editarea p.html-editarea-toolbar {
- position: absolute;
- background: gray;
-
- bottom: -26px;
- height: 24px;
-
- left: 0px;
- right: 0px;
-
- border: 2px solid black;
- margin: 0px;
- padding: 0px;
-
- z-index: 100;
-}
/* ================= */
/* = Message boxes = */
});
},
- putXMLPart: function(elem, data) {
+ putXMLPart: function(elem, data, callback) {
var self = this;
var path = elem.attr('x-pointer');
// format: 'nl'
},
success: function(htmldata) {
- elem.html(htmldata);
+ callback(elem, htmldata);
self.set('state', 'dirty');
}
});
.addObserver(this, 'state', this.modelStateChanged.bind(this));
$('.htmlview', this.element).html(this.model.get('data'));
+
+ this.$menuTemplate = $(render_template('html-view-frag-menu-template', this));
+
this.modelStateChanged('state', this.model.get('state'));
- this.model.load();
+ this.model.load();
+
+ this.currentOpen = null;
},
modelDataChanged: function(property, value) {
$('.htmlview', this.element).html(value);
this.updatePrintLink();
-
+ var self = this;
+
$("*[x-editable]").each(function() {
- var e = $('<span class="context-menu"><span class="edit-button">Edytuj</span><span>Przypisy</span></span>');
- e.appendTo(this);
+ $(this).append( self.$menuTemplate.clone() );
});
},
if (value == 'synced' || value == 'dirty') {
this.unfreeze();
} else if (value == 'unsynced') {
+ if(this.currentOpen) this.closeWithoutSave(this.currentOpen);
this.freeze('Niezsynchronizowany...');
} else if (value == 'loading') {
this.freeze('Ćadowanie...');
this._super();
},
- itemHover: function(event)
- {
- var $e = $(event.target);
- if( $e.attr('x-editable') == 'editable' ) {
- console.log('over:', $e[0]);
- $e.css({'background-color': 'grey'});
- }
-
- },
-
itemClicked: function(event)
{
var self = this;
- console.log('click:', event, event.ctrlKey, event.target);
- var editableContent = null;
+ console.log('click:', event, event.ctrlKey, event.target);
var $e = $(event.target);
if($e.hasClass('edit-button'))
- this.openForEdit($e);
+ this.openForEdit( this.editableFor($e) );
+
+ if($e.hasClass('accept-button'))
+ this.closeWithSave( this.editableFor($e) );
+
+ if($e.hasClass('reject-button'))
+ this.closeWithoutSave( this.editableFor($e) );
},
- openForEdit: function($e)
- {
- var n = 0;
+ closeWithSave: function($e) {
+ var $edit = $e.data('edit-overlay');
+ var newText = $('textarea', $edit).val();
+
+ this.model.putXMLPart($e, newText, function($e, html) {
+ this.renderPart($e, html);
+ $edit.remove();
+ $e.removeAttr('x-open');
+ }.bind(this) );
+ this.currentOpen = null;
+ },
+
+ closeWithoutSave: function($e) {
+ var $edit = $e.data('edit-overlay');
+ $edit.remove();
+ $e.removeAttr('x-open');
+ this.currentOpen = null;
+ },
- while( ($e[0] != this.element[0]) && !($e.attr('x-editable'))
- && n < 50)
+ renderPart: function($e, html) {
+ $e.html(html);
+ $e.append( this.$menuTemplate.clone() );
+ },
+
+ editableFor: function($button)
+ {
+ var $e = $button;
+ var n = 0;
+
+ while( ($e[0] != this.element[0]) && !($e.attr('x-editable')) && n < 50)
{
// console.log($e, $e.parent(), this.element);
$e = $e.parent();
n += 1;
}
-
+
if(!$e.attr('x-editable'))
- return true;
+ throw Exception("Click outside of editable")
+
+ return $e;
+ },
- var $origin = $e;
- console.log("editable: ", $e);
+ openForEdit: function($origin)
+ {
+ if(this.currentOpen && this.currentOpen != $origin) {
+ this.closeWithSave(this.currentOpen);
+
+ }
// start edition on this node
- var $overlay = $(
- '<div class="html-editarea">\n\
- <p class="html-editarea-toolbar">\n\
- <button class="html-editarea-save-button" type="button">Zapisz</button>\n\
- <button class="html-editarea-cancel-button" type="button">Anuluj</button>\n\
- </p>\n\
- <textarea></textarea>\n\
- </div>');
-
- var x = $e[0].offsetLeft;
- var y = $e[0].offsetTop;
- var w = $e.outerWidth();
- var h = $e.innerHeight();
- $overlay.css({position: 'absolute', height: 1.2*h, left: x, top: y, width: w});
- // $e.offsetParent().append($overlay);
+ var $overlay = $('<div class="html-editarea"><textarea></textarea></div>');
+ var x = $origin[0].offsetLeft;
+ var y = $origin[0].offsetTop;
+ var w = $origin.outerWidth();
+ var h = $origin.innerHeight();
-
- /* $('.html-editarea-cancel-button', $overlay).click(function() {
- $overlay.remove();
- });
-
- $('.html-editarea-save-button', $overlay).click(function() {
- $overlay.remove();
-
- // put the part back to the model
- self.model.putXMLPart($e, $('textarea', $overlay).val());
- }); */
-
- this.model.getXMLPart($e, function(path, data) {
- $('textarea', $overlay).val(data);
- });
+ $overlay.css({position: 'absolute', height: h, left: x, top: y, width: '95%'});
+
+ $origin.offsetParent().append($overlay);
+ $origin.data('edit-overlay', $overlay);
+
+ this.model.getXMLPart($origin, function(path, data) {
+ $('textarea', $overlay).val(data);
+ });
- $origin.attr('x-open', 'open');
+ this.currentOpen = $origin;
+ $origin.attr('x-open', 'open');
+
+
return false;
}
<div class="htmlview">
</div>
</script>
+
+ <script type="text/html" charset="utf-8" id="html-view-frag-menu-template">
+ <span class="default-menu context-menu">
+ <span class="edit-button">Edytuj</span>
+ </span>
+ <span class="edit-menu context-menu">
+ <span class="accept-button">OK</span>
+ <span class="reject-button">Anuluj</span>
+ </span>
+ </script>
+
+
<script type="text/html" charset="utf-8" id="flash-view-template">
<div class="flashview">