@@ -18,7 +18,7 @@ function newAdmin(username, password, name) {
1818 } ,
1919
2020 error : function ( response ) {
21- addStatusMessage ( 'error' , filterText ( jQuery . parseJSON ( response . responseText ) . message ) ) ;
21+ addStatusMessage ( 'error' , jQuery . parseJSON ( response . responseText ) . message ) ;
2222 }
2323 } ) ;
2424}
@@ -37,7 +37,7 @@ function deleteAdmin(id) {
3737 } ,
3838
3939 error : function ( response ) {
40- addStatusMessage ( 'error' , filterText ( jQuery . parseJSON ( response . responseText ) . message ) ) ;
40+ addStatusMessage ( 'error' , jQuery . parseJSON ( response . responseText ) . message ) ;
4141 }
4242 } ) ;
4343}
@@ -46,16 +46,16 @@ function deleteAdmin(id) {
4646function unlockAdmin ( id , targetLink ) {
4747
4848 $ . ajax ( {
49- url : '/api/v1/admins/' + id + 'unlock/ ' ,
49+ url : '/api/v1/admins/' + id + '/unlock ' ,
5050 type : 'put' ,
5151
5252 success : function ( response ) {
5353 addStatusMessage ( 'success' , 'The administrator was unlocked successfully' ) ;
54- targetLink . parent ( 'td' ) . html ( 'Unlocked' ) ;
54+ targetLink . parent ( 'td' ) . text ( 'Unlocked' ) ;
5555 } ,
5656
5757 error : function ( response ) {
58- addStatusMessage ( 'error' , filterText ( jQuery . parseJSON ( response . responseText ) . message ) ) ;
58+ addStatusMessage ( 'error' , jQuery . parseJSON ( response . responseText ) . message ) ;
5959 }
6060 } ) ;
6161
@@ -64,21 +64,21 @@ function unlockAdmin(id, targetLink) {
6464// Sets the event listeners for x-editable
6565function editableAdminEventListeners ( ) {
6666
67- var adminUsername = $ ( 'a.adminUsername ' ) ;
67+ var adminEmail = $ ( 'a.adminEmail ' ) ;
6868 var adminPassword = $ ( 'a.adminPassword' ) ;
6969 var adminName = $ ( 'a.adminName' ) ;
7070 var adminLocked = $ ( 'a.adminLocked' )
7171
72- adminUsername . unbind ( ) ;
72+ adminEmail . unbind ( ) ;
7373 adminPassword . unbind ( ) ;
7474 adminName . unbind ( ) ;
7575 adminLocked . unbind ( ) ;
76- adminUsername . tooltip ( ) ;
76+ adminEmail . tooltip ( ) ;
7777 adminPassword . tooltip ( ) ;
7878 adminName . tooltip ( ) ;
7979 adminLocked . tooltip ( ) ;
8080
81- adminUsername . editable ( {
81+ adminEmail . editable ( {
8282 type : 'text' ,
8383 mode : 'inline' ,
8484 anim : 100 ,
@@ -94,11 +94,11 @@ function editableAdminEventListeners() {
9494 } ,
9595
9696 display : function ( value ) {
97- $ ( this ) . html ( filterText ( value . toLowerCase ( ) ) ) ;
97+ $ ( this ) . text ( value . toLowerCase ( ) ) ;
9898 } ,
9999
100100 error : function ( response ) {
101- addStatusMessage ( 'error' , filterText ( jQuery . parseJSON ( response . responseText ) . message ) ) ;
101+ addStatusMessage ( 'error' , jQuery . parseJSON ( response . responseText ) . message ) ;
102102 } ,
103103
104104 success : function ( ) {
@@ -122,11 +122,11 @@ function editableAdminEventListeners() {
122122 } ,
123123
124124 display : function ( ) {
125- $ ( this ) . html ( '●●●●●●●●' ) ;
125+ $ ( this ) . text ( '●●●●●●●●' ) ;
126126 } ,
127127
128128 error : function ( response ) {
129- addStatusMessage ( 'error' , filterText ( jQuery . parseJSON ( response . responseText ) . message ) ) ;
129+ addStatusMessage ( 'error' , jQuery . parseJSON ( response . responseText ) . message ) ;
130130 } ,
131131
132132 success : function ( ) {
@@ -150,11 +150,11 @@ function editableAdminEventListeners() {
150150 } ,
151151
152152 display : function ( value ) {
153- $ ( this ) . html ( filterText ( value ) ) ;
153+ $ ( this ) . text ( value ) ;
154154 } ,
155155
156156 error : function ( response ) {
157- addStatusMessage ( 'error' , filterText ( jQuery . parseJSON ( response . responseText ) . message ) ) ;
157+ addStatusMessage ( 'error' , jQuery . parseJSON ( response . responseText ) . message ) ;
158158 } ,
159159
160160 success : function ( ) {
@@ -272,17 +272,46 @@ function fillInTable () {
272272 var i = 1 ;
273273 // For each item, add a row, but if the row exists, just change the value
274274 $ . each ( result [ 'items' ] , function ( j , item ) {
275+ // Query the existing table row
275276 var tableRow = $ ( '#dynamicTableRow' + String ( i ) ) ;
276- var html = '' ;
277-
278- tableRow . length == 0 ? html += '<tr id="dynamicTableRow' + String ( i ) + '">' : null ;
279- html += '<td data-title="Username: "><a href="#" class="adminUsername" data-pk="' + item . id + '" data-url="/api/v1/admins/' + item . id + '" title="Click to change the username">' + filterText ( item . username ) + '</a></td>\
280- <td data-title="Password: "><a href="#" class="adminPassword" data-pk="' + item . id + '" data-url="/api/v1/admins/' + item . id + '" title="Click to change the password">●●●●●●●●</a></td>\
281- <td data-title="Name: "><a href="#" class="adminName" data-pk="' + item . id + '" data-url="/api/v1/admins/' + item . id + '" title="Click to change the name">' + filterText ( item . name ) + '</a></td>\
282- <td data-title="Locked: ">' + ( item . locked ? ( '<a href="#" class="adminLocked" data-pk="' + item . id + '" title="Click to unlock the administrator">Locked</a>' ) : 'Unlocked' ) + '</td>\
283- <td data-title="Action: "><a href="#" class="deleteAnchor" data-pk="' + item . id + '" data-toggle="modal" data-target="#deleteModal">Delete</a></td>' ;
284- tableRow . length == 0 ? html += '</tr>' : null ;
285- tableRow . length == 0 ? insertTableRow ( html ) : tableRow . html ( html ) ;
277+ // Create a new table row to be inserted or replace the current one
278+ var newTableRow = $ ( '<tr />' , { 'id' : 'dynamicTableRow' + String ( i ) } ) ;
279+ var columnDataUrl = '/api/v1/admins/' + item . id ;
280+ var email_td = $ ( '<td />' , { 'data-title' : 'Email: ' } ) . append (
281+ $ ( '<a />' , { 'href' : '#' , 'class' : 'adminEmail' , 'data-pk' : item . id , 'data-url' : columnDataUrl ,
282+ 'title' : 'Click to change the username' } ) . text ( item . username )
283+ ) ;
284+ var password_td = $ ( '<td />' , { 'data-title' : 'Password: ' } ) . append (
285+ $ ( '<a />' , { 'href' : '#' , 'class' : 'adminPassword' , 'data-pk' : item . id , 'data-url' : columnDataUrl ,
286+ 'title' : 'Click to change the password' } ) . text ( '●●●●●●●●' )
287+ ) ;
288+ var name_td = $ ( '<td />' , { 'data-title' : 'Name: ' } ) . append (
289+ $ ( '<a />' , { 'href' : '#' , 'class' : 'adminName' , 'data-pk' : item . id , 'data-url' : columnDataUrl ,
290+ 'title' : 'Click to change the name' } ) . text ( item . name )
291+ ) ;
292+ var locked_td = $ ( '<td />' , { 'data-title' : 'Locked: ' } ) ;
293+ if ( item . locked ) {
294+ locked_td . append (
295+ $ ( '<a />' , { 'href' : '#' , 'class' : 'adminLocked' , 'data-pk' : item . id ,
296+ 'title' : 'Click to unlock the administrator' } ) . text ( 'Locked' )
297+ ) ;
298+ }
299+ else {
300+ locked_td . text ( 'Unlocked' ) ;
301+ }
302+ var action_td = $ ( '<td />' , { 'data-title' : 'Action: ' } ) . append (
303+ $ ( '<a />' , { 'href' : '#' , 'class' : 'deleteAnchor' , 'data-pk' : item . id , 'data-toggle' : 'modal' ,
304+ 'data-target' : '#deleteModal' } ) . text ( 'Delete' )
305+ ) ;
306+ // Add the new columns to the new table row
307+ newTableRow . append ( email_td ) . append ( password_td ) . append ( name_td ) . append ( locked_td ) . append ( action_td ) ;
308+ // If the table row exists, then replace it, otherwise insert it
309+ if ( tableRow . length > 0 ) {
310+ tableRow . replaceWith ( newTableRow ) ;
311+ }
312+ else {
313+ insertTableRow ( newTableRow ) ;
314+ }
286315
287316 i ++ ;
288317 } ) ;
0 commit comments