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

The popup supports custom url option. #1238

Closed
wants to merge 1 commit into from

Conversation

wpjscc
Copy link
Contributor

@wpjscc wpjscc commented Oct 25, 2024

The default request URL for $.popup is location.href

$.popup({...})

Add support for URL parameters

$.popup({url: "https://xxxx.com/backend/plugin/author/action",...})

@bennothommo
Copy link
Member

It already supports an external URL via the ajax property, not the url property. See

url: this.options.ajax,
.

@wpjscc
Copy link
Contributor Author

wpjscc commented Oct 26, 2024

When a handler parameter is present, it appears to be more beneficial. it is quite adept at rendering a form by utilizing the existing configuration.

if (this.options.handler) {

The aforementioned example requires modification.

$.popup({url: "https://xxxx.com/backend/blog/post/update/1", handler: 'onUpdateForm'})

onUpdateForm


    public function onUpdateForm()
    {

        $updateRecordId = $this->params[0] ?? 0;

        $this->asExtension('FormController')->update($updateRecordId, post('context'));
       
        return $this->makePartial('update_form');
    }

update_form.htm


<?= Form::open(['id' => 'xxxx']) ?>

    <div class="modal-header">
        <button type="button" class="close" data-dismiss="popup">&times;</button>
        <h4 class="modal-title"><?=  'update' ?></h4>
    </div>

    <?php if (!$this->fatalError): ?>

        <div class="modal-body">
            <?= $this->formRender() ?>
        </div>

        <div class="modal-footer">
            <button
                type="submit"
                data-request="onSave"
                data-request-data="close:1"
                data-hotkey="ctrl+s, cmd+s"
                data-popup-load-indicator
                class="btn btn-primary">
                <?= e(trans('backend::lang.form.save')) ?>
            </button>

            <button
                type="button"
                class="btn btn-default"
                data-dismiss="popup">
                <?= e(trans('backend::lang.form.cancel')) ?>
            </button>
        </div>


    <?php else: ?>

        <div class="modal-body">
            <p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
        </div>
        <div class="modal-footer">
            <button
                type="button"
                class="btn btn-default"
                data-dismiss="popup">
                <?= e(trans('backend::lang.form.close')) ?>
            </button>
        </div>

    <?php endif ?>
<?= Form::close() ?>

@LukeTowers
Copy link
Member

@wpjscc in your example how does the onSave handler run? The default one in the FormController is not available outside of the update / create actions

@wpjscc
Copy link
Contributor Author

wpjscc commented Oct 26, 2024

@wpjscc in your example how does the onSave handler run? The default one in the FormController is not available outside of the update / create actions

onSave refers to the update_onSave method within the FormController. You are absolutely correct. If changes are made to this in framework.js, it can indeed be invoked. I neglected to make this alteration.

develop...wpjscc-labs:winter:develop

@LukeTowers
Copy link
Member

@wpjscc what exactly are you trying to enable by adding this functionality?

The best I can determine is that you're either trying to add support for editing records in a popup on the list view instead of going directly to an update page; or that you might not be aware that the RelationController exists. Am I close or do you have something else in mind entirely?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants