Skip to content

Commit

Permalink
metadata_general attaches existing file via AJAX. See ome#6193
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Moore committed Jan 3, 2012
1 parent 42c3af8 commit 03b1a0a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def createFileAnnotation(self, otype, newFile):
l_ia.setParent(selfobject._obj)
l_ia.setChild(fa)
link_obj = self.conn.getUpdateService().saveAndReturnObject(l_ia)
# need to retrieve Annotation with link loaded
# need to retrieve Annotation with link loaded - should only be 1 link to this annotation
links = self.conn.getAnnotationLinks (otype, ann_ids=[link_obj.child.getId().getValue()])
fa_link = links.next() # get first item in generator
fa = fa_link.getAnnotation()
Expand Down Expand Up @@ -793,7 +793,11 @@ def createAnnotationLinks(self, otype, atype, ids):
self.conn.saveObject(l)
except:
failed+=1
return failed

# need to retrieve Annotations with links loaded
links = self.conn.getAnnotationLinks (otype, parent_ids=[selfobject.getId()], ann_ids=ids)
fas = [fa_link.getAnnotation() for fa_link in links]
return fas

def createAnnotationsLinks(self, atype, tids, oids):
#TODO: check if link already exist !!!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% load i18n %}
{% load common_filters %}
{% load wikitags %}

{% comment %}
<!--
Copyright (C) 2011 University of Dundee & Open Microscopy Environment.
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
{% endcomment %}

{% comment %}
<!--
This file-annotations block is used as an AJAX response, when linking multiple file-annotations to the metadata_general panel.
-->
{% endcomment %}


{% for fileann in fileanns %}
{% include "webclient/annotations/fileann.html" %}
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,14 @@
$(".dropdown_menu_options").hover(function(){}, function(){
$(this).css('visibility', 'hidden');
}).hide();



// Choose to upload a local file...
$("#choose_local_document").click(function(event) {
$("#upload_file_form input[type=file]").click();
$("#upload_file_form input[type=file]").click(); // 'click' the hidden file field to launch file chooser
return false;
});
// handle the file chooser closing: submit the form if we have a value
$('#upload_file_form input[type=file]').bind('change focus', function() {
var value = $(this).val();
var $form = $("#upload_file_form");
Expand All @@ -314,7 +317,7 @@
}
return false;
});

// set-up the form to use AJAX. (requires jquery.form.js plugin)
$('#upload_file_form').ajaxForm({
success: function(data) {
// update the list of file annotations and bind actions
Expand All @@ -329,6 +332,57 @@
}
});


// prepare dialog for choosing file to attach...
$("#choose_attachments_form").dialog({
autoOpen: false,
resizable: true,
height: 210,
width:420,
modal: true,
buttons: {
"Accept": function() {
$("#choose_attachments_form").data("clicked_button", "Accept");
$( this ).dialog( "close" );
},
"Cancel": function() {
$("#choose_attachments_form").data("clicked_button", "Cancel");
$( this ).dialog( "close" );
}
}
});
// show dialog for choosing file to attach...
$("#choose_uploaded_document").click(function() {
// show dialog first, then do the AJAX call to load files...
var attach_form = $( "#choose_attachments_form" );
attach_form.dialog( "open" );
$.removeData(attach_form, "clicked_button"); // clear previous data
attach_form.unbind("dialogclose");
attach_form.bind("dialogclose", function(event, ui) {
if (attach_form.data("clicked_button") == "Accept") {
$("#choose_attachments_form form").submit();
}
});
// load form via AJAX...
var load_url = $(this).attr('href');
$("form", attach_form).load(load_url + " #id_files"); // only load the files field
return false;
});
// set-up the form to use AJAX. (requires jquery.form.js plugin)
$('#choose_attachments_form form').ajaxForm({
success: function(data) {
// update the list of file annotations and bind actions
var $fileanns = $(data)
$("#fileanns_container").prepend( $fileanns );
$(".deleteFile", $fileanns).click(function(event) {
deleteItem(event, "file_ann_wrapper");
});
$(".removeFile", $fileanns).click(function(event) {
removeItem(event, "file_ann_wrapper");
});
}
});

});

</script>
Expand Down Expand Up @@ -761,7 +815,11 @@ <h1>{% trans "Annotations" %}</h1>
</span>
<ul class="dropdown_menu_options">
<li><a id="choose_local_document" href="#">Local document...</a></li>
<li><a href="{% url manage_action_containers 'newfile' manager.obj_type manager.obj_id %}?url={{url}}">Uploaded document...</a></li>
<li>
<a id="choose_uploaded_document" href="{% url manage_action_containers 'newfile' manager.obj_type manager.obj_id %}?url={{url}}">
Uploaded document...
</a>
</li>
</ul>
</span>
{% endif %}
Expand All @@ -773,6 +831,15 @@ <h1>{% trans "Annotations" %}</h1>
{{ field }}
{% endfor %}
</form>

<!-- hidden form for choosing uploaded file in dialog - load form via AJAX when we show dialog -->
<div id="choose_attachments_form" title="Select Attachments">
<p>Select the Attachments to add</p>
<form action="{% url manage_action_containers 'usefile' manager.obj_type manager.obj_id %}" method="post">
Load form here...
</form>
</div>

</td>
<td>
<div id="fileanns_container" class="lnfiles">
Expand Down
10 changes: 5 additions & 5 deletions components/tools/OmeroWeb/omeroweb/webclient/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,11 +1569,10 @@ def manage_action_containers(request, action, o_type=None, o_id=None, **kwargs):
form_tags = TagListForm(initial={'tags':manager.getTagsByObject()})
context = {'nav':request.session['nav'], 'url':url, 'manager':manager, 'eContext':manager.eContext, 'form_tag':form_tag, 'form_tags':form_tags, 'index':index}
elif action == 'newfile':
# form for attaching new file (upload) or existing one.
# form for attaching existing file Annotation (used via AJAX to load into dialog).
template = "webclient/annotations/annotation_new_form.html"
form_file = UploadFileForm()
form_files = FileListForm(initial={'files':manager.getFilesByObject()})
context = {'nav':request.session['nav'], 'url':url, 'manager':manager, 'eContext':manager.eContext, 'form_file':form_file, 'form_files':form_files, 'index':index}
context = {'nav':request.session['nav'], 'url':url, 'manager':manager, 'eContext':manager.eContext, 'form_files':form_files, 'index':index}
elif action == 'newsharecomment':
# TODO: not used now?
template = "webclient/annotations/annotation_new_form.html"
Expand Down Expand Up @@ -1933,8 +1932,9 @@ def manage_action_containers(request, action, o_type=None, o_id=None, **kwargs):
form_files = FileListForm(data=request.REQUEST.copy(), initial={'files':file_list})
if form_files.is_valid() and o_type is not None and o_id > 0:
files = request.POST.getlist('files')
manager.createAnnotationLinks(o_type, 'file', files)
return HttpResponseRedirect(url)
fileanns = manager.createAnnotationLinks(o_type, 'file', files)
template = "webclient/annotations/fileanns.html"
context = {'fileanns': fileanns}
else:
template = "webclient/annotations/annotation_new_form.html"
context = {'nav':request.session['nav'], 'url':url, 'manager':manager, 'eContext':manager.eContext, 'form_files':form_files, 'index':index}
Expand Down

0 comments on commit 03b1a0a

Please sign in to comment.