Commits

Seph Soliman committed c4ea512

removed old file import. only report time if we can, so disable buttons in other cases. remove debug css when publishing.

Comments (0)

Files changed (3)

 
 widget: clean
 	cp -R src TimeTrack.wdgt
+	rm -f TimeTrack.wdgt/css/debug.css
 
 clean:
 	rm -rf TimeTrack.wdgt
 	$("#reportdate").hide();
 	$("#show_project").hide();
 	$("#done").hide(); // * initially hide until user logs in
-	//showBack(false);
+	$("#reportbtn").attr('disabled', 'disabled');
 	// }}}
 	
 	// * ui hooks {{{
 	var projectId = $("#projects").val();
 	var prj = allProjects[projectId];
 	
-	$("#show_project").hide();
 	if(prj != null) {
 		if(len(prj.todolists) > 0) {
 			updateProjectTodos();
 			pullProjectTodoLists(prj.id);
 		}
 		$("#show_project").show();
+		$("#reportbtn").attr('disabled', '');
+	} else {
+		$("#show_project").hide();
+		$("#reportbtn").attr('disabled', 'disabled');
 	}
 }
 
 		timeURL = BC_BASE_URL + "/todo_items/" + todoItemId + "/time_entries.xml";
 		console.log('reporting time on to-do ' + todoItemId);
 	} else {
-		var projectId = 
 		timeURL = BC_BASE_URL + "/projects/" + projectId + "/time_entries.xml";
 		console.log('reporting time on project ' + projectId);
 	}
 	
-	var d = new Date();
-	var date = $("#reportdate_y").val() + "-" + zeropad(parseInt($("#reportdate_m").val())+1, 2) + "-" + zeropad($("#reportdate_d").val(), 2);
-	var data = '<time-entry>';
-	data += '<person-id>'+BC_USER_ID+'</person-id>';
-	data += '<date>' + date + '</date>';
-	data += '<hours>' + hours + '</hours>';
-	data += '<description>' + description + '</description>';
-	data += '</time-entry>';
-	opts.data = data;
-	opts.processData = false;
-	
-	opts.type = 'POST';
-	opts.url = timeURL;
-	opts.success = function(root) {
-		$("#reportloader").attr('src', 'images/tick.png');
-		setTimeout(function() {
-			$("#reportloader").fadeOut(250);
-		}, 2000);
-		/* Returns HTTP status code 201 (Created) on success, with the Location header set to the URL of the new time entry. The integer ID of the entry may be extracted from that URL*/
-	};
-	$("#reportloader").attr('src', 'images/ajax-loader-submit.gif').show();
-	$.ajax(opts);
+	if(allProjects[projectId]) {
+		var d = new Date();
+		var date = $("#reportdate_y").val() + "-" + zeropad(parseInt($("#reportdate_m").val())+1, 2) + "-" + zeropad($("#reportdate_d").val(), 2);
+		var data = '<time-entry>';
+		data += '<person-id>'+BC_USER_ID+'</person-id>';
+		data += '<date>' + date + '</date>';
+		data += '<hours>' + hours + '</hours>';
+		data += '<description>' + description + '</description>';
+		data += '</time-entry>';
+		opts.data = data;
+		opts.processData = false;
+		
+		opts.type = 'POST';
+		opts.url = timeURL;
+		opts.complete = function(request, textstatus) {
+			if(request.status == 201) {
+				$("#reportloader").attr('src', 'images/tick.png');
+				setTimeout(function() {
+					$("#reportloader").fadeOut(250);
+				}, 2000);
+				/* Returns HTTP status code 201 (Created) on success, with the Location header set to the URL of the new time entry. The integer ID of the entry may be extracted from that URL*/
+			} else {
+				$("#reportdescription").val('Error (HTTP code '+request.status+'). ' + request.responseText);
+			}
+		};
+		$("#reportloader").attr('src', 'images/ajax-loader-submit.gif').show();
+		$.ajax(opts);
+	} else {
+		$("#reportdescription").val('Please select a project first.');
+	}
 }
 
 function submitLogin() {
 		<script type='text/javascript' src='js/jquery.helptext.js' charset='utf-8'></script>
 		<script type='text/javascript' src='js/stopwatch.js' charset='utf-8'></script>
 		<script type='text/javascript' src='js/utils.js' charset='utf-8'></script>
-		<script type='text/javascript' src='js/bc_user.js' charset='utf-8'></script>
 		<script type='text/javascript' src='js/widget.js' charset='utf-8'></script>
 	</head>