Refactoring

This commit is contained in:
gamonoid
2017-09-03 20:39:22 +02:00
parent af40881847
commit a7274d3cfd
5075 changed files with 238202 additions and 16291 deletions

View File

@@ -0,0 +1,17 @@
<div class="col-lg-3 col-xs-12">
<div class="small-box bg-yellow">
<div class="inner">
<h3><t>Users</t></h3>
<p id="numberOfUsers">
#_numberOfUsers_# <t>Users</t>
</p>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
</div>
<a href="#_moduleLink_#" class="small-box-footer" id="usersLink">
<t>Manage</t> <t>Users</t> <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>

View File

@@ -0,0 +1,17 @@
Dear #_name_#,<br/><br/>
Your account in <b>IceHrm</b> has been created on <a href="#_url_#">#_url_#</a><br/><br/>
<b>Please find your account information below:</b><br/><br/>
Username: <b>#_username_#</b><br/>
Email: <b>#_email_#</b> (You can use, username or email to login)<br/>
Password: <b>#_password_#</b> (Strongly advised to change this password once logged in)<br/>
<br/>
To get started, follow this link: <b><a href="#_url_#">#_url_#</a></b><br/><br/>
<font face="Arial, sans-serif" size="1" color="#4a4a4a">
THIS IS AN AUTOMATED EMAIL - REPLIES WILL BE SENT TO #_adminEmail_#
</font>
<br/>
<br/>

66
admin/users/index.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
/*
This file is part of iCE Hrm.
iCE Hrm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
iCE Hrm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with iCE Hrm. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------
Original work Copyright (c) 2012 [Gamonoid Media Pvt. Ltd]
Developer: Thilina Hasantha (thilina.hasantha[at]gmail.com / facebook.com/thilinah)
*/
$moduleName = 'users';
define('MODULE_PATH',dirname(__FILE__));
include APP_BASE_PATH.'header.php';
include APP_BASE_PATH.'modulejslibs.inc.php';
?><div class="span9">
<ul class="nav nav-tabs" id="modTab" style="margin-bottom:0px;margin-left:5px;border-bottom: none;">
<li class="active"><a id="tabUser" href="#tabPageUser"><?=t('Users')?></a></li>
<li class=""><a id="tabUserRole" href="#tabPageUserRole"><?=t('User Roles')?></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tabPageUser">
<div id="User" class="reviewBlock" data-content="List" style="padding-left:5px;">
</div>
<div id="UserForm" class="reviewBlock" data-content="Form" style="padding-left:5px;display:none;">
</div>
</div>
<div class="tab-pane" id="tabPageUserRole">
<div id="UserRole" class="reviewBlock" data-content="List" style="padding-left:5px;">
</div>
<div id="UserRoleForm" class="reviewBlock" data-content="Form" style="padding-left:5px;display:none;">
</div>
</div>
</div>
</div>
<script>
var modJsList = new Array();
modJsList['tabUser'] = new UserAdapter('User');
<?php if(isset($_REQUEST['action']) && $_REQUEST['action'] == "new" && isset($_REQUEST['object'])){?>
modJsList['tabUser'].newInitObject = JSON.parse(Base64.decode('<?=$_REQUEST['object']?>'));
<?php }?>
modJsList['tabUserRole'] = new UserRoleAdapter('UserRole');
var modJs = modJsList['tabUser'];
</script>
<?php include APP_BASE_PATH.'footer.php';?>

200
admin/users/lib.js Normal file
View File

