Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove add/edit options of ReferenceWidget #1541

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Changelog

**Removed**

- #1541 Remove add/edit options of ReferenceWidget
- #1535 Remove `zcatalog` monkey (and `getRequestUID` index)
- #1518 Removed stale indexes from `analysis_catalog`
- #1516 Removed getResultsRange metadata from analysis_catalog
Expand Down
21 changes: 0 additions & 21 deletions bika/lims/browser/bootstrap/static/css/bootstrap-integration.css
Original file line number Diff line number Diff line change
Expand Up @@ -358,27 +358,6 @@ div.overlay div.close {
width: 30px;
opacity: 1;
}
/* /Fixture for overlays */

/* Patient and Doctor Add and Edit buttons */
a.add-button {
font-weight: bold;
background: transparent url(++resource++bika.lims.images/add.png) left center no-repeat;
padding: 8px 8px 8px 10px;
}
a.edit-button {
font-weight: bold;
background: transparent url(++resource++bika.lims.images/edit.png) left center no-repeat;
padding: 8px 8px 8px 10px;
}
#content a.add-button.referencewidget-add-button.link-overlay,
#content a.edit-button.referencewidget-edit-button.link-overlay {
border-bottom: medium none !important;
}
h2 a.add-button {
padding: 12px 0 0 38px;
background-position: 15px 10px;
}

/* Flatten the first heading from content a bit
https://github.com/senaite/senaite.lims/pull/92 */
Expand Down
Binary file removed bika/lims/browser/images/edit.png
Binary file not shown.
Binary file removed bika/lims/browser/images/edit_big.png
Binary file not shown.
25 changes: 0 additions & 25 deletions bika/lims/browser/js/bika.lims.site.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
this.get_portal_url = bind(this.get_portal_url, this);
this.init_referencedefinition = bind(this.init_referencedefinition, this);
this.init_datepickers = bind(this.init_datepickers, this);
this.init_client_add_overlay = bind(this.init_client_add_overlay, this);
this.bind_eventhandler = bind(this.bind_eventhandler, this);
this.load = bind(this.load, this);
}
Expand All @@ -39,7 +38,6 @@
console.debug("SiteView::load");
jarn.i18n.loadCatalog('senaite.core');
this._ = window.jarn.i18n.MessageFactory("senaite.core");
this.init_client_add_overlay();
this.init_datepickers();
this.init_referencedefinition();
this.bind_eventhandler();
Expand Down Expand Up @@ -80,29 +78,6 @@
});
};

SiteView.prototype.init_client_add_overlay = function() {

/*
* Initialize Client Overlay
*/
console.debug("SiteView::init_client_add_overlay");
return $('a.add_client').prepOverlay({
subtype: 'ajax',
filter: 'head>*,#content>*:not(div.configlet),dl.portalMessage.error,dl.portalMessage.info',
formselector: '#client-base-edit',
closeselector: '[name="form.button.cancel"]',
width: '70%',
noform: 'close',
config: {
closeOnEsc: false,
onLoad: function() {
this.getOverlay().find('.ArchetypesRemarksWidget').remove();
},
onClose: function() {}
}
});
};

SiteView.prototype.init_datepickers = function() {

/*
Expand Down
27 changes: 0 additions & 27 deletions bika/lims/browser/js/coffee/bika.lims.site.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ class window.SiteView
jarn.i18n.loadCatalog 'senaite.core'
@_ = window.jarn.i18n.MessageFactory("senaite.core")

# initialze the client add overlay
@init_client_add_overlay()

# initialze datepickers
@init_datepickers()

Expand Down Expand Up @@ -88,30 +85,6 @@ class window.SiteView
return


init_client_add_overlay: =>
###
* Initialize Client Overlay
###
console.debug "SiteView::init_client_add_overlay"

$('a.add_client').prepOverlay
subtype: 'ajax'
filter: 'head>*,#content>*:not(div.configlet),dl.portalMessage.error,dl.portalMessage.info'
formselector: '#client-base-edit'
closeselector: '[name="form.button.cancel"]'
width: '70%'
noform: 'close'
config:
closeOnEsc: false
onLoad: ->
# manually remove remarks
@getOverlay().find('.ArchetypesRemarksWidget').remove()
return
onClose: ->
# here is where we'd populate the form controls, if we cared to.
return


init_datepickers: =>
###
* Initialize date pickers
Expand Down
45 changes: 0 additions & 45 deletions bika/lims/browser/widgets/referencewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@ class ReferenceWidget(StringWidget):
'sidx': 'Title',
'force_all': False,
'portal_types': {},
'add_button': {
'visible': False,
'url': '',
'js_controllers': [],
'return_fields': [],
'overlay_options': {},
},
'edit_button': {
'visible': False,
'url': '',
'js_controllers': [],
'return_fields': [],
'overlay_options': {},
},
})
security = ClassSecurityInfo()

Expand Down Expand Up @@ -161,37 +147,6 @@ def initial_uid_field_value(self, value):
ret = value.UID() if value else value
return ret

def get_addbutton_options(self):
# Return a dict with the options defined in the schema whose widget needs an add button.
return {
'visible': self.add_button.get('visible', False),
'url': self.add_button.get('url'),
'return_fields': json.dumps(self.add_button.get('return_fields')),
'js_controllers': json.dumps(self.add_button.get('js_controllers',[])),
'overlay_handler': self.add_button.get('overlay_handler', ''),
'overlay_options': json.dumps(self.add_button.get('overlay_options',{
'filter': 'head>*,#content>*:not(div.configlet),dl.portalMessage.error,dl.portalMessage.info',
'formselector': 'form[id$="base-edit"]',
'closeselector': '[name="form.button.cancel"]',
'width': '70%',
'noform': 'close',}))
}

def get_editbutton_options(self):
# Return a dict with the options defined in the schema whose widget needs an edit button.
return {
'visible': self.edit_button.get('visible', False),
'url': self.edit_button.get('url'),
'return_fields': json.dumps(self.edit_button.get('return_fields')),
'js_controllers': json.dumps(self.edit_button.get('js_controllers',[])),
'overlay_handler': self.edit_button.get('overlay_handler', ''),
'overlay_options': json.dumps(self.edit_button.get('overlay_options',{
'filter': 'head>*,#content>*:not(div.configlet),dl.portalMessage.error,dl.portalMessage.info',
'formselector': 'form[id$="base-edit"]',
'closeselector': '[name="form.button.cancel"]',
'width': '70%',
'noform': 'close',}))
}

registerWidget(ReferenceWidget, title='Reference Widget')

Expand Down
7 changes: 0 additions & 7 deletions bika/lims/content/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,6 @@
"sort_on": "sortable_title",
"sort_order": "ascending"},
showOn=True,
add_button={
'visible': True,
'url': 'clients/createObject?type_name=Client',
'return_fields': ['Title'],
'js_controllers': ['#client-base-edit'],
'overlay_handler': 'ClientOverlayHandler',
}
),
),

Expand Down
136 changes: 0 additions & 136 deletions bika/lims/skins/bika/bika_widgets/referencewidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
save_UID_check();
check_UID_check();
check_missing_UID();
load_addbutton_overlays();
load_editbutton_overlays();
});

}(jQuery));
Expand Down Expand Up @@ -238,137 +236,3 @@ function check_missing_UID(){
}
)
}

function apply_button_overlay(button) {
/**
* Given an element (button), this function sets its overlay options.
* The overlay options to be applied are retrieved from the button's
* data_overlay attribute.
* Further info about jQuery overlay:
* http://jquerytools.github.io/documentation/overlay/
*/
// Obtain overlay options from html button attributes.
var options = $.parseJSON($(button).attr('data_overlay'));
options['subtype'] = 'ajax';
var config = {};

// overlay.OnLoad javascript snippet
config['onLoad'] = function () {
var triggerid = "[rel='#" + this.getTrigger().attr('id') + "']";
// If there are defined some jsControllers, they'll be reloaded every time the overlay is loaded.
var jscontrollers = $(triggerid).attr('data_jscontrollers');
jscontrollers = $.parseJSON(jscontrollers);
if (jscontrollers.length > 0) {
window.bika.lims.loadControllers(false, jscontrollers);
}
// Check personalized onLoad functionalities.
var handler = $(triggerid).attr('data_overlay_handler');
if (handler != '') {
var fn = window[handler];
if (typeof fn === "function") {
handler = new fn();
if (typeof handler.onLoad === "function") {
handler.onLoad(this);
}
}
}
};

// overlay.OnBeforeClose javascript snippet
config['onBeforeClose'] = function () {
var triggerid = "[rel='#" + this.getTrigger().attr('id') + "']";
var handler = $(triggerid).attr('data_overlay_handler');
if (handler != '') {
var fn = window[handler];
if (typeof fn === "function") {
handler = new fn();
if (typeof handler.onBeforeClose === "function") {
handler.onBeforeClose(this);
// Done, exit
return true;
}
}
}
var retfields = $.parseJSON($(triggerid).attr('data_returnfields'));
if (retfields.length > 0) {
// Default behaviour.
// Set the value from the returnfields to the input
// and select the first option.
// This might be improved by finding a way to get the
// uid of the object created/edited and assign directly
// the value to the underlaying referencewidget
var retvals = [];
$.each(retfields, function (index, value) {
var retval = $('div.overlay #' + value).val();
if (retval != '') {
retvals.push(retval);
}
});
if (retvals.length > 0) {
retvals = retvals.join(' ');
$(triggerid).prev('input').val(retvals).focus();
setTimeout(function () {
$('.cg-DivItem').first().click();
}, 500);
}
}
return true;
};
options['config'] = config;
$(button).prepOverlay(options);
}

function load_addbutton_overlays() {
/**
* Add the overlay conditions for the AddButton.
*/
$('a.referencewidget-add-button').each(function (i) {
apply_button_overlay('#' + $(this).attr('id'));
});
}

function load_editbutton_overlay(button) {
/**
* Given an element (button), show/hide the element depending on its trigger UID.
* No UID -> No object selected -> Noting to edit -> hide edit
* Yes UID -> Object selected -> Something to edit -> show edit.
*/
var element = '#' + $(button).attr('data_fieldid');
var uid = $(element).attr('uid');
// No UID found -> Hide Edit button
if (!uid || uid == '') {
$(button).hide();
}
else {
// UID found -> Show Edit button & update href attribute
$(button).show();
// Get object's id
var request_data = {
catalog_name: "uid_catalog",
UID: uid
};
window.bika.lims.jsonapi_read(request_data, function (data) {
var root_href = $(button).attr('data_baseurl');
var id = data.objects[0].id;
$(button).attr('href', root_href + "/" + id + '/edit');
apply_button_overlay(button);
});
}
}

function load_editbutton_overlays() {
/**
* Add the overlay conditions for the EditButton.
*/
$('a.referencewidget-edit-button').each(function (i) {
var button = '#' + $(this).attr('id');
var fieldid = '#' + $(this).attr('data_fieldid');

$(fieldid).bind("selected blur paste", function () {
var button = '#' + $(this).siblings('a.referencewidget-edit-button').attr('id');
load_editbutton_overlay(button);
});

load_editbutton_overlay(button);
});
}
35 changes: 0 additions & 35 deletions bika/lims/skins/bika/bika_widgets/referencewidget.pt
Original file line number Diff line number Diff line change
Expand Up @@ -116,41 +116,6 @@
multiValued python:1 if context.Schema()[fieldName].multiValued else 0;
combogrid_options python:widget.get_combogrid_options(context, fieldName)" />

<!-- AddButton definition -->
<a rel='#overlay'
class='add-button referencewidget-add-button'
tal:define="options python:widget.get_addbutton_options()"
tal:condition="options/visible"
tal:attributes="name python:fieldName+'_addbutton';
id python:fieldName+'_addbutton';
href string:${portal/absolute_url}/${options/url};
data_fieldid fieldName;
data_fieldname fieldName;
data_overlay_handler options/overlay_handler;
data_returnfields options/return_fields;
data_jscontrollers options/js_controllers;
data_overlay options/overlay_options">
<span class='notext' i18n:translate="">Add</span>
</a>

<!-- EditButton definition -->
<a rel='#overlay'
class='edit-button referencewidget-edit-button'
tal:define="options python:widget.get_editbutton_options()"
tal:condition="options/visible"
tal:attributes="name python:fieldName+'_editbutton';
id python:fieldName+'_editbutton';
href string:${portal/absolute_url}/${options/url};
data_baseurl string:${portal/absolute_url}/${options/url};
data_fieldid fieldName;
data_fieldname fieldName;
data_overlay_handler options/overlay_handler;
data_returnfields options/return_fields;
data_jscontrollers options/js_controllers;
data_overlay options/overlay_options">
<span class='notext' i18n:translate="">Edit</span>
</a>

<input type="hidden"
name=""
value=""
Expand Down