(function(){ var splitPane; spud.admin.users = { index: function(){ splitPane = new spud.admin.SplitPane('.admin-users-split-pane'); $('.admin-user-add-btn').on('click', true, clickedAddEditUser); $('.admin-users-split-pane').on('click', '.admin-user-edit-btn', clickedAddEditUser); $('.admin-users-split-pane').on('click', '.admin-user-edit-cancel-btn', clickedCancelAddEditUser); $('.admin-users-split-pane').on('click', '.admin-user-delete-btn', clickedDeleteUser); $('.admin-users-split-pane').on('submit', '.admin-user-form', submittedUserForm); $('body').on('click', '.split-pane-refresh-btn', clickedRefreshButton); } }; var _userHtmlCache; var _previouslySelected; var clickedAddEditUser = function(e){ e.preventDefault(); _previouslySelected = splitPane.getActiveItem(); _userHtmlCache = splitPane.getContentAreaHtml(); var isAdd = e.data; if(isAdd){ splitPane.deselectActiveItem(); } var title = $(this).attr('title'); var url = $(this).attr('href'); $.ajax(url, { dataType:'html', success:function(html){ splitPane.setContentAreaHtml(html); splitPane.setToolbarTitle(title); } }); }; var clickedCancelAddEditUser = function(e){ e.preventDefault(); splitPane.setContentAreaHtml(_userHtmlCache); splitPane.setActiveItem(_previouslySelected); splitPane.setToolbarTitle(''); }; var clickedDeleteUser = function(e){ e.preventDefault(); var url = $(this).attr('href'); $.ajax(url, { dataType:'json', type:'post', data: {_method:'delete'}, success:function(html){ splitPane.removeCurrentlySelectedItem(); splitPane.setToolbarTitle(''); } }); }; var submittedUserForm = function(e){ e.preventDefault(); var form = $(this); var url = form.attr('action'); $.ajax(url, { dataType:'html', type: 'post', data: form.serialize(), success:function(html, textStatus, jqXHR){ splitPane.setContentAreaHtml(html); splitPane.refreshList(); }, error:function(jqXHR, textStatus, errorThrown){ splitPane.setContentAreaHtml(jqXHR.responseText); } }); }; var clickedRefreshButton = function(e){ e.preventDefault(); splitPane.refreshList(); }; })();