<commit_before>define(["jquery", "knockout", "bootstrap", 
        "data-table", "notify"], function($, ko){
	
	function refreshManusTable() {
		$('#manus-grid').DataTable().ajax.reload();
	}
	
	function UserViewModel() {
    	var self = this;
    	
    	self.data = {
    		userId: ko.observable(),
			userName: ko.observable(),
	    	accountNumber: ko.observable(),
	    	accountPosition:  ko.observable(),
	    	
	    	departement: ko.observable(),
	    	fullName: ko.observable(),
	    	password: ko.observable(),
	    	rePassword: ko.observable(),
	    	
	    	role: ko.observable(),
	    	address: ko.observable()
	    	
    	}
    	
    	self.data.userName.subscribe(function(ev){
    		//TODO; check existing username
//    		console.info("data sekarang "+ ev);
    	});
    	
    	self.userNotif = ko.observable();
    	self.doInsert = function() {
    		var reqData = ko.toJSON(self.data);
    		
    		var actionType = "POST";
    		console.debug(self.data.userId());
    		if (self.data.userId() != null) {
    			actionType = "PUT";
    		} 
    		
    		console.debug(reqData);
//    		console.debug('actionType: '+ actionType);
    		$.ajax({
				type: actionType,
				data: reqData,
				contentType: 'application/json',
				url: site_url + "tlhp/restmanus",
				beforeSend: function(){
					console.info('attempting to insert new user');
					$('#btnSave').attr('disabled', 'disabled');
				},
				success: function(data) {
					console.info('new user was added');
					refreshManusTable();
					if (actionType == "POST") {
						self.resetData();
//						$("#notify").notify("Data telah disimpan", "alert alert-info");
						$('#userModal').modal('hide');
					} else {
						$('#userModal').modal('hide');
					}
				},
				error: function(xhr, msg) {
//					self.userNotif("Internal Server Error");
					$("#notify").notify("Internal Server Error", "alert alert-error");
				}
			}).always(function(){
				$('#btnSave').removeAttr('disabled');
			});
    	}
    	
    	self.newUser = function() {
			self.resetData();
		}
    	
    	self.resetData = function() {
    		self.data.userId(null);
			self.data.userName(null);
			self.data.accountNumber(null);
	    	self.data.accountPosition(null);
	    	
	    	self.data.departement(null);
	    	self.data.fullName(null);
	    	self.data.password(null);
	    	self.data.rePassword(null);
	    	
	    	self.data.role(null);
	    	self.data.address(null);
    	},<commit_msg>auto close user form<commit_after>define(["jquery", "knockout", "bootstrap", 
        "data-table", "notify"], function($, ko){
	
	function refreshManusTable() {
		$('#manus-grid').DataTable().ajax.reload();
	}
	
	function UserViewModel() {
    	var self = this;
    	
    	self.data = {
    		userId: ko.observable(),
			userName: ko.observable(),
	    	accountNumber: ko.observable(),
	    	accountPosition:  ko.observable(),
	    	
	    	departement: ko.observable(),
	    	fullName: ko.observable(),
	    	password: ko.observable(),
	    	rePassword: ko.observable(),
	    	
	    	role: ko.observable(),
	    	address: ko.observable()
	    	
    	}
    	
    	self.data.userName.subscribe(function(ev){
    		//TODO; check existing username
//    		console.info("data sekarang "+ ev);
    	});
    	
    	self.userNotif = ko.observable();
    	self.doInsert = function() {
    		var reqData = ko.toJSON(self.data);
    		
    		var actionType = "POST";
    		console.debug(self.data.userId());
    		if (self.data.userId() != null) {
    			actionType = "PUT";
    		} 
    		
    		console.debug(reqData);
//    		console.debug('actionType: '+ actionType);
    		$.ajax({
				type: actionType,
				data: reqData,
				contentType: 'application/json',
				url: site_url + "tlhp/restmanus",
				beforeSend: function(){
					console.info('attempting to insert new user');
					$('#btnSave').attr('disabled', 'disabled');
				},
				success: function(data) {
					console.info('new user was added');
					refreshManusTable();
					$('#userModal').modal('hide');
//					if (actionType == "POST") {
//						self.resetData();
//						
//					} else {
//						$('#userModal').modal('hide');
//					}
				},
				error: function(xhr, msg) {
//					self.userNotif("Internal Server Error");
					$("#notify").notify("Internal Server Error", "alert alert-error");
				}
			}).always(function(){
				$('#btnSave').removeAttr('disabled');
			});
    	}
    	
    	self.newUser = function() {
			self.resetData();
		}
    	
    	self.resetData = function() {
    		self.data.userId(null);
			self.data.userName(null);
			self.data.accountNumber(null);
	    	self.data.accountPosition(null);
	    	
	    	self.data.departement(null);
	    	self.data.fullName(null);
	    	self.data.password(null);
	    	self.data.rePassword(null);
	    	
	    	self.data.role(null);
	    	self.data.address(null);
    	},
{'fraction_non_alphanumeric': 0.17263506520389155, 'fraction_numerical': 0.0, 'mean_word_length': 2.419674451521585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5285713', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1633, 'n_words': 256}