@@ -0,0 +1,200 @@
/**
* Author: Thilina Hasantha
*/
function UserAdapter(endPoint) {
this.initAdapter(endPoint);
}
UserAdapter.inherits(AdapterBase);
UserAdapter.method('getDataMapping', function() {
return [
"id",
"username",
"email",
"employee",
"user_level"
];
});
UserAdapter.method('getHeaders', function() {
return [
{ "sTitle": "ID" },
{ "sTitle": "User Name" },
{ "sTitle": "Authentication Email" },
{ "sTitle": "Employee"},
{ "sTitle": "User Level"}
];
});
UserAdapter.method('getFormFields', function() {
return [
[ "id", {"label":"ID","type":"hidden","validation":""}],
[ "username", {"label":"User Name","type":"text","validation":"username"}],
[ "email", {"label":"Email","type":"text","validation":"email"}],
[ "employee", {"label":"Employee","type":"select2","allow-null":true,"remote-source":["Employee","id","first_name+last_name"]}],
[ "user_level", {"label":"User Level","type":"select","source":[["Admin","Admin"],["Manager","Manager"],["Employee","Employee"],["Other","Other"]]}],
[ "user_roles", {"label":"User Roles","type":"select2multi","remote-source":["UserRole","id","name"]}],
[ "lang", {"label":"Language","type":"select2","allow-null":true,"remote-source":["SupportedLanguage","id","description"]}],
[ "default_module", {"label":"Default Module","type":"select2","null-label":"No Default Module","allow-null":true,"remote-source":["Module","id","menu+label"]}]
];
});
UserAdapter.method('postRenderForm', function(object, $tempDomObj) {
if(object == null || object == undefined){
$tempDomObj.find("#changePasswordBtn").remove();
}
});
UserAdapter.method('changePassword', function() {
$('#adminUsersModel').modal('show');
$('#adminUsersChangePwd #newpwd').val('');
$('#adminUsersChangePwd #conpwd').val('');
});
UserAdapter.method('saveUserSuccessCallBack', function(callBackData,serverData) {
this.showMessage("Create User","An email has been sent to "+callBackData['email']+" with a temporary password to login to IceHrm.");
this.get([]);
});
UserAdapter.method('saveUserFailCallBack', function(callBackData,serverData) {
this.showMessage("Error",callBackData);
});
UserAdapter.method('doCustomValidation', function(params) {
var msg = null;
if((params['user_level'] != "Admin" && params['user_level'] != "Other") && params['employee'] == "NULL"){
msg = "For this user type, you have to assign an employee when adding or editing the user.<br/>";
msg += " You may create a new employee through 'Admin'->'Employees' menu";
}
return msg;
});
UserAdapter.method('save', function() {
var validator = new FormValidation(this.getTableName()+"_submit",true,{'ShowPopup':false,"LabelErrorClass":"error"});
if(validator.checkValues()){
var params = validator.getFormParameters();
var msg = this.doCustomValidation(params);
if(msg == null){
var id = $('#'+this.getTableName()+"_submit #id").val();
if(id != null && id != undefined && id != ""){
$(params).attr('id',id);
this.add(params,[]);
}else{
var reqJson = JSON.stringify(params);
var callBackData = [];
callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'saveUserSuccessCallBack';
callBackData['callBackFail'] = 'saveUserFailCallBack';
this.customAction('saveUser','admin=users',reqJson,callBackData);
}
}else{
//$("#"+this.getTableName()+'Form .label').html(msg);
//$("#"+this.getTableName()+'Form .label').show();
this.showMessage("Error Saving User",msg);
}
}
});
UserAdapter.method('changePasswordConfirm', function() {
$('#adminUsersChangePwd_error').hide();
var passwordValidation = function (str) {
var val = /^[a-zA-Z0-9]\w{6,}$/;
return str != null && val.test(str);
};
var password = $('#adminUsersChangePwd #newpwd').val();
if(!passwordValidation(password)){
$('#adminUsersChangePwd_error').html("Password may contain only letters, numbers and should be longer than 6 characters");
$('#adminUsersChangePwd_error').show();
return;
}
var conPassword = $('#adminUsersChangePwd #conpwd').val();
if(conPassword != password){
$('#adminUsersChangePwd_error').html("Passwords don't match");
$('#adminUsersChangePwd_error').show();
return;
}
var req = {"id":this.currentId,"pwd":conPassword};
var reqJson = JSON.stringify(req);
var callBackData = [];
callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'changePasswordSuccessCallBack';
callBackData['callBackFail'] = 'changePasswordFailCallBack';
this.customAction('changePassword','admin=users',reqJson,callBackData);
});
UserAdapter.method('closeChangePassword', function() {
$('#adminUsersModel').modal('hide');
});
UserAdapter.method('changePasswordSuccessCallBack', function(callBackData,serverData) {
this.closeChangePassword();
this.showMessage("Password Change","Password changed successfully");
});
UserAdapter.method('changePasswordFailCallBack', function(callBackData,serverData) {
this.closeChangePassword();
this.showMessage("Error",callBackData);
});
/**
* UserRoleAdapter
*/
function UserRoleAdapter(endPoint,tab,filter,orderBy) {
this.initAdapter(endPoint,tab,filter,orderBy);
}
UserRoleAdapter.inherits(AdapterBase);
UserRoleAdapter.method('getDataMapping', function() {
return [
"id",
"name"
];
});
UserRoleAdapter.method('getHeaders', function() {
return [
{ "sTitle": "ID" ,"bVisible":false},
{ "sTitle": "Name"}
];
});
UserRoleAdapter.method('postRenderForm', function(object, $tempDomObj) {
$tempDomObj.find("#changePasswordBtn").remove();
});
UserRoleAdapter.method('getFormFields', function() {
return [
[ "id", {"label":"ID","type":"hidden"}],
[ "name", {"label":"Name","type":"text","validation":""}]
];
});

13
admin/users/meta.json Normal file
View File

@@ -0,0 +1,13 @@
{
"label": "Users",
"menu": "System",
"order": "2",
"icon": "fa-user",
"user_levels": [
"Admin"
],
"dashboardPosition": 3,
"permissions": [],
"model_namespace": "\\Users\\Common\\Model",
"manager": "\\Users\\Admin\\Api\\UsersAdminManager"
}

View File

@@ -0,0 +1,55 @@
<form class="form-horizontal" id="_id_">
<div class="control-group">
<div class="controls">
<span class="label label-warning" id="_id__error" style="display:none;"></span>
</div>
</div>
_fields_
<div class="control-group">
<div class="controls">
<button onclick="try{modJs.save()}catch(e){};return false;" class="btn">Save</button>
<button onclick="modJs.cancel();return false;" class="btn">Cancel</button>
<button id="changePasswordBtn" onclick="modJs.changePassword();return false;" class="btn btn-primary">Change Password</button>
</div>
</div>
</form>
<div class="modal" id="adminUsersModel" tabindex="-1" role="dialog" aria-labelledby="messageModelLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><li class="fa fa-times"/></button>
<h3 style="font-size: 17px;">Change User Password</h3>
</div>
<div class="modal-body">
<form id="adminUsersChangePwd">
<div class="control-group">
<div class="controls">
<span class="label label-warning" id="adminUsersChangePwd_error" style="display:none;"></span>
</div>
</div>
<div class="control-group" id="field_newpwd">
<label class="control-label" for="newpwd">New Password</label>
<div class="controls">
<input class="" type="password" id="newpwd" name="newpwd" value="" class="form-control"/>
<span class="help-inline" id="help_newpwd"></span>
</div>
</div>
<div class="control-group" id="field_conpwd">
<label class="control-label" for="conpwd">Confirm Password</label>
<div class="controls">
<input class="" type="password" id="conpwd" name="conpwd" value="" class="form-control"/>
<span class="help-inline" id="help_conpwd"></span>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" onclick="modJs.changePasswordConfirm();">Change Password</button>
<button class="btn" onclick="modJs.closeChangePassword();">Not Now</button>
</div>
</div>
</div>
</div>