Does Mybb have this ?
#1
Hi
I am in the process of producing a plugin but I can not find an answer to this :-
Within Admin CP is there an event to check if a produced object has been changed - so if a combobox has changed value - do something
Example
if the combobox contains usergroups, on change perhaps an other created object changes to suit the combobox value, so perhaps a textbox could then display the amount of users in that group.

any ideas ?
Not in this land alone,
But be God's mercies known,
From shore to shore!
Lord make the nations see,
That men should brothers be,
And form one family,
The wide world ov'er

Reply
#2
I know I'm stating the obvious, but this would be more javascript than PHP.
I'm not sure how comfortable you are with javascript, but I'll run with your example.

If you create a simple select box setting, you could add a piece of HTML into the description field for that setting, something like

  <span class='usergroupselect_show_users'></span>

Then, in javascript, you would track any changes on the select box, and populate the 'usergroupselect_show_users' element with the data (I.E. the users in that group). The data would need to be obtained through ajax, or you could pre-populate a few hidden html elements within the description and just grab the data from the element that has class of 'usergroup_<id>' or something.

This seems vastly over-complicated for something not really needed like showing the users in a usergroup, but I understand that was an example. It may be easier to help if you shared the real goal you were trying to achieve.

I also understand this is a rather tedious method, but I'm welcome to hear a more efficient method.
Reply
#3
(2012-02-13, 07:48 PM)Beardy Wrote: I know I'm stating the obvious, but this would be more javascript than PHP.
I'm not sure how comfortable you are with javascript, but I'll run with your example.

If you create a simple select box setting, you could add a piece of HTML into the description field for that setting, something like

  <span class='usergroupselect_show_users'></span>

Then, in javascript, you would track any changes on the select box, and populate the 'usergroupselect_show_users' element with the data (I.E. the users in that group). The data would need to be obtained through ajax, or you could pre-populate a few hidden html elements within the description and just grab the data from the element that has class of 'usergroup_<id>' or something.

This seems vastly over-complicated for something not really needed like showing the users in a usergroup, but I understand that was an example. It may be easier to help if you shared the real goal you were trying to achieve.

I also understand this is a rather tedious method, but I'm welcome to hear a more efficient method.

Thanks for the response, I guessed PHP may not be up for the job and a java script may be needed to date the screen looks like this :-
[Image: plug.png]
as you can see I have 2 combo boxes both of which could alter the 'yes_no' objects ... can you think of another way of doing this ?
Not in this land alone,
But be God's mercies known,
From shore to shore!
Lord make the nations see,
That men should brothers be,
And form one family,
The wide world ov'er

Reply
#4
Oh, since you're using actual admin modules and not just the configuration settings, you're constrained less, making it easier to play around with different form elements. This method can be done with just PHP, too, meaning less work.

Rather than using a simple select box, make a multiple select-box (values are just made up, but you'd populate them with the usergroups):
	<select multiple="multiple" name="can_view_usergroups[]">
		<option value='-1'>None</option>
		<option value='1'>Guests</option>
		<option value='2'>Admins</option>
		<option value='3'>Users</option>
	</select>

	<select multiple="multiple" name="can_upload_usergroups[]">
		<option value='-1'>None</option>
		<option value='1'>Guests</option>
		<option value='2'>Admins</option>
		<option value='3'>Users</option>
	</select>

These two multiple select boxes would be placed instead of the yes/no options.

That way, the admin can just hold CTRL (or option, for mac users) to select all of the usergroups that can have that permission.

Then, when processing the form in PHP, you would just iterate over the $mybb->input['can_upload_usergroups'] and $mybb->input['can_view_usergroups'] arrays and process the permissions for those usergroups.
If the "None" value is selected however, you'd ignore all of the other selected options and remove that permission for all usergroups.

Apologies if I wrote that out a little confusing, I've not really used the Form class much so I'm not sure how much control you actually get with it.

If you can't do that with the Form class, you might just need to generate the HTML manually. It'll be a lot messier in code, but again, you'll get more freedom in how everything should work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)