Skip to content

Commit 13fa23c

Browse files
committed
Migration, controller, template, and asset updates
1 parent 2de781a commit 13fa23c

4 files changed

Lines changed: 49 additions & 43 deletions

File tree

app/sprinkles/account/src/Database/Migrations/v430/UpdateUsersTable.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public function up()
4040
{
4141
if ($this->schema->hasTable('users')) {
4242
$this->schema->table('users', function (Blueprint $table) {
43-
$table->dropIndex(['group_id']);
44-
$table->unsignedInteger('group_id')->comment('The id of the user group.')->nullable()->change();
43+
$table->unsignedInteger('group_id')->default(null)->comment('The id of the user group.')->nullable()->change();
4544
});
4645
}
4746
}

app/sprinkles/admin/assets/userfrosting/js/widgets/users.js

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Set up the form in a modal after being successfully attached to the body.
77
*/
88
function attachUserForm() {
9-
$("body").on('renderSuccess.ufModal', function (data) {
9+
$("body").on('renderSuccess.ufModal', function(data) {
1010
var modal = $(this).ufModal('getModal');
1111
var form = modal.find('.js-form');
1212

@@ -15,6 +15,8 @@ function attachUserForm() {
1515
width: '100%'
1616
});
1717

18+
19+
1820
// Set up the form for submission
1921
form.ufForm({
2022
validator: page.validators
@@ -42,14 +44,14 @@ function toggleChangePasswordMode(el, userName, changePasswordMode) {
4244
if (validator) {
4345
//Iterate through named elements inside of the form, and mark them as error free
4446
el.find("input[type='password']").each(function() {
45-
validator.successList.push(this); //mark as error free
47+
validator.successList.push(this); //mark as error free
4648
});
47-
validator.resetForm();//remove error class on name elements and clear history
48-
validator.reset();//remove all error and success data
49+
validator.resetForm(); //remove error class on name elements and clear history
50+
validator.reset(); //remove all error and success data
4951
}
5052
el.find("input[type='password']").closest('.form-group')
51-
.removeClass('has-error has-success');
52-
el.find('.form-control-feedback').each(function () {
53+
.removeClass('has-error has-success');
54+
el.find('.form-control-feedback').each(function() {
5355
$(this).remove();
5456
});
5557
} else {
@@ -66,7 +68,7 @@ function toggleChangePasswordMode(el, userName, changePasswordMode) {
6668
* Update user field(s)
6769
*/
6870
function updateUser(userName, fieldName, fieldValue) {
69-
var data = {
71+
var data = {
7072
'value': fieldValue
7173
};
7274

@@ -92,19 +94,19 @@ function updateUser(userName, fieldName, fieldValue) {
9294
return $.parseJSON(result);
9395
}
9496
} catch (e) {
95-
// statements to handle any exceptions
96-
console.log("Warning: Could not parse expected JSON response.");
97-
return {};
97+
// statements to handle any exceptions
98+
console.log("Warning: Could not parse expected JSON response.");
99+
return {};
98100
}
99101
}
100102
}
101-
}).fail(function (jqXHR) {
103+
}).fail(function(jqXHR) {
102104
// Error messages
103105
if (debugAjax && jqXHR.responseText) {
104106
document.write(jqXHR.responseText);
105107
document.close();
106108
} else {
107-
console.log("Error (" + jqXHR.status + "): " + jqXHR.responseText );
109+
console.log("Error (" + jqXHR.status + "): " + jqXHR.responseText);
108110

109111
// Display errors on failure
110112
// TODO: ufAlerts widget should have a 'destroy' method
@@ -113,12 +115,12 @@ function updateUser(userName, fieldName, fieldValue) {
113115
} else {
114116
$("#alerts-page").ufAlerts('clear');
115117
}
116-
118+
117119
$("#alerts-page").ufAlerts('fetch').ufAlerts('render');
118120
}
119121

120122
return jqXHR;
121-
}).done(function (response) {
123+
}).done(function(response) {
122124
window.location.reload();
123125
});
124126
}
@@ -128,8 +130,8 @@ function updateUser(userName, fieldName, fieldValue) {
128130
* @param {module:jQuery} el jQuery wrapped element to target.
129131
* @param {{delete_redirect: string}} options Options used to modify behaviour of button actions.
130132
*/
131-
function bindUserButtons(el, options) {
132-
if (!options) options = {};
133+
function bindUserButtons(el, options) {
134+
if (!options) options = {};
133135

134136
/**
135137
* Buttons that launch a modal dialog
@@ -162,38 +164,38 @@ function updateUser(userName, fieldName, fieldValue) {
162164
msgTarget: $("#alerts-page")
163165
});
164166

165-
$("body").on('renderSuccess.ufModal', function (data) {
167+
$("body").on('renderSuccess.ufModal', function(data) {
166168
var modal = $(this).ufModal('getModal');
167169
var form = modal.find('.js-form');
168170

169171
// Set up collection widget
170172
var roleWidget = modal.find('.js-form-roles');
171173
roleWidget.ufCollection({
172-
dropdown : {
174+
dropdown: {
173175
ajax: {
174-
url : site.uri.public + '/api/roles'
176+
url: site.uri.public + '/api/roles'
175177
},
176-
placeholder : "Select a role"
178+
placeholder: "Select a role"
177179
},
178180
dropdownTemplate: modal.find('#user-roles-select-option').html(),
179-
rowTemplate : modal.find('#user-roles-row').html()
181+
rowTemplate: modal.find('#user-roles-row').html()
180182
});
181183

182184
// Get current roles and add to widget
183185
$.getJSON(site.uri.public + '/api/users/u/' + userName + '/roles')
184-
.done(function (data) {
185-
$.each(data.rows, function (idx, role) {
186-
role.text = role.name;
187-
roleWidget.ufCollection('addRow', role);
186+
.done(function(data) {
187+
$.each(data.rows, function(idx, role) {
188+
role.text = role.name;
189+
roleWidget.ufCollection('addRow', role);
190+
});
188191
});
189-
});
190192

191193
// Set up form for submission
192194
form.ufForm()
193-
.on("submitSuccess.ufForm", function() {
194-
// Reload page on success
195-
window.location.reload();
196-
});
195+
.on("submitSuccess.ufForm", function() {
196+
// Reload page on success
197+
window.location.reload();
198+
});
197199
});
198200
});
199201

@@ -210,7 +212,7 @@ function updateUser(userName, fieldName, fieldValue) {
210212
msgTarget: $("#alerts-page")
211213
});
212214

213-
$("body").on('renderSuccess.ufModal', function () {
215+
$("body").on('renderSuccess.ufModal', function() {
214216
var modal = $(this).ufModal('getModal');
215217
var form = modal.find('.js-form');
216218

@@ -246,16 +248,16 @@ function updateUser(userName, fieldName, fieldValue) {
246248
msgTarget: $("#alerts-page")
247249
});
248250

249-
$("body").on('renderSuccess.ufModal', function () {
251+
$("body").on('renderSuccess.ufModal', function() {
250252
var modal = $(this).ufModal('getModal');
251253
var form = modal.find('.js-form');
252254

253255
form.ufForm()
254-
.on("submitSuccess.ufForm", function() {
255-
// Navigate or reload page on success
256-
if (options.delete_redirect) window.location.href = options.delete_redirect;
257-
else window.location.reload();
258-
});
256+
.on("submitSuccess.ufForm", function() {
257+
// Navigate or reload page on success
258+
if (options.delete_redirect) window.location.href = options.delete_redirect;
259+
else window.location.reload();
260+
});
259261
});
260262
});
261263

@@ -269,12 +271,12 @@ function updateUser(userName, fieldName, fieldValue) {
269271
updateUser(btn.data('user_name'), 'flag_verified', '1');
270272
});
271273

272-
el.find('.js-user-enable').click(function () {
274+
el.find('.js-user-enable').click(function() {
273275
var btn = $(this);
274276
updateUser(btn.data('user_name'), 'flag_enabled', '1');
275277
});
276278

277-
el.find('.js-user-disable').click(function () {
279+
el.find('.js-user-disable').click(function() {
278280
var btn = $(this);
279281
updateUser(btn.data('user_name'), 'flag_enabled', '0');
280282
});
@@ -292,4 +294,4 @@ function bindUserCreationButton(el) {
292294

293295
attachUserForm();
294296
});
295-
};
297+
};

app/sprinkles/admin/src/Controller/UserController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,10 @@ public function updateInfo(Request $request, Response $response, $args)
12111211
return $response->withJson([], 400);
12121212
}
12131213

1214+
if (isset($data['group_id']) && $data['group_id'] == 0) {
1215+
$data['group_id'] = null;
1216+
}
1217+
12141218
// Begin transaction - DB will be rolled back if an exception occurs
12151219
Capsule::transaction(function () use ($data, $user, $currentUser) {
12161220
// Update the user and generate success messages

app/sprinkles/admin/templates/forms/user.html.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
{% if 'group' in form.fields.disabled %}
2525
<input type="text" class="form-control" name="theme" value="{{user.group.name}}" disabled>
2626
{% else %}
27-
<select id="input-group" class="form-control js-select2" name="group_id">
27+
<select id="input-group" class="form-control js-select2-group" name="group_id">
28+
<option value="0" </option>
2829
{% for group in groups %}
2930
<option value="{{group.id}}" {% if (group.id == user.group_id) %}selected{% endif %}>{{group.name}}</option>
3031
{% endfor %}

0 commit comments

Comments
 (0)