Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Working with links and pop-ups for an plugin

Because I'm not allowed to post in Developing, I using this category.

I'm currently developing a plugin, to reservate resources (por example an car), for vanilla and I got a few questions. The plugins appears in a new page (works good) and prints an simple html table (currently reservated resources).

  1. How does the pop up work for activity/discussion deletion? I want to use this also for delete a row via link. Looked already in the discussion model and found the function that deletes the db entry and also found the link generation, but nothing about the pop up.

    // Are you sure? YesNo

  2. I want to open a detailed information page inside a pop up, is this possible not to complicated?

  3. Generally, how does it work to trigger a function via a link with the garden framework? Like the bookmark link.

Thanks everyone for helping me.

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    Not exactly sure what you are looking for (vielleicht kannst du es ja für mich auch kurz mal in Deutsch schreiben), but if you want a confirmation dialog, you do it like that:

    echo anchor(
        t(Delete'),
        'plugin/yourplugin/delete/'.$id.'/'.$this->data('TransientKey'),
        ['class' => 'Button Danger PopConfirm']
    );
    

    The "PopConfirm" class is the magic that triggers the confirmation dialogue.

    You need to have a method in your plugin which is doing the deletion and it should end with:

    $sender->jsonTarget('', '', 'Refresh');
    $sender->render('blank', 'utility', 'dashboard');
    

    You should always check for the correct TransientKey to prevent click jacking

    if (!Gdn::session()->validateTransientKey($transientKey)) {
        throw permissionException();
    }
    
  • The "PopConfirm" class is the magic that triggers the confirmation dialogue.

    This is exactly that what I need. Thanks! :+1:

    You need to have a method in your plugin which is doing the deletion and it should end with:

    (Zu 3. : Wie trigger ich die diese Methode zum löschen, bzw. wo definiere ich welche aufgerufen werden soll?)

  • R_JR_J Ex-Fanboy Munich Admin
    edited December 2017

    In deinem Plugin muss eine solche "delete" Methode implementiert werden. Hier mal ein Code Schnippsel aus einem Plugin, dass ich hier nicht hochgeladen habe:

        public function delete($sender, $options) {
            // Check for valid TransientKey before deleting.
            if (Gdn::session()->validateTransientKey($sender->Request->get('tk'))) {
                Gdn::sql()->delete(
                    $this->tableName,
                    [$this->primaryKey => val('PrimaryKeyValue', $options, 0)]
                );
            }
            redirect($this->indexLink);
        }
    

    In dem View dazu ist dieser Code: <?= anchor(t('Delete'), $link.'/delete/'.$row[$primaryKey].'&tk='.$transientKey, ['class' => 'Button SmallButton Danger PopConfirm']) ?>

    Falls du dein Plugin in einem öffentlichen Repository hast, kann ich gerne mal drüber gucken. Ansonsten kannst du aber auch einfach hier Code einstellen (oberhalb und unterhalb eines Code Blocks musst du jeweils eine Zeile mit drei Tilden ~~~ setzen, damit der Code richtig formatiert ausgegeben wird.


    There must be such a "delete" method implement in the plugin like the one below. It is a code snippet from a Plugin that I haven't uploaded here:

        public function delete($sender, $options) {
            // Check for valid TransientKey before deleting.
            if (Gdn::session()->validateTransientKey($sender->Request->get('tk'))) {
                Gdn::sql()->delete(
                    $this->tableName,
                    [$this->primaryKey => val('PrimaryKeyValue', $options, 0)]
                );
            }
            redirect($this->indexLink);
        }
    

    The accompanying view has the following code: <?= anchor(t('Delete'), $link.'/delete/'.$row[$primaryKey].'&tk='.$transientKey, ['class' => 'Button SmallButton Danger PopConfirm']) ?>

    If you've got your plugin in a public repository, I'll be happy to take a look at it. But you could also paste it here, if you like to (enclose the code with three tildes in a single line above and below in order to get properly formatted code)

  • rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    For the sake of non German speakers who may want to learn from this, can we get a translation bitte?

  • R_JR_J Ex-Fanboy Munich Admin

    Sorry, I was even thinking about answering completely in English but then have been too lazy and only chose German. =)
    It's tempting being able to write in German. @rbrahmson: I've edited the comment above.

  • rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    Danke R_J, I appreciate that. The subject of this discussion intrigued me because of my previous inqueries into popups.

    @timme2707 - sure would be nice to see your plugin.

    Happy Holidays!

  • Happy new year and Dankeschön! =)
    I'll try it out and later put them here.

Sign In or Register to comment.