SMF Community Helpers > Customization Development

Mod that allows deleting packages without refreshing page....

(1/2) > >>

dougiefresh:
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) ---', $package['is_installed'] && $package['is_current'] ? ' onclick="return confirm(\'' . $txt['package_delete_bad'] . '\');"' : '', '
--- End code ---
and replace it with this code:

--- Code: (Replace) --- onclick="return ajax_delete(', $package['is_installed'] && $package['is_current'] ? '1' : '0', ', ', $i, ', \'package\', this);"
--- End code ---
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: ---<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>';

--- End code ---
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....

dougiefresh:
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.....

Steve:
Moved to mods as this applies to the current official release of SMF.

Arantor:
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...

Gwenwyfar:

--- Quote from: Arantor 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...

--- End quote ---
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.

Navigation

[0] Message Index

[#] Next page

Go to full version