Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joelpalmer/b30f19e0fa6b88bf3be4 to your computer and use it in GitHub Desktop.
Save joelpalmer/b30f19e0fa6b88bf3be4 to your computer and use it in GitHub Desktop.
WCF RESTful services and JavaScript consumers for a document management application
WCF RESTful services and JavaScript Consumers
$(function () {
$('#jstree').on(
{
"move_node.jstree": function (e, data) {
$.get(SERVICE_PATH + "Main.svc/folder/move",
{
id: projectID,
node_id: data.node.id,
parent_node_id: data.old_parent,
target_node_id: data.parent
});
console.log(data.node.id + " moved");
},
"rename_node.jstree": function (e, data) {
$.get(SERVICE_PATH + "Main.svc/folder/update",
{
id: projectID,
node_id: GetNodeID(data.node.id),
text: data.node.text
});
console.log(data.node.id + " renamed");
},
"create_node.jstree": function (e, data) {
$.get(SERVICE_PATH + "Main.svc/folder/add",
{
id: projectID,
parent_node_id: data.parent,
text: data.node.text
})
.done(function (data) {
newNodeID = data.AddFolderResult;
})
.fail(function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
});
console.log(data.node.id + " added");
//setTimeout(function () { $('#jstree').jstree(true).refresh(); }, 1000);
},
"delete_node.jstree": function (e, data) {
var nodeText = data.node.text;
$.get(SERVICE_PATH + "Main.svc/folder/remove",
{
id: projectID,
node_id: GetNodeID(data.node.id)
})
.done(function (data) {
console.log(nodeText + " deleted");
})
.fail(function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
console.log(errorThrown);
setTimeout(function () {
$('#jstree').jstree(true).refresh();
}, 1000);
});
}
}
).jstree(
{
'core':
{
"multiple": false,
"check_callback": function (op, node) {
if (op === 'delete_node') { return confirm("Are you sure you want to delete " + node.text + "?"); }
if (op === 'move_node') {
if (_.isNull(node.data)) {
return true;
}
else { return !node.data.stationary; }
}
},
'data':
{
url: SERVICE_PATH + 'Main.svc/project/get?id=' + projectID,
dataFilter: function (data) {
return JSON.parse(data).GetProjectResult;
}
}
},
"types":
{
"#":
{
"max_children": 4,
"max_depth": 6,
"valid_children": ["root"]
},
"root":
{
"valid_children": ["default"]
},
"default":
{
"valid_children": ["default", "file"]
},
"file":
{
"icon": "fileicon.gif",
"valid_children": []
}
},
"plugins": [
"contextmenu", "dnd", "search",
"state", "types", "wholerow"
],
'contextmenu':
{
'items': customMenu
}
});
$('#userMessage').html("Project " + projectID);
});
function customMenu(node) {
var tmp = $.jstree.defaults.contextmenu.items();
var default_items = {
"create":
{
"label": "New Folder",
"action": function (data) {
var inst = $.jstree.reference(data.reference),
obj = inst.get_node(data.reference);
inst.create_node(obj,
{
type: "default"
}, "last", function (new_node) {
setTimeout(function () {
inst.edit(new_node);
console.log("create_node");
}, 0);
});
}
},
"Edit":
{
"label": "Edit Doc Details",
"_disabled": function (data) {
var inst = $.jstree.reference(data.reference), obj = inst.get_node(data.reference);
return obj.type == "file";
},
"action": function (data) {
var inst = $.jstree.reference(data.reference), obj = inst.get_node(data.reference);
setTimeout(function () {
window.open("DocDetails.html?pid=" + projectID + "&fid=" + GetNodeID(obj.id));
console.log("Edit Documents");
}, 0);
}
},
"Order":
{
"label": "Order Docs in Folder",
"_disabled": function (data) {
var inst = $.jstree.reference(data.reference), obj = inst.get_node(data.reference);
return obj.type == "file";
},
"action": function (data) {
var inst = $.jstree.reference(data.reference), obj = inst.get_node(data.reference);
setTimeout(function () {
window.open("OrderDocuments.html?pid=" + projectID + "&fid=" + GetNodeID(obj.id), 'winReOrder', 'width=750,height=500,scrollbars=auto');
console.log("Order Documents");
}, 0);
}
},
"rename":
{
"label": "Rename",
"_disabled": function (data) {
var inst = $.jstree.reference(data.reference), obj = inst.get_node(data.reference);
if (_.isNull(obj.data))
{
return false;
}
else{return obj.data.stationary;}
},
},
"remove":
{
"_disabled": false,
"label": "Delete",
"_disabled": function (data) {
var inst = $.jstree.reference(data.reference), obj = inst.get_node(data.reference);
if (_.isNull(obj.data)) {
return false;
}
else { return obj.data.stationary; }
},
},
//"refresh": {
// "label": "Refresh",
// "separator_before": true,
// "action": function (data) {
// var inst = $.jstree.reference(data.reference), obj = inst.get_node(data.reference);
// if (!inst.is_leaf(obj)) { inst.refresh_node(obj); }
// }
//},
"ccp": null
};
$.extend(true, tmp, default_items);
if (this.get_type(node) === "1drive") {
tmp = null;
}
else if (this.get_type(node) === "2folder") {
var default_items = {
"remove":
{
"_disabled": true,
"label": "Delete"
}
}
$.extend(true, tmp, default_items);
}
else if (this.get_type(node) === "3file") {
var default_items = {
"create": null
}
$.extend(true, tmp, default_items);
};
// $('.previewPane').append('<div>' + $.isFunction(tmp.create.action) + '</div>');
return tmp;
}
using System;
using System.Collections.Generic;
using System.ServiceModel.Web;
using System.IO;
using System.Linq;
using DMD;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace DMDService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Main" in code, svc and config file together.
public class Main : IMain
{
#region "Service Methods"
public string GetProject(string id)
{
string sReply;
bool bError = false;
try
{
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
Project oProject = new Project(Convert.ToInt32(id));
var oNodes = GetContainerItems(oProject.Containers.Items);
if (oProject.Containers.Documents.Count > 0)
{
oNodes.AddRange(oProject.Containers.Documents.Select(oDocument => new NodeProxy
{
id = oDocument.ID, text = oDocument.Name, type = "file"
}));
}
outResponse.Headers.Add("Cache-Control", "no-cache");
outResponse.Headers.Add("Pragma", "no-cache");
sReply = JsonConvert.SerializeObject(oNodes);
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.NotImplemented;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("GetProject (id: " + id + "). Reply: " + sReply, bError);
return sReply;
}
public string GetProjectDocuments(string id, string parent_node_id)
{
string sReply;
bool bError = false;
try
{
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
Project oProject = new Project(Convert.ToInt32(id));
DocumentsProxy oDocumentsProxy = new DocumentsProxy();
List<Document> oDocuments;
if (string.IsNullOrEmpty(parent_node_id))
{
oDocuments = oProject.Documents.Items;
}
else
{
int iParentID;
if (Int32.TryParse(parent_node_id, out iParentID))
{
oDocuments = oProject.Documents.GetDocumentsByParentID(iParentID);
oDocuments.Sort();
}
else
{
throw new Exception("Invalid Forder ID.");
}
}
if (oDocuments.Count > 0)
{
foreach (Document oDocument in oDocuments)
{
oDocumentsProxy.data.Add(new DocumentProxy(oDocument));
}
}
outResponse.Headers.Add("Cache-Control", "no-cache");
outResponse.Headers.Add("Pragma", "no-cache");
outResponse.Headers.Add("Expires", "0");
sReply = JsonConvert.SerializeObject(oDocumentsProxy, Formatting.None, new IsoDateTimeConverter() { DateTimeFormat = "MM/dd/yyyy" }).Replace("\\\"", "\"").Replace(":\"{", ":{").Replace("}\"}", "}}");
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.NotImplemented;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("GetProjectDocuments (id: " + id + ", parent_node_id: " + parent_node_id + "). Reply: " + sReply, bError);
return sReply;
}
public string MoveFolder(string id, string node_id, string parent_node_id, string target_node_id)
{
string sReply = "";
bool bError = false;
try
{
Project oProject = new Project(Convert.ToInt32(id));
oProject.Containers.Move(node_id, parent_node_id, target_node_id);
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.NotImplemented;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("MoveFolder (id: " + id + ", node_id: " + node_id + ", parent_node_id: " + parent_node_id + ", target_node_id: " + target_node_id + "). Reply: " + sReply, bError);
return sReply;
}
public string AddFolder(string id, string parent_node_id, string text)
{
string sReply = "";
bool bError = false;
try
{
long iNewNodeID;
String NodeID;
Project oProject = new Project(Convert.ToInt32(id));
oProject.Containers.Add(parent_node_id, text, false, out iNewNodeID);
NodeID = iNewNodeID.ToString();
sReply = JsonConvert.SerializeObject(NodeID);
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.NotImplemented;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("AddFolder (id: " + id + ", parent_node_id: " + parent_node_id + ", text: " + text + "). Reply: " + sReply, bError);
return sReply;
}
public string RemoveFolder(string id, string node_id)
{
string sReply = "";
bool bError = false;
try
{
Project oProject = new Project(Convert.ToInt32(id));
oProject.Containers.Remove(node_id);
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.NotImplemented;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("RemoveFolder (id: " + id + ", node_id: " + node_id + "). Reply: " + sReply, bError);
return sReply;
}
public string UpdateFolder(string id, string node_id, string text, string static_flag)
{
string sReply = "";
bool bError = false;
try
{
Project oProject = new Project(Convert.ToInt32(id));
oProject.Containers.Update(node_id, text, static_flag == "1");
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.NotImplemented;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("UpdateFolder (id: " + id + ", node_id: " + node_id + ", text: " + text + ", static_flag: " + static_flag + "). Reply: " + sReply, bError);
return sReply;
}
public string UpdateDocument(string project_id, string doc_id, string public_flag, string name, string description,
string sensitivity, string author, string addressee, string doclabel, string date)
{
string sReply = "";
bool bError = false;
try
{
Document oDocument = new Document(doc_id, project_id)
{
Public = public_flag == "1",
Name = name,
Description = description,
SensitivityRationale = Convert.ToInt16(sensitivity),
Author = author,
Addressee = addressee,
DateLabel = doclabel
};
DateTime dDocumentDate;
if (DateTime.TryParse(date, out dDocumentDate))
{
oDocument.Date = dDocumentDate;
}
else
{
oDocument.Date = null;
}
oDocument.Update();
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.NotImplemented;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("UpdateDocument (project_id: " + project_id + ", doc_id: " + doc_id + ", public_flag: " + public_flag + ", name: " + name +
", description: " + description + ", sensitivity: " + sensitivity + ", author: " + author + ", addressee: " + addressee +
", doclabel: " + doclabel + ", date: " + date + "). Reply: " + sReply, bError);
return sReply;
}
public string GetDocumentDetails(string project_id, string doc_id)
{
string sReply;
try
{
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
Document oDocument = new Document(doc_id, project_id);
outResponse.Headers.Add("Cache-Control", "no-cache");
outResponse.Headers.Add("Pragma", "no-cache");
outResponse.Headers.Add("Expires", "0");
sReply = JsonConvert.SerializeObject(oDocument);
}
catch (Exception e)
{
sReply = e.Message;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.NotImplemented;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("GetDocumentDetails (project_id: " + project_id + ", doc_id: " + doc_id + "). Reply: " + sReply, true);
return sReply;
}
public Stream DownloadProjectDocument(string project_id, string doc_id)
{
string sReply;
bool bError = false;
string sFileName = "";
Stream oReply = null;
try
{
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
Document oDocument = new Document(doc_id, project_id);
sFileName = oDocument.FileMetaData.filename;
byte[] oContent = oDocument.GetContent();
outResponse.Headers.Add("Cache-Control", "no-cache");
outResponse.Headers.Add("Pragma", "no-cache");
outResponse.Headers.Add("Expires", "0");
outResponse.Headers.Add("Content-Disposition", string.Format("attachment; filename={0}", sFileName));
oReply = new MemoryStream(oContent);
sReply = "Downloaded file " + sFileName;
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.NotImplemented;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("OpenProjectDocument (project_id: " + project_id + ", doc_id: " + doc_id + "). Reply: " + sReply, bError);
return oReply;
}
public string ReOrderDocuments(string project_id, string doc_id, string position)
{
string sReply = "";
bool bError = false;
try
{
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
Project oProject = new Project(Convert.ToInt32(project_id));
oProject.Documents.ReOrder(doc_id, Convert.ToInt32(position));
outResponse.Headers.Add("Cache-Control", "no-cache");
outResponse.Headers.Add("Pragma", "no-cache");
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.NotImplemented;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("ReOrderDocuments (project_id: " + project_id + ", doc_id: " + doc_id + ", position: " + position + "). Reply: " + sReply, bError);
return sReply;
}
public string GetToken(string project_id, string pals_pw, string userid)
{
string sReply;
bool bError = false;
try
{
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
Token token = new Token(project_id, pals_pw, userid);
outResponse.Headers.Add("Cache-Control", "no-cache");
outResponse.Headers.Add("Pragma", "no-cache");
sReply = token.GenerateToken().ToString();
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.BadRequest;
outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("GetToken (project_id: " + project_id + ", pals_pw: " + pals_pw + ", userid: " + userid + "). Reply: " + sReply, bError);
return sReply;
}
public string GetTokenInfo(string sToken)
{
string sReply;
bool bError = false;
Token token = new Token(sToken);
string tokenInfo = token.GetTokenInfo(sToken);
try
{
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.Headers.Add("Cache-Control", "no-cache");
outResponse.Headers.Add("Pragma", "no-cache");
sReply = tokenInfo;
}
catch (Exception e)
{
sReply = e.Message;
bError = true;
OutgoingWebResponseContext outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = System.Net.HttpStatusCode.BadRequest;
//outResponse.StatusDescription = sReply;
}
General.WriteToEventLog("GetToken (sToken: " + sToken + "). Reply: " + sReply, bError);
return tokenInfo;
}
#endregion
#region "Private Methods"
private List<NodeProxy> GetContainerItems(List<Container> Containers)
{
List<NodeProxy> oNodes = new List<NodeProxy>();
foreach (Container oContainer in Containers)
{
NodeProxy oNode = new NodeProxy();
oNode.id = oContainer.ID.ToString();
oNode.text = oContainer.Label;
oNode.data.stationary = oContainer.Static;
oNode.type = "default";
if (oContainer.Containers.Count > 0)
{
oNode.children = GetContainerItems(oContainer.Containers);
}
if (oContainer.Documents.Count > 0)
{
foreach (Document oDocument in oContainer.Documents)
{
NodeProxy oDocumentNode = new NodeProxy();
oDocumentNode.id = oDocument.ID.ToString();
oDocumentNode.text = oDocument.Name;
oDocumentNode.data.stationary = false;
oDocumentNode.type = "file";
oNode.children.Add(oDocumentNode);
}
}
oNodes.Add(oNode);
}
return oNodes;
}
#endregion
}
#region "Service Proxies"
public struct NodeState
{
public bool opened;
public bool disabled;
public bool selected;
}
public class NodeData
{
public bool stationary;
}
public class NodeProxy
{
private NodeState _state;
public string id { get; set; }
public string text { get; set; }
public string type { get; set; }
public NodeData data { get; set; }
public NodeState state
{
get { return _state; }
}
public List<NodeProxy> children { get; set; }
public NodeProxy()
{
children = new List<NodeProxy>();
_state.opened = false;
_state.disabled = false;
_state.selected = false;
data = new NodeData {stationary = false};
}
}
public class DocumentProxy
{
static int idCount = 0;
public int id { get; set; }
public Document values { get; set; }
public DocumentProxy()
{
idCount++;
id = idCount;
values = new Document();
}
public DocumentProxy(Document values)
{
idCount++;
id = idCount;
this.values = values;
}
}
public class DocumentMetaData
{
public string name { get; set; }
public string label { get; set; }
public string datatype { get; set; }
public bool editable { get; set; }
public string values { get; set; }
public DocumentMetaData(string name, string label, string datatype, bool editable, string values = null)
{
this.name = name;
this.label = label;
this.datatype = datatype;
this.editable = editable;
this.values = values;
}
}
public class DocumentsProxy
{
public List<DocumentMetaData> metadata { get; set; }
public List<DocumentProxy> data { get; set; }
public DocumentsProxy()
{
metadata = new List<DocumentMetaData>();
data = new List<DocumentProxy>();
metadata.Add(new DocumentMetaData("ID", "DocID", "string", false));
metadata.Add(new DocumentMetaData("Public", "Publish to Web?", "boolean", true));
metadata.Add(new DocumentMetaData("Name", "Name", "string", true));
metadata.Add(new DocumentMetaData("Description", "Description", "string", true));
metadata.Add(new DocumentMetaData("Author", "Author", "string", true));
metadata.Add(new DocumentMetaData("Addressee", "Addressee", "string", true));
metadata.Add(new DocumentMetaData("DateLabel", "Date Type", "string", true,GetDocumentGridList(DocumentGridLists.DateLabels)));
metadata.Add(new DocumentMetaData("Date", "Date", "date", true));
metadata.Add(new DocumentMetaData("DateAdded", "Date Added", "date", false));
metadata.Add(new DocumentMetaData("AddedBy", "Added By", "string", false));
metadata.Add(new DocumentMetaData("SensitivityRationale", "Sensitivity Rationale", "string", true, GetDocumentGridList(DocumentGridLists.SensitivityRationales)));
metadata.Add(new DocumentMetaData("Download", "Download Original", "string", false));
metadata.Add(new DocumentMetaData("Link", "Download PDF", "website", false));
metadata.Add(new DocumentMetaData("PDFfileSize", "Size, (kb)", "integer", false));
}
private string GetDocumentGridList(DocumentGridLists List)
{
Dictionary<int, string> oList = List == DocumentGridLists.SensitivityRationales ? General.GetSensitivityRationales() : General.GetDateLabels();
string sReturn = oList.Aggregate("", (current, oItem) => current + (current.Length == 0 ? "" : ",") + "\"" + oItem.Key.ToString() + "\":\"" + oItem.Value + "\"");
return String.Concat("{", sReturn, "}");
}
}
#endregion
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.IO;
namespace DMDService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IMain" in both code and config file together.
[ServiceContract]
public interface IMain
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "project/get?id={id}")]
string GetProject(string id);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "folder/move?id={id}&node_id={node_id}&parent_node_id={parent_node_id}&target_node_id={target_node_id}")]
string MoveFolder(string id, string node_id, string parent_node_id, string target_node_id);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "folder/add?id={id}&parent_node_id={parent_node_id}&text={text}")]
string AddFolder(string id, string parent_node_id, string text);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "folder/remove?id={id}&node_id={node_id}")]
string RemoveFolder(string id, string node_id);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "folder/update?id={id}&node_id={node_id}&text={text}&static_flag={static_flag}")]
string UpdateFolder(string id, string node_id, string text, string static_flag);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "documents/get?id={id}&parent_node_id={parent_node_id}")]
string GetProjectDocuments(string id, string parent_node_id);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "documents/update?project_id={project_id}&doc_id={doc_id}&public_flag={public_flag}&name={name}&description={description}&sensitivity={sensitivity}&author={author}&addressee={addressee}&doclabel={doclabel}&date={date}")]
string UpdateDocument(string project_id, string doc_id, string public_flag, string name, string description, string sensitivity, string author, string addressee, string doclabel, string date);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "documents/details?project_id={project_id}&doc_id={doc_id}")]
string GetDocumentDetails(string project_id, string doc_id);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "documents/download?project_id={project_id}&doc_id={doc_id}")]
Stream DownloadProjectDocument(string project_id, string doc_id);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "documents/reorder?project_id={project_id}&doc_id={doc_id}&position={position}")]
string ReOrderDocuments(string project_id, string doc_id, string position);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "authentication/gettoken?project_id={project_id}&pals_pw={pals_pw}&userid={userid}")]
string GetToken(string project_id, string pals_pw, string userid);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "authentication/login?token={token}")]
string GetTokenInfo(string token);
}
}
//var SERVICE_PATH = "http://localhost:65254/"; // /DMDService/ in test environment
window.onload = function () {
editableGrid = new EditableGrid("EditDocumentsGrid", {
enableSort: true, // true is the default, set it to false if you don't want sorting to be enabled
editmode: "absolute", // change this to "fixed" to test out editorzone, and to "static" to get the old-school mode
//editorzoneid: "edition", // will be used only if editmode is set to "fixed"
pageSize: 10
//maxBars: 10
//allowSimultaneousEdition: true,
//saveOnBlur: true
});
editableGrid.tableLoaded = function () { this.renderGrid("tablecontent", "testgrid"); };
if (_.isUndefined(folderID))
{
editableGrid.loadJSON(SERVICE_PATH + "Main.svc/documents/get?id=" + projectID);
}
else{
editableGrid.loadJSON(SERVICE_PATH + "Main.svc/documents/get?id=" + projectID + "&parent_node_id=" + folderID);
}
editableGrid.modelChanged = function (rowIndex, columnIndex, oldValue, newValue, row) {
//alert(this.data[rowIndex].columns[9]);
$.ajax({
url: SERVICE_PATH + "Main.svc/documents/update",
type: 'GET',
data: {
project_id: projectID,
doc_id: this.data[rowIndex].columns[0],
public_flag: Number(this.data[rowIndex].columns[1]),
name: this.data[rowIndex].columns[2],
description: this.data[rowIndex].columns[3],
sensitivity: this.data[rowIndex].columns[10],
author: this.data[rowIndex].columns[4],
addressee: this.data[rowIndex].columns[5],
docLabel: this.data[rowIndex].columns[6],
date: this.data[rowIndex].columns[7]
//&author={author}&addressee={addressee}&doclabel={doclabel}&date={date}"
},
success: function (response) {
//We may do something here
},
error: function (XMLHttpRequest, textStatus, exception) {
alert(XMLHttpRequest.responseText);
}
});
};
$('#userMessage').html("Project " + projectID);
_$('filter').onkeyup = function () { editableGrid.filter(_$('filter').value); };
}
//$(document).ready(function () {
// $(".editablegrid-ID").toggle().delay(1000);
//});
var projectID = GetQueryStringParams('pid');
var folderID = GetQueryStringParams('fid');
// function to render the paginator control
var updateCounter = 0;
EditableGrid.prototype.updatePaginator = function () {
var paginator = $("#paginator").empty();
var nbPages = this.getPageCount();
// get interval
var interval = this.getSlidingPageInterval(20);
if (interval == null) return;
// get pages in interval (with links except for the current page)
var pages = this.getPagesInInterval(interval, function (pageIndex, isCurrent) {
if (isCurrent) return "" + (pageIndex + 1);
return $("<a>").css("cursor", "pointer").html(pageIndex + 1).click(function (event) { editableGrid.setPageIndex(parseInt($(this).html()) - 1); });
});
if (updateCounter === 0)
{
this.firstPage();
}
// "first" link
var link = $("<a>").html("<img src='./images/gofirst.png'/>&nbsp;");
if (!this.canGoBack()) link.css({ opacity: 0.4, filter: "alpha(opacity=40)" });
else link.css("cursor", "pointer").click(function (event) { editableGrid.firstPage(); });
paginator.append(link);
// "prev" link
link = $("<a>").html("<img src='./images/prev.png'/>&nbsp;");
if (!this.canGoBack()) link.css({ opacity: 0.4, filter: "alpha(opacity=40)" });
else link.css("cursor", "pointer").click(function (event) { editableGrid.prevPage(); });
paginator.append(link);
// pages
for (p = 0; p < pages.length; p++) paginator.append(pages[p]).append(" | ");
// "next" link
link = $("<a>").html("<img src='./images/next.png'/>&nbsp;");
if (!this.canGoForward()) link.css({ opacity: 0.4, filter: "alpha(opacity=40)" });
else link.css("cursor", "pointer").click(function (event) { editableGrid.nextPage(); });
paginator.append(link);
// "last" link
link = $("<a>").html("<img src='./images/golast.png'/>&nbsp;");
if (!this.canGoForward()) link.css({ opacity: 0.4, filter: "alpha(opacity=40)" });
else link.css("cursor", "pointer").click(function (event) { editableGrid.lastPage(); });
paginator.append(link);
updateCounter++;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment