提交 5126e4f2 编写于 作者: N nilspreusker

added button and fileChooser dialog to add artifact links

上级 1696a9b3
......@@ -45,4 +45,9 @@
#artifact-div .yui-navset div.loading div {
background:url("/activiti-cycle/res/images/loading.gif") no-repeat scroll center center transparent;
height:8em;
}
#artifact-div .yui-push-button {
margin-top: 10px;
margin-left: 1px;
}
\ No newline at end of file
......@@ -26,12 +26,14 @@
this.onEvent(Activiti.event.clickFormEventButton, this.onClickFormEventButton);
this._tabView = {};
this._connectorId = "";
this._repositoryNodeId = "";
this._isRepositoryArtifact = false;
this._name = "";
this._activeTabIndex = 0;
this._fileChooserDialog = {};
this._linksDataTable = {};
return this;
};
......@@ -130,8 +132,6 @@
this._tabView.addTab(tab);
}
// ------------------------------ Links Tab --
// Add artifact links tab
var linksTab = new YAHOO.widget.Tab({
label: "Links",
......@@ -145,8 +145,6 @@
this._tabView.addTab(linksTab);
// -------------------------- End Links Tab --
this._tabView.appendTo('artifact-div');
// replace the tabViews onActiveTabCHange evnet handler with our own one
......@@ -244,7 +242,6 @@
tabContent = '<div class="artifact-text-plain"><pre id="' + responseJson.contentRepresentationId + '">' + responseJson.content + '</pre></div>';
}
tab.set('content', tabContent);
//{ "renderInfo": "IMAGE", "contentRepresentationId": "PNG", "contentType": "image\/png", "imageUrl": "\/activiti-cycle\/proxy\/activiti-rest-endpoint\/content?artifactId=%2FDemo%2Fminutes%2FInitialMindmap.mm&contentRepresentationId=PNG" }
}
catch (e) {
alert("Invalid response for tab data");
......@@ -255,7 +252,7 @@
try{
var responseJson = YAHOO.lang.JSON.parse(response.responseText);
tab.set('content', '<div id="linksTab"/>');
tab.set('content', '<div id="linksTable"></div><span id="addLink" class="yui-button"><span class="first-child"><button type="button">Add link</button></span></span>');
var linksColumnDefs = [
{key:"Name", sortable:true},
......@@ -274,12 +271,16 @@
fields: ["Name","Revision","Type"]
};
var linksDataTable = new YAHOO.widget.DataTable("linksTab", linksColumnDefs, linksDataSource, {scrollable:true});
this._linksDataTable = new YAHOO.widget.DataTable("linksTable", linksColumnDefs, linksDataSource, {scrollable:true});
var linkElements = Dom.getElementsByClassName("openArtifactLink", "a");
for (var i = 0; i < linkElements.length; i++) {
YAHOO.util.Event.addListener(linkElements[i], "click", this.onArtifactLinkClick, this, true);
}
var addLinkButton = new YAHOO.widget.Button("addLink", { label:"Add link", id:"addLinkButton" });
addLinkButton.addListener("click", this.onClickAddLinkButton, null, this);
}
catch (e) {
alert("Invalid response for tab data");
......@@ -326,7 +327,29 @@
onClickFormEventButton: function Artifact_onClickFormEventButton(event, args)
{
return new Activiti.component.FileChooserDialog(this.id, args[1].value.callback);
return new Activiti.component.FileChooserDialog(this.id, args[1].value.callback, false, null, true, false);
},
onClickAddLinkButton: function Artifact_onClickAddLinkButton(event, args)
{
return new Activiti.component.FileChooserDialog(this.id, "onAddLinkSubmit", true, this, false, true);
},
onAddLinkSubmit: function Artifact_onAddLinkSubmit(obj) {
this.services.repositoryService.createArtifactLink({"connectorId": this._connectorId, "artifactId": this._repositoryNodeId, "targetConnectorId": obj.connectorId,"targetArtifactId": obj.nodeId});
},
/**
* This method is called when the service method createArtifactLink returns and reloads
* the links-tab so the new row in the links-table becomes visible.
*
* @param args object that contains three attributes: config, json and serverResponse
*/
onCreateArtifactLinkSuccess: function Artifact_onCreateArtifactLinkSuccess(args)
{
this._tabView.getTab(this._activeTabIndex).set( 'cacheData', false );
this._tabView.selectTab( this._activeTabIndex );
this._tabView.getTab(this._activeTabIndex).set( 'cacheData', true );
}
});
......
......@@ -16,7 +16,7 @@
* @return {Activiti.component.RepoTree} The new component.FileChooserDialog instance
* @constructor
*/
Activiti.component.FileChooserDialog = function FileChooserDialog_constructor(htmlId, callbackFn)
Activiti.component.FileChooserDialog = function FileChooserDialog_constructor(htmlId, callbackFn, showFiles, scope, highlightFolders, highlightFiles)
{
Activiti.component.FileChooserDialog.superclass.constructor.call(this, "Activiti.component.FileChooserDialog", htmlId);
......@@ -27,6 +27,10 @@
this._treeView = {};
this._currentNode = {};
this._callbackFn = callbackFn;
this._showFiles = showFiles;
this._scope = scope;
this._highlightFolders = highlightFolders;
this._highlightFiles = highlightFiles;
return this;
};
......@@ -94,7 +98,16 @@
// instantiate the TreeView control
this._treeView = new YAHOO.widget.TreeView("fileChooserTree", treeNodesJson);
this._treeView.singleNodeHighlight = true;
this._treeView.subscribe('clickEvent', this.onTreeNodeLabelClicked, this, true);
this._treeView.subscribe('clickEvent', this.onTreeNodeLabelClicked, this, true);
for(var nodeIndex in this._treeView._nodes) {
var node = this._treeView.getNodeByIndex(nodeIndex);
if(node.data.folder) {
node.enableHighlight = this._highlightFolders;
} else if (node.data.file) {
node.enableHighlight = this._highlightFiles;
}
}
// set the callback function to dynamically load child nodes
// set iconMode to 1 to use the leaf node icon when a node has no children.
......@@ -116,8 +129,38 @@
var treeNodesJson = response.json;
for(var i = 0; i<treeNodesJson.length; i++) {
if(treeNodesJson[i].folder) {
var node = new YAHOO.widget.TextNode(treeNodesJson[i], obj[0], treeNodesJson[i].expanded);
if( treeNodesJson[i].folder ) {
var node = new YAHOO.widget.TextNode(treeNodesJson[i], obj[0], false);
node.enableHighlight = this._highlightFolders;
} else if( this._showFiles && treeNodesJson[i].file ) {
var node = new YAHOO.widget.TextNode(treeNodesJson[i], obj[0], true);
if(treeNodesJson[i].contentType) {
if(treeNodesJson[i].contentType === "image/png" || treeNodesJson[i].contentType === "image/gif" || treeNodesJson[i].contentType === "image/jpeg") {
node.labelStyle = "icon-img";
} else if(treeNodesJson[i].contentType === "application/xml") {
node.labelStyle = "icon-code-red";
} else if(treeNodesJson[i].contentType === "text/html") {
node.labelStyle = "icon-www";
} else if(treeNodesJson[i].contentType === "text/plain") {
node.labelStyle = "icon-txt";
} else if(treeNodesJson[i].contentType === "application/pdf") {
node.labelStyle = "icon-pdf";
} else if(treeNodesJson[i].contentType === "application/json;charset=UTF-8") {
node.labelStyle = "icon-code-blue";
} else if(treeNodesJson[i].contentType === "application/msword") {
node.labelStyle = "icon-doc";
} else if(treeNodesJson[i].contentType === "application/powerpoint") {
node.labelStyle = "icon-ppt";
} else if(treeNodesJson[i].contentType === "application/excel") {
node.labelStyle = "icon-xls";
} else if(treeNodesJson[i].contentType === "application/javascript") {
node.labelStyle = "icon-code-blue";
} else {
// Use white page as default icon for all other content types
node.labelStyle = "icon-blank";
}
}
node.enableHighlight = this._highlightFiles;
}
}
......@@ -153,7 +196,12 @@
onSubmit: function FileChooserDialog_onSubmit() {
if(this._currentNode.data && this._currentNode.data.connectorId && this._currentNode.data.artifactId && this._currentNode.label) {
this._callbackFn({"connectorId": this._currentNode.data.connectorId, "nodeId": this._currentNode.data.artifactId, "nodeName": this._currentNode.label});
if(this._scope) {
this._scope[this._callbackFn]({"connectorId": this._currentNode.data.connectorId, "nodeId": this._currentNode.data.artifactId, "nodeName": this._currentNode.label});
} else {
this._callbackFn({"connectorId": this._currentNode.data.connectorId, "nodeId": this._currentNode.data.artifactId, "nodeName": this._currentNode.label});
}
} else {
// TODO: handle error... should never happen due to validation, though...
}
......
......@@ -126,6 +126,27 @@
executeArtifactFormURL: function RepositoryService_executeArtifactFormURL(connectorId, artifactId, artifactActionName)
{
return Activiti.service.REST_PROXY_URI_RELATIVE + "artifact-action?connectorId=" + encodeURIComponent(connectorId) + "&artifactId=" + encodeURIComponent(artifactId) + "&actionName=" + encodeURIComponent(artifactActionName);
},
/**
* Creates a new artifactLink by posting the provided artifactLinkLiteral parameter to the
* REST API. The 'artifactLinkLiteral' is an object literal that should contain the following
* values: "connectorId", "artifactId", "targetConnectorId", "targetArtifactId"
*
* @param artifactLinkLiteral object literal with the values of the link to be created
*/
createArtifactLink: function RepositoryService_createArtifactLink(artifactLinkLiteral) {
this.jsonPost(this.createArtifactLinkURL(), artifactLinkLiteral, null, "createArtifactLink");
},
/**
* Creates the POST url to use when creating an artifact-link
*
* @method createArtifactLinkURL
* @return {string} The url
*/
createArtifactLinkURL: function RepositoryService_createArtifactLinkURL() {
return Activiti.service.REST_PROXY_URI_RELATIVE + "artifact-link";
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册