<?xml version="1.0" encoding="UTF-8"?>
<unload unload_date="2016-05-19 17:31:54">
<sys_ui_page action="INSERT_OR_UPDATE">
<category>general</category>
<client_script><![CDATA[var projectApp = angular.module('projectEditor', []);

projectApp.controller('ProjectController', [
'$scope',
'$http',
function($scope, $http) {
	$scope.isLoaded = false;
	$scope.loading = true;
	$scope.url = '/api/now/table/pm_project';
	$http.defaults.headers.common.Accept = "application/json";
	
	$scope.updateRecordList = function() {
		$http({
			method: 'GET',
			url: $scope.url + "?sysparm_query=active=true^ORDERBYDESCend_date&sysparm_limit=15&sysparm_display_value=true"
		}).
		success( function(data, status) {
			$scope.loading = false;
			$scope.isLoaded = true;
			$scope.projects = data.result;
			for (var i=0; i< $scope.projects.length; i++) {
				$scope.projects[i].showNotes = false;
			}
			console.log(data.result);
		}).
		error ( function(data, status) {
			$scope.projects = [{"number": "Error fetching list"}];
		});
	};
	
	$scope.updateNotes = function(id, notes) {
		$http({
			method: 'PATCH',
			url: $scope.url + "/" + id,
			headers: {'Content-Type': 'application/json'},
			data: {'work_notes': notes}
		}).
		success( function(data, status) {
			$scope.status = "Successfully updated Work Notes.";
		}).
		error ( function(data, status) {
			$scope.status = "Error updating Work Notes.";
		});
	};
	
	$scope.toggleNotes = function(idx) {
		$scope.projects[idx]['showNotes'] = !$scope.projects[idx]['showNotes'];
	};
	
	$scope.saveNotes = function(idx) {
		$scope.updateNotes($scope.projects[idx]['sys_id'], $scope.projects[idx]['notes']);
		$scope.toggleNotes(idx);
		$scope.projects[idx]['notes'] = '';
	};
	
	$scope.updateRecordList('');
}] );

projectApp.directive('pctComplete', function() {
	return {
		restrict: 'E',
		replace: true,
		scope: {
			value: '='
		},
		template: ' <div class="c100 p{{value}}">\
		<span>{{value}}%</span>\
		<div class="slice">\
		<div class="bar"></div>\
		<div class="fill"></div>\
		</div>\
		</div>'
	};
});]]></client_script>
<description/>
<direct>false</direct>
<endpoint/>
<html><![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
	<link href="c04180ac0fb61200aff186bce1050e42.cssdbx?" rel="stylesheet" type="text/css" />
    <style>
        .normal-cell {
            width: 200px;
            padding-right: 10px;
        }
        .center {
            text-align: center;
        }
        .center h2 {
            color: #f68920;
        }
        .column-headers h4 {
            font-weight: 800;
        }
        .save-button {
            display: none;
        }
        a {
            color: #91b4c5;
        }
        a h4{
            font-weight: 600;
        }
		#filter-text {
			width: 110px;
		}
    </style>
    <div class="container">
        <div class="center">
            <h2 class="page-title">Project Status</h2>
        </div>
    </div>
    <div class="container" ng-app="projectEditor">
        <div class="row" ng-controller="ProjectController">
            <div class="panel panel-default">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th class="normal-cell">Project</th>
                            <th class="normal-cell">State</th>
                            <th class="normal-cell">Percent Complete</th>
                            <th class="normal-cell">Planned Start Date</th>
                            <th class="normal-cell">Planned End Date</th>
							<td class="normal-cell"><input id="filter-text" placeholder="Filter" type="text" ng-model="filterText"/></td>
                        </tr>
                    </thead>
                    <tbody ng-show="isLoaded">
                        <tr ng-repeat="proj in projects | filter : {short_description: filterText}">
                            <td colspan="6">
                                <table>
                                    <tr>
                                        <td class="normal-cell"><a class="project-link" href="pm_project.do?sys_id={{proj.sys_id}}" style="color: #91b4c5; font-weight: 600;">{{proj.number}}</a><div>{{proj.short_description}}</div></td>
                                        <td class="normal-cell">{{proj.state}}</td>
                                        <td class="normal-cell"><pct-complete value="proj.percent_complete"></pct-complete></td>
                                        <td class="normal-cell">{{proj.start_date}}</td>
                                        <td class="normal-cell">{{proj.end_date}}</td>
                                        <td class="normal-cell">
                                            <button ng-click="toggleNotes($index)" ng-show="!proj.showNotes">Add Notes</button>
                                            <button ng-click="saveNotes($index)" ng-show="proj.showNotes">Save Notes</button>
                                        </td>
                                    </tr>
									<tr>
                                        <td colspan="6">
                                            <div ng-show="proj.showNotes">
                                                <div class="col-md-6"></div>
                                                <div class="col-md-5">
                                                    <label>Notes:</label>
                                                    <textarea class="form-control" rows="5" ng-model="proj.notes"></textarea>
                                                </div>
                                                <div class="col-md-1"></div>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
	
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
</j:jelly>]]></html>
<name>project_angular_challenge</name>
<processing_script/>
<sys_class_name>sys_ui_page</sys_class_name>
<sys_created_by>admin</sys_created_by>
<sys_created_on>2016-05-17 16:41:50</sys_created_on>
<sys_customer_update>true</sys_customer_update>
<sys_id>522e604469a312007f4411c26b4ee474</sys_id>
<sys_mod_count>6</sys_mod_count>
<sys_name>project_angular_challenge</sys_name>
<sys_package display_value="Global">global</sys_package>
<sys_policy/>
<sys_replace_on_upgrade>false</sys_replace_on_upgrade>
<sys_scope display_value="Global">global</sys_scope>
<sys_update_name>sys_ui_page_522e604469a312007f4411c26b4ee474</sys_update_name>
<sys_updated_by>admin</sys_updated_by>
<sys_updated_on>2016-05-17 17:09:11</sys_updated_on>
</sys_ui_page>
</unload>
