Advertisement:

Author Topic: Mod that allows deleting packages without refreshing page....  (Read 4287 times)

Offline dougiefresh

  • SMF Hero
  • ******
  • Posts: 2,436
    • XPtsp.com Community
Mod that allows deleting packages without refreshing page....
« on: August 24, 2017, 11:23:53 AM »
Description of Mod
I have written a mod for SMF 2.0.14 that allows one who is browsing the package manager to delete a package without refreshing the page.  It's important to me to have this capability because I have 189 mods on my forum, and deleting one forces me to start looking all over again.  It's kind of annoying, and this mod solves the issue for me.

The Issue
In SMF 2.0.14, I look for this code in Packages.template.php:
Code: (Find) [Select]
', $package['is_installed'] && $package['is_current'] ? ' onclick="return confirm(\'' . $txt['package_delete_bad'] . '\');"' : '', 'and replace it with this code:
Code: (Replace) [Select]
onclick="return ajax_delete(', $package['is_installed'] && $package['is_current'] ? '1' : '0', ', ', $i, ', \'package\', this);"It's done 4 times in the package and the Javascript I wrote works perfectly.

The problem that I am having is trying to adapt it to SMF 2.1 Beta 3.  In SMF 2.1 Beta 3, these lines do not exist!  I found this line in Packages.php:
Code: [Select]
<a href="' . $scripturl . '?action=admin;area=packages;sa=remove;package=' . $package['filename'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '"' . ($package['is_installed'] && $package['is_current'] ? ' data-confirm="' . $txt['package_delete_bad'] . '"' : '') . ' class="button' . ($package['is_installed'] && $package['is_current'] ? ' you_sure' : '') . '">' . $txt['package_delete'] . '</a>';
How do I change this so that my custom code is called for SMF 2.1 Beta 3?

Thanks in advance!

EDIT:  Fixed the "Find" code statement to accurately reflect what I'm looking for....

EDIT # 2:  As a side note, this mod also tackles a side issue, in which the confirmation message is included for as many mods as are installed.  I've have 160 mods installed on my forum at one time.  That string was included 160 TIMES!!!  In this mod, the string is included once in the <html>...</html> tags, and used by the Javascript file....
« Last Edit: August 24, 2017, 11:52:35 AM by dougiefresh »
NOTICE:  My website is back up!

My Free Simple Machines mods on XPtsp.com and Simple Machines Customization Site!
My mods are being uploaded and are available at GitHub as well!

Offline dougiefresh

  • SMF Hero
  • ******
  • Posts: 2,436
    • XPtsp.com Community
Re: Mod that allows deleting packages without refreshing page....
« Reply #1 on: August 24, 2017, 11:16:03 PM »
BTW, the Delete Packages Without Refresh mod in question has been approved and is ready to download....

And yes, I have the Sortable Packages (and Installed Time) mod installed as well.....
NOTICE:  My website is back up!

My Free Simple Machines mods on XPtsp.com and Simple Machines Customization Site!
My mods are being uploaded and are available at GitHub as well!

Offline Steve

  • Support Specialist
  • SMF Hero
  • *
  • Posts: 3,937
  • Gender: Male
  • I have not yet begun to procrastinate.
Re: Mod that allows deleting packages without refreshing page....
« Reply #2 on: August 25, 2017, 07:21:13 AM »
Moved to mods as this applies to the current official release of SMF.
Please do not PM me for support.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,051
    • Arantor on GitHub
Re: Mod that allows deleting packages without refreshing page....
« Reply #3 on: August 25, 2017, 07:42:08 AM »
I wouldn't even do it the way you're proposing. I wouldn't even do an edit to the template.

You can do it in 2.0 but it's easier in 2.1 because jQuery is bundled. You'd add some JS to the page which looks for those links, add a new event handler which receives the click event, tell it to ignore the default (follow the link) and then call ajax_delete.

Note that the sortable packages mod you talk about is also in 2.1 by default.

Though honestly the need for so many mods at once baffles me. I have never had a production SMF with more than 10 mods on it at once...
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Gwenwyfar

  • Customizer
  • Full Member
  • *
  • Posts: 693
  • Gender: Female
    • Gwenwyfar on GitHub
Re: Mod that allows deleting packages without refreshing page....
« Reply #4 on: August 25, 2017, 09:04:02 AM »
I wouldn't even do it the way you're proposing. I wouldn't even do an edit to the template.

You can do it in 2.0 but it's easier in 2.1 because jQuery is bundled. You'd add some JS to the page which looks for those links, add a new event handler which receives the click event, tell it to ignore the default (follow the link) and then call ajax_delete.

Note that the sortable packages mod you talk about is also in 2.1 by default.

Though honestly the need for so many mods at once baffles me. I have never had a production SMF with more than 10 mods on it at once...
Which would then still work if JS is disabled :)

I can see this kind of feature being more useful in board managing, but its nice to have as long as it doesn't eat too many resources. And forums with tons of mods installed is very common at the end of the day.

Offline dougiefresh

  • SMF Hero
  • ******
  • Posts: 2,436
    • XPtsp.com Community
Re: Mod that allows deleting packages without refreshing page....
« Reply #5 on: August 25, 2017, 10:13:48 AM »
I wouldn't even do it the way you're proposing. I wouldn't even do an edit to the template.
One of the reasons I'm doing template edits is so that I can fix the mod numbering in the column before the package name, as well as to fix the alternating div backgrounds.  Both get messed up when I delete a package using my AJAX function....

You can do it in 2.0 but it's easier in 2.1 because jQuery is bundled. You'd add some JS to the page which looks for those links, add a new event handler which receives the click event, tell it to ignore the default (follow the link) and then call ajax_delete.
Any chance you could give me sample code to work with?  Or even a link to what you're talking about?  My Javascript is a bit rusty (and my experience with Javascript a bit more)....

EDIT:  I'm trying to stay away from JQuery as much as I can (at least for SMF 2.0.x), just so that I don't have to add additional requirements to the mod....

Note that the sortable packages mod you talk about is also in 2.1 by default.
Yeah, I saw that!  I just included that mod because it helps, but it's not a great answer when one has so many mods...

Which would then still work if JS is disabled :)
Obviously the goal!  O:)
« Last Edit: August 25, 2017, 10:36:05 AM by dougiefresh »
NOTICE:  My website is back up!

My Free Simple Machines mods on XPtsp.com and Simple Machines Customization Site!
My mods are being uploaded and are available at GitHub as well!

Offline Gwenwyfar

  • Customizer
  • Full Member
  • *
  • Posts: 693
  • Gender: Female
    • Gwenwyfar on GitHub
Re: Mod that allows deleting packages without refreshing page....
« Reply #6 on: August 25, 2017, 11:24:27 AM »
Obviously the goal!  O:)
Extra bonus with no effort involved. Though my thinking was more that it could be on core if there are no downsides :)

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,051
    • Arantor on GitHub
Re: Mod that allows deleting packages without refreshing page....
« Reply #7 on: August 25, 2017, 02:01:46 PM »
If you're planning to keep all the numbers the same... best of luck to you, because it's basically impossible to do in a reasonable amount of code.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline dougiefresh

  • SMF Hero
  • ******
  • Posts: 2,436
    • XPtsp.com Community
Re: Mod that allows deleting packages without refreshing page....
« Reply #8 on: August 28, 2017, 10:31:15 AM »
I completely rewrote the mod to use hooks, and altered the buffer before it was sent to the user.  Problem solved.
NOTICE:  My website is back up!

My Free Simple Machines mods on XPtsp.com and Simple Machines Customization Site!
My mods are being uploaded and are available at GitHub as well!