octobercms / october

Self-hosted CMS platform based on the Laravel PHP Framework.
https://octobercms.com/
Other
11.01k stars 2.21k forks source link

RecordFinder should have a "Remove" option #1669

Closed GRV89 closed 7 years ago

GRV89 commented 8 years ago

Hey! If I select a record in the recordfinder, then later I can not clean it, but sometimes it is necessary (to set a null value). It would be good to implement the mechanism clean recordfinder.

GRV89 commented 8 years ago

as solutions can create a record witdh id 0, and to use it for cleaning)

daftspunk commented 8 years ago

Good point. For justification, can you provide a real-world example that shows a time where you would need to dissociate a record using record finder?

Almusamim commented 8 years ago

I agree there should be a remove/clear button :)

Almusamim commented 8 years ago

1+

yehiaa commented 8 years ago

+1

daftspunk commented 8 years ago

Note to maintainer: Handle #1669 as part of this.

edit: Should have been #1199

oadslug commented 7 years ago

+1. I've tried adding this myself, but having trouble following the code.

In terms of UI, I might suggest the cleanest option would be to add a button to the bottom of the pop-up list window (i.e. 'Delete', 'Clear', or 'Remove' button next to 'Cancel' button?).

SebastiaanKloos commented 7 years ago

+1

MaxNozhkin commented 7 years ago

+1

floatnz commented 7 years ago

+1

floatnz commented 7 years ago

I've written this dirty patch for now; Add to your plugin's javascript. It also watches for pop-up modals and applies to those. (apologies, javascript is not my thing)

(function(){"use strict";
    function initItemLinkRemove(el, index) {
        var $target = this;
        var $input = $('input', $target);
        var $container = $input.closest('.form-group');
        console.log('<<< init item link remover', $input);
        if (!$input.length || $input.attr('data-remove-init') == 'true')
            return;
        $container.append('<button type="button" class="close" style="position:absolute;right:40px;top:32px;background-color:#fff">×</button>');
        $('.close', $container).click(remoteItemLink);
        $input.attr('data-remove-init', 'true');
    }
    function remoteItemLink(e) {
        var $container = $(this).closest('.form-group');
        var $input = $('input', $container);
        var $control = $('.form-control', $container);
        console.log('<<< removing item link', $input.val());
        $input.val('');
        $control.html('<span class="text-muted">Click the <i class="icon-th-list"></i> button to find a record</span>');
    }
    $('.recordfinder-widget').each(initItemLinkRemove);
    MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
    var observer = new MutationObserver(function(mutations, observer) {
        mutations.forEach(function(mutation) {
            var c = mutation.target.getAttribute("class");
            if (c == 'modal-content') {
                $('.recordfinder-widget').each(initItemLinkRemove);
            }
        });
    });
    observer.observe(document, {
      subtree: true,
      attributes: true
    });
});
daftspunk commented 7 years ago

Fixed by #2756

LukeTowers commented 7 years ago

whoot whoot, thanks @daftspunk

blubcow commented 7 years ago

Wow! This is great! Thank you .. and just when I needed it.

WaskiWabit commented 7 years ago

What about adding a new record from within the record finder? Is there a simple yet effective way to accomplish this? Seems strange that it is not already documented.

daftspunk commented 7 years ago

@WaskiWabit Use the RelationController for this http://octobercms.com/docs/backend/relations

WaskiWabit commented 7 years ago

@daftspunk My problem is that I will have tons of records (customers) which is more suited for the RecordFinder. And if a customer doesn't exist, I would like to be able to create one from the record finder instead of leaving my current location and having to go to the customer controller. Is this possible?

LukeTowers commented 7 years ago

@WaskiWabit Yes, try using the RelationController behavior.