Commit 6a5af6d2 authored by Leigh Stoller's avatar Leigh Stoller

Stay on the portalization train.

parent 1a2bfd4a
......@@ -27,7 +27,7 @@ function HideWaitWait()
HideModal('#waitwait-modal-withmessage');
}
function CallServerMethod(url, route, method, args)
function CallServerMethod(url, route, method, args, callback)
{
// ignore url now.
url = 'https://' + window.location.host + '/apt/server-ajax.php';
......@@ -39,6 +39,7 @@ function CallServerMethod(url, route, method, args)
return $.ajax({
// the URL for the request
url: url,
success: callback,
// the data to send (will be converted to a query string)
data: {
......
......@@ -4,9 +4,10 @@ require(window.APT_OPTIONS.configObject,
'js/lib/text!template/experiment-list.html',
'js/lib/text!template/profile-list.html',
'js/lib/text!template/member-list.html',
'js/lib/text!template/project-profile.html',
],
function (_, sup, moment, mainString,
experimentString, profileString, memberString)
experimentString, profileString, memberString, detailsString)
{
'use strict';
var mainTemplate = _.template(mainString);
......@@ -26,6 +27,7 @@ function (_, sup, moment, mainString,
LoadExperimentTab();
LoadProfileTab();
LoadMembersTab();
LoadProjectTab();
}
function LoadExperimentTab()
......@@ -169,6 +171,37 @@ function (_, sup, moment, mainString,
xmlthing.done(callback);
}
function LoadProjectTab()
{
var callback = function(json) {
console.info(json);
if (json.code) {
console.info(json.value);
return;
}
if (json.value.length == 0) {
return;
}
var template = _.template(detailsString);
$('#admin_content')
.html(template({"fields" : json.value}));
// Format dates with moment before display.
$('#admin_table .format-date').each(function() {
var date = $.trim($(this).html());
if (date != "") {
$(this).html(moment($(this).html()).format("ll"));
}
});
}
var xmlthing = sup.CallServerMethod(null,
"show-project", "ProjectProfile",
{"pid" : window.TARGET_PROJECT});
xmlthing.done(callback);
}
$(document).ready(initialize);
});
......
......@@ -4,10 +4,13 @@ require(window.APT_OPTIONS.configObject,
'js/lib/text!template/experiment-list.html',
'js/lib/text!template/profile-list.html',
'js/lib/text!template/project-list.html',
'js/lib/text!template/myaccount-table.html',
'js/lib/text!template/user-profile.html',
'js/lib/text!template/oops-modal.html',
'js/lib/text!template/waitwait-modal.html',
],
function (_, sup, moment, mainString,
experimentString, profileString, projectString, myaccountString)
experimentString, profileListString, projectString,
profileString, oopsString, waitwaitString)
{
'use strict';
var mainTemplate = _.template(mainString);
......@@ -23,12 +26,14 @@ function (_, sup, moment, mainString,
target_user : window.TARGET_USER,
});
$('#main-body').html(html);
$('#oops_div').html(oopsString);
$('#waitwait_div').html(waitwaitString);
LoadExperimentTab();
// Should we do these on demand?
LoadProfileTab();
LoadProfileListTab();
LoadProjectsTab();
LoadMyProfileTab();
LoadProfileTab();
}
function LoadExperimentTab()
......@@ -70,7 +75,7 @@ function (_, sup, moment, mainString,
xmlthing.done(callback);
}
function LoadProfileTab()
function LoadProfileListTab()
{
var callback = function(json) {
console.info(json);
......@@ -83,7 +88,7 @@ function (_, sup, moment, mainString,
$('#profiles_noprofiles').removeClass("hidden");
return;
}
var template = _.template(profileString);
var template = _.template(profileListString);
$('#profiles_content')
.html(template({"profiles" : json.value,
......@@ -165,7 +170,12 @@ function (_, sup, moment, mainString,
xmlthing.done(callback);
}
function LoadMyProfileTab()
/*
* We actually display two profile tabs, one for the non-admin view,
* which is always the same. The other for the admin view.
*/
function LoadProfileTab()
{
var callback = function(json) {
console.info(json.value);
......@@ -177,10 +187,27 @@ function (_, sup, moment, mainString,
if (json.value.length == 0) {
return;
}
var template = _.template(myaccountString);
var template = _.template(profileString);
if (window.ISADMIN) {
$('#admin_content')
.html(template({"fields" : json.value,
"isadmin" : 1}));
// Format dates with moment before display.
$('#admin_content .format-date').each(function() {
var date = $.trim($(this).html());
if (date != "") {
$(this).html(moment($(this).html()).format("ll"));
}
});
$('#admin_content .toggle').click(function() {
Toggle(this);
});
}
$('#myprofile_content')
.html(template({"fields" : json.value}));
.html(template({"fields" : json.value,
"isadmin" : 0}));
}
var xmlthing = sup.CallServerMethod(null,
"user-dashboard", "AccountDetails",
......@@ -188,5 +215,24 @@ function (_, sup, moment, mainString,
xmlthing.done(callback);
}
//
// Toggle flags.
//
function Toggle(item) {
var name = item.dataset["name"];
var callback = function(json) {
if (json.code) {
sup.SpitOops("oops", json.value);
return;
}
LoadProfileTab();
};
sup.CallServerMethod(null, "user-dashboard", "Toggle",
{"uid" : window.TARGET_USER,
"toggle" : name},
callback);
}
$(document).ready(initialize);
});
......@@ -178,6 +178,8 @@ $routing = array("myprofiles" =>
"Do_ProjectList",
"ProfileList" =>
"Do_ProfileList",
"Toggle" =>
"Do_Toggle",
"AccountDetails" =>
"Do_AccountDetails")),
"show-project" =>
......@@ -189,8 +191,8 @@ $routing = array("myprofiles" =>
"Do_ProfileList",
"MemberList" =>
"Do_MemberList",
"ProjectDetails" =>
"Do_ProjectDetails")),
"ProjectProfile" =>
"Do_ProjectProfile")),
);
#
......
......@@ -112,6 +112,31 @@ function Do_MemberList()
SPITAJAX_RESPONSE($results);
}
function Do_ProjectProfile()
{
global $this_user, $target_project;
if (CheckPageArgs()) {
return;
}
if (!ISADMIN()) {
SPITAJAX_ERROR(-1, "Not enough permission");
return;
}
$results = array();
$results["pid"] = $target_project->pid();
$results["pid_idx"] = $target_project->pid_idx();
$results["leader"] = $target_project->head_uid();
$results["created"] = DateStringGMT($target_project->created());
$results["approved"] = $target_project->approved();
$results["url"] = $target_project->URL();
$results["description"] = $target_project->name();
$results["why"] = $target_project->why();
SPITAJAX_RESPONSE($results);
}
# Local Variables:
# mode:php
# End:
......
<div>
<table class='table table-condensed table-bordered' id="admin_table">
<tr>
<td>PID</td>
<td><%- fields.pid %> (<%- fields.pid_idx%>)</td>
</tr>
<tr>
<td>Description</td>
<td><%= fields.description %></td>
</tr>
<tr>
<td>URL</td>
<td><a href='<%- fields.url %>'><%= fields.url %></td>
</tr>
<tr>
<td>Leader</td>
<td><a href='user-dashboard.php?user=<%- fields.leader %>'>
<%= fields.leader %></a></td>
</tr>
<tr>
<td>Created</td>
<td class="format-date"><%= fields.created %></td>
</tr>
<tr>
<td>Approved</td>
<td><% if (fields.approved) { %>Yes<% } else { %>No<% } %></td>
</tr>
<tr>
<td colspan="2"><center>Long Description</center></td>
</tr>
<tr>
<td colspan="2"><%= fields.why %></td>
</tr>
</table>
</div>
......@@ -119,9 +119,7 @@
</div>
<% if (isadmin) { %>
<div role="tabpanel" class="tab-pane" id="admin">
<div id="admin_content">
Not yet sure what goes here.
</div>
<div id="admin_content"></div>
</div>
<% } %>
</div>
......
......@@ -114,7 +114,7 @@
</div>
<% if (isadmin) { %>
<div role="tabpanel" class="tab-pane" id="admin">
Not yet sure what goes here.
<div id="admin_content"></div>
</div>
<% } %>
</div>
......@@ -147,6 +147,5 @@
</div>
</div>
</div>
<div id='waitwait_div'></div>
<div id='oops_div'></div>
<style>
.toggle {
cursor: pointer;
}
</style>
<div>
<table class='table table-condensed table-bordered'>
<tr>
<td>Username</td>
<td><%- fields.uid %></td>
<td><%- fields.uid %>
<% if (isadmin) { %> (<%- fields.uid_idx %>)<% } %></td>
</tr>
<tr>
<td>Name</td>
......@@ -28,5 +34,41 @@
<td>City</td>
<td><%= fields.city %></td>
</tr>
<% if (isadmin) { %>
<tr>
<td>Created</td>
<td class="format-date"><%= fields.created %></td>
</tr>
<tr>
<td>Status</td>
<td><%= fields.status %></td>
</tr>
<tr>
<td>Administrator</td>
<td><% if (fields.admin) { %>
<span class="text-danger">Yes</span><% } else { %>No<% } %>
(Be very careful with this
<a class="toggle" data-name="admin">Toggle</a>)
</td>
</tr>
<tr>
<td>Foreign Admin</td>
<td><% if (fields.foreign_admin) { %>Yes<% } else { %>No<% } %>
(<a class="toggle" data-name="foreign_admin">Toggle</a>)
</td>
</tr>
<tr>
<td>Studly</td>
<td><% if (fields.stud) { %>Yes<% } else { %>No<% } %>
(<a class="toggle" data-name="stud">Toggle</a>)
</td>
</tr>
<tr>
<td>Web Frozen</td>
<td><% if (fields.web_frozen) { %>Yes<% } else { %>No<% } %>
(<a class="toggle" data-name="web_frozen">Toggle</a>)
</td>
</tr>
<% } %>
</table>
</div>
......@@ -141,9 +141,86 @@ function Do_AccountDetails()
$results["state"] = $target_user->state();
$results["city"] = $target_user->city();
if (ISADMIN()) {
$results["uid_idx"] = $target_user->uid_idx();
$results["created"] = DateStringGMT($target_user->created());
$results["status"] = $target_user->status();
$results["stud"] = $target_user->stud() ? true : false;
$results["admin"] = $target_user->admin() ? true : false;
$results["foreign_admin"] = $target_user->foreign_admin() ? true:false;
$results["web_frozen"] = $target_user->weblogin_frozen()? true:false;
}
SPITAJAX_RESPONSE($results);
}
#
# Toggle flags.
#
function Do_Toggle()
{
global $this_user, $target_user;
global $ajax_args;
global $TBMAIL_OPS, $TBMAIL_AUDIT, $TBMAIL_WWW, $TBADMINGROUP;
if (CheckPageArgs()) {
return;
}
if (!ISADMIN()) {
SPITAJAX_ERROR(-1, "Not enough permission");
return;
}
if ($target_user->status() != TBDB_USERSTATUS_ACTIVE) {
SPITAJAX_ERROR(-1, "User not been activated yet!");
return;
}
$target_idx = $target_user->uid_idx();
$target_uid = $target_user->uid();
$this_uid = $this_user->uid();
if (!isset($ajax_args["toggle"])) {
SPITAJAX_ERROR(-1, "Missing toggle name");
return -1;
}
$toggle = $ajax_args["toggle"];
if ($toggle == "admin") {
$target_user->SetAdminFlag($target_user->admin() ? 0 : 1);
if ($target_user->admin()) {
TBMAIL($TBMAIL_OPS,
"Admin Flag enabled for '$target_uid'",
"$this_uid has enabled the admin flag for $target_uid!\n\n",
"From: $TBMAIL_OPS\n".
"Bcc: $TBMAIL_AUDIT\n".
"Errors-To: $TBMAIL_WWW");
}
if (SUEXEC($this_uid, $TBADMINGROUP,
"webtbacct mod $target_uid", SUEXEC_ACTION_CONTINUE)) {
SPITAJAX_ERROR(-1, $suexec_output);
return -1;
}
if (SUEXEC($this_uid, $TBADMINGROUP,
"webmodgroups $target_uid", SUEXEC_ACTION_CONTINUE)) {
SPITAJAX_ERROR(-1, $suexec_output);
return -1;
}
}
elseif ($toggle == "foreign_admin") {
$target_user->SetForeignAdmin($target_user->foreign_admin() ? 0 : 1);
}
elseif ($toggle == "stud") {
$target_user->SetStudly($target_user->stud() ? 0 : 1);
}
elseif ($toggle == "web_frozen") {
$target_user->SetWebFreeze($target_user->weblogin_frozen() ? 0 : 1);
}
else {
SPITAJAX_ERROR(-1, "Unknown toggle name: $toggle");
return;
}
SPITAJAX_RESPONSE(1);
}
# Local Variables:
# mode:php
# End:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment