From 7dd6b2bb72e6f3f6ece5812017f7b1d2a551aa8b Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Mon, 20 Aug 2012 11:40:53 +1200 Subject: [PATCH] ENHANCEMENT: Nice enabling and disabling of fields when linking a document --- javascript/DMSDocumentAddExistingField.js | 33 ++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/javascript/DMSDocumentAddExistingField.js b/javascript/DMSDocumentAddExistingField.js index 1c237b0..256c97a 100644 --- a/javascript/DMSDocumentAddExistingField.js +++ b/javascript/DMSDocumentAddExistingField.js @@ -39,6 +39,9 @@ var document_id = ui.item.value; $(this).closest('.document-add-existing').adddocument(document_id); + $(this).val(''); + + return false; } } }); @@ -52,23 +55,22 @@ } }); - // TODO - This will become redundant if the above function works - // When clicking on the search input this removes the disabled state - $('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({ - onclick: function() { + $('.document-add-existing .TreeDropdownField').entwine({ + onpanelshow: function() { $(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', true); + }, + onpanelhide: function() { + $(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', $(this).closest('.document-add-existing').find('.document-list:visible').length > 0); } }); - //TODO - When documents load in the document list. Toggle the visibilty of this. By default it should be hidden $('.document-add-existing input[name=PageSelector]').entwine({ onchange: function(event) { - $(this).closest('.document-add-existing').find('.document-list').load( - 'admin/pages/adddocument/documentlist?pageID=' + $(this).val(), - null, - function () { - $(this).show(); - } + var doclist = $(this).closest('.document-add-existing').find('.document-list'); + doclist.html('Loading...'); + doclist.show(); + doclist.load( + 'admin/pages/adddocument/documentlist?pageID=' + $(this).val() ); } @@ -84,7 +86,14 @@ return false; } - }) + }); + + $('body').entwine({ + onclick: function(event) { + $('.document-list:visible').hide() + .closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', false); + } + }); }); }(jQuery)); \ No newline at end of file