cancel
Showing results for 
Search instead for 
Did you mean: 

creating a new space using webscripts

mialfresco
Champ in-the-making
Champ in-the-making
Hi team,
I'm following a tutorial at http://drquyong.com/myblog/?p=5… Actually this is a very good tutorial for beganers.

This is really a simple UI which illustrates most ways…
This ui allows only for creating the small text documents only.
Now i want to provide an option like "Create a Space", if the user clicks on this i want to display a form where the user can fill the details like name,desc,title for the space. for that i have added a new link in DocumentList.get.html.ftl like
Create a Space
   <img src="${url.context}/images/icons/folder.gif" onClick="createSpace();"/></b>
   </tr>

and cretaeSpace java script is


var sdlg;
function createSpace() {
         document.getElementById("space_label").innerHTML='Create Space';
         document.forms['space_new'].action = '${url.serviceContext}/simpleui/document/createSpace';
         sdlg.show();
      }

and space_new form is,


<div dojoType="dialog" id="SpaceDialog" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
   <form name="space_new" action="" method="post">
      <table>
         <tbody>
            <tr>
               <th colspan="2"><b><div id="space_label"></div></b></th>
            </tr>
            <tr>
               <td>Name</td>
               <td><input id="space_name" name="sn" type="text"></td>
            </tr>

            <tr>
               <td>Title</td>
               <td><input id="space_title" name="st" type="text"></td>
            </tr>

            <tr>
               <td>Description</td>
               <td><input id="space_description" name="sd" type="text" size="60"></td>
            </tr>
            
            <tr>
               <td colspan="2" align="center">
                  <INPUT type="hidden" id="file_noderef" name="noderef" value=""/>
                  <INPUT type="submit" value="Create">
                  <input type="button" id="hider2" value="Cancel" onClick="sdlg.hide()"></td>
            </tr>
         </tbody>
      </table>
   </form>
   </div>

and my FolderCreate.post.js is

// Client has requested server-side action

// Client has requested server-side action

/* Inputs */


/* Outputs */
var resultString = "Action failed",
   resultCode = false;


         resultString = "Could not create space";
        var spaceName = args.sn,
            spaceTitle = (args.st == "undefined") ? "" : args.st,
            spaceDescription = (args.sd == "undefined") ? "" : args.sd,
          
         var nodeNew;
        
         if ((spaceName == null) || (spaceName == ""))
         {
            resultString = "Space must have a Name";
         }
         else
         {
           
            var nodeParent = roothome.childByNamePath("/Company Home/User Homes/Demo" + spaceName);
          
         nodeNew = nodeParent.createFolder(spaceName);
          
            // Always add title & description, default icon
            nodeNew.properties["cm:title"] = spaceTitle;
            nodeNew.properties["cm:description"] = spaceDescription;
            nodeNew.properties["app:icon"] = "space-icon-default";
            nodeNew.save();
            // Add uifacets aspect for the web client
            nodeNew.addAspect("app:uifacets");
            if (nodeNew != null)
            {
               resultString = "New space created";
               resultCode = true;
            }
         }
    
  
model.resultString = resultString;
model.resultCode = resultCode;




and my FolderCreate.desc.xml is
<webscript>
  <shortname>Create Space</shortname>
  <description>Create a space to store info from Teamworks</description>

   <url format="html" template="/simpleui/document/createSpace?n={nodeId}&amp;sn={spaceName}&amp;st={spaceTitle?}&amp;sd={spaceDescription?}" />
  <authentication>user</authentication>

</webscript>


my problem is i'm passing 3 variables like space name, space title, descrption in the spaceCreate form.

and i'm getting the following error in browser.

The Web Script /alfresco/service/simpleui/document/createSpace has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   Wrapped Exception (with status template): Failed to execute script '/alfresco/demo/simpleui/FolderCreate.post.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': missing variable name (AlfrescoScript#17)
   
Exception:   org.mozilla.javascript.EvaluatorException - missing variable name (AlfrescoScript#17)
   
   org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
   org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:96)
   org.mozilla.javascript.Parser.addError(Parser.java:140)
   org.mozilla.javascript.Parser.reportError(Parser.java:154)
   org.mozilla.javascript.Parser.mustMatchToken(Parser.java:240)
   org.mozilla.javascript.Parser.variables(Parser.java:1260)
   org.mozilla.javascript.Parser.statementHelper(Parser.java:1057)
   org.mozilla.javascript.Parser.statement(Parser.java:655)
   org.mozilla.javascript.Parser.parse(Parser.java:377)
   org.mozilla.javascript.Parser.parse(Parser.java:315)
   org.mozilla.javascript.Context.compileImpl(Context.java:2320)
   org.mozilla.javascript.Context.compileString(Context.java:1348)
   org.mozilla.javascript.Context.compileString(Context.java:1337)
   org.mozilla.javascript.Context.evaluateString(Context.java:1193)
   org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:390)
   org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:122)
   org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:263)
   org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:108)
   org.alfresco.web.scripts.AbstractWebScript.executeScript(AbstractWebScript.java:800)
   org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:90)
   org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:319)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:320)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:227)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:368)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:390)
   org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:273)
   org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:261)
   org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:139)
   org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:116)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   java.lang.Thread.run(Thread.java:595)
   
Exception:   org.alfresco.error.AlfrescoRuntimeException - missing variable name (AlfrescoScript#17)
   
   org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:406)
   
Exception:   org.alfresco.scripts.ScriptException - Failed to execute script '/alfresco/demo/simpleui/FolderCreate.post.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': missing variable name (AlfrescoScript#17)
   
   org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:126)
   
Exception:   org.alfresco.web.scripts.WebScriptException - Wrapped Exception (with status template): Failed to execute script '/alfresco/demo/simpleui/FolderCreate.post.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': missing variable name (AlfrescoScript#17)
   
   org.alfresco.web.scripts.AbstractWebScript.createStatusException(AbstractWebScript.java:595)
   
Server:   Alfresco Labs v3.0.0 (Stable 1526) schema 1,002
Time:   Jun 29, 2009 4:29:02 PM


The full DocumentList.get.html.ftl is,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
   <title>Alfresco Simple UI</title>
   <script type="text/javascript">
      var djConfig = {
         isDebug: true
         ,debugAtAllCosts: true
      };
   </script>
   <script type="text/javascript" src="${url.context}/scripts/ajax/dojo/dojo.js"></script>
   <script type="text/javascript">
      dojo.require("dojo.widget.FilteringTable");
      dojo.require("dojo.widget.InlineEditBox");
      dojo.require("dojo.widget.Dialog");
      dojo.require("dojo.event.*");
      dojo.hostenv.writeIncludes();
      
      var dlg,previewdlg,removedlg;
      function init(e) {
         dlg        = dojo.widget.byId("DialogContent");
         previewdlg = dojo.widget.byId("DialogPreview");
         removedlg  = dojo.widget.byId("DialogRemove");
         sdlg        = dojo.widget.byId("SpaceDialog");



      }
      dojo.addOnLoad(init);
      
      function populate(id,noderef) {
         document.getElementById("file_label").innerHTML='Edit File';
         document.forms['edit_new_form'].action = '${url.serviceContext}/simpleui/document/save';
         document.getElementById("file_name").value=document.getElementById("name_"+id).innerHTML;
         document.getElementById("file_description").value=document.getElementById("desc_"+id).innerHTML;
         document.getElementById("file_body").value=document.getElementById("body_"+id).innerHTML;
         document.getElementById("file_noderef").value=noderef;
         dlg.show();
      }

      function populatepreview(id) {
         document.getElementById("preview_name").innerHTML=document.getElementById("name_"+id).innerHTML;
         document.getElementById("preview_body").innerHTML=document.getElementById("body_"+id).innerHTML;
         previewdlg.show();
      }
      
      function populateremove(id,noderef) {
         document.getElementById("remove_name").value=document.getElementById("name_"+id).innerHTML;
         document.getElementById("remove_noderef").value=noderef;
         removedlg.show();
      }

      function create() {
         document.getElementById("file_label").innerHTML='Create File';
         document.forms['edit_new_form'].action = '${url.serviceContext}/simpleui/document/create';
         dlg.show();
      }


      function createSpace() {
         document.getElementById("file_label").innerHTML='Create Space';
         document.forms['space_new'].action = '${url.serviceContext}/simpleui/document/createSpace';
         sdlg.show();
      }




   </script>
   <style type="text/css">
      /***
         The following is just an example of how to use the table.
         You can override any class names to be used if you wish.
      ***/
      table {
         font-family:Lucida Grande, Verdana;
         font-size:0.8em;
         width:100%;
         border:1px solid #ccc;
         border-collapse:collapse;
         cursor:default;
      }
      table td,
      table th{
         padding:2px;
         font-weight:normal;
      }
      table thead td, table thead th {
         background-image:url(${url.context}/images/dojo/ft-head.gif);
         background-repeat:no-repeat;
         background-position:top right;
      }
      table thead td.selectedUp, table thead th.selectedUp {
         background-image:url(${url.context}/images/dojo/ft-headup.gif);
      }
      table thead td.selectedDown, table thead th.selectedDown {
         background-image:url(${url.context}/images/dojo/ft-headdown.gif);
      }
         
      table tbody tr td{
         border-bottom:1px solid #ddd;
      }
      table tbody tr.alt td{
         background: #e3edfa;
      }
      table tbody tr.selected td{
         background: yellow;
      }
      table tbody tr:hover td{
         background: #a6c2e7;
      }
      table tbody tr.selected:hover td{
         background:#ff9;
      }

      #inputArea{
         margin:1em 0;
         padding:1em;
         background-color:#eef;
      }
      #updateTestInput{
         border:1px solid #ccc;
         width:100%;
         height:80px;
         font-family:serif;
         font-size:0.9em;
         overflow:auto;
      }
      
      .bar a img {
         border:0;
         vertical-align: middle;
      }
      
      .dojoDialog {
         background : #eee;
         border : 1px solid #999;
         -moz-border-radius : 5px;
         padding : 4px;
         width: 80%
      }
      

      .footer {
         text-align: center;
         position:absolute;
         font-family:Lucida Grande, Verdana;
         font-size:0.8em;
         bottom:10px;
         left: 35%
      }

   </style>

</head>
<body>
   <div dojoType="dialog" id="DialogPreview" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
      <table>
         <tbody>
            <tr>
               <th><b>Previw File </b><div id="preview_name"></div></th>
            </tr>
            <tr>
               <td><div id="preview_body"></div></td>               
            </tr>
            <tr>
               <td align="center"><input type="button" id="hide3" value="Close" onClick="previewdlg.hide()"></td></td>               
            </tr>
         </tbody>
      </table>   
   </div>
   <div dojoType="dialog" id="DialogRemove" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
   <form name="remove_form" action="${url.serviceContext}/simpleui/document/remove" method="post">   
      <table>
         <tbody>
            <tr>
               <th><b>Remove File </b><INPUT type="text" id="remove_name" name="name" value="" disabled/></th>
            </tr>
            <tr>
               <td>Do you really really really want to delete this file?</td>               
            </tr>
            <tr>
               <td align="center">
               <INPUT type="hidden" id="remove_noderef" name="noderef" value=""/>
               <INPUT type="hidden" id="remove_name" name="name" value=""/>
               <input type="submit" value="Ok"/>
               <input type="button" id="hide3" value="Cancel" onClick="removedlg.hide()"></td></td>               
            </tr>
         </tbody>
      </table>
   </form>   
   </div>
   <div dojoType="dialog" id="DialogContent" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
   <form name="edit_new_form" action="" method="post">
      <table>
         <tbody>
            <tr>
               <th colspan="2"><b><div id="file_label"></div></b></th>
            </tr>
            <tr>
               <td>Name</td>
               <td><input id="file_name" name="name" type="text"></td>
            </tr>
            <tr>
               <td>Description</td>
               <td><input id="file_description" name="desc" type="text" size="60"></td>
            </tr>
            <tr>
               <td valign="top">Body</td>
               <td><textarea id="file_body" name="body" rows="10" cols="60"></textarea></td>
            </tr>
            <tr>
               <td colspan="2" align="center">
                  <INPUT type="hidden" id="file_noderef" name="noderef" value=""/>
                  <INPUT type="submit" value="Save">
                  <input type="button" id="hider2" value="Cancel" onClick="dlg.hide()"></td>
            </tr>
         </tbody>
      </table>
   </form>
   </div>









<div dojoType="dialog" id="SpaceDialog" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
   <form name="space_new" action="" method="post">
      <table>
         <tbody>
            <tr>
               <th colspan="2"><b><div id="space_label"></div></b></th>
            </tr>
            <tr>
               <td>Name</td>
               <td><input id="space_name" name="sn" type="text"></td>
            </tr>

            <tr>
               <td>Title</td>
               <td><input id="space_title" name="st" type="text"></td>
            </tr>

            <tr>
               <td>Description</td>
               <td><input id="space_description" name="sd" type="text" size="60"></td>
            </tr>
            
            <tr>
               <td colspan="2" align="center">
                  <INPUT type="hidden" id="file_noderef" name="noderef" value=""/>
                  <INPUT type="submit" value="Create">
                  <input type="button" id="hider2" value="Cancel" onClick="sdlg.hide()"></td>
            </tr>
         </tbody>
      </table>
   </form>
   </div>





















   <h3>Simple Alfresco User Interface</h3>
   <h4>Hello ${person.properties.firstName}!</h4>
   <tr>   <b>Create a File
   <img src="${url.context}/images/icons/add.gif" onClick="create();"/>
   Create a Space
   <img src="${url.context}/images/icons/folder.gif" onClick="createSpace();"/></b>
   </tr>
   <table dojoType="filteringTable" id="documentList" alternateRows="true" maxSortable="2"

         cellpadding="0" cellspacing="0" border="0">
         
         
         
         
   <thead>

      <tr>
         <th field="Name" dataType="String" sort="asc" valign="top">Name</th>
         <th field="DateAdded" dataType="DateTime" align="center" valign="top">Created</th>
         <th field="DateModified" dataType="DateTime" align="center" valign="top">Modified</th>
         <th dataType="html">Description</th>
         <th dataType="html">Body</th>
         <th dataType="html">Actions</th>
      </tr>
   </thead>

   <tbody>
     <#list resultset as node>
     <tr value="${node_index + 1}">
       <td><div id="name_${node_index + 1}">${node.name}</div></td>
       <td>${node.properties.created?datetime}</td>
       <td>${node.properties.modified?datetime}</td>
       <td><div id="desc_${node_index + 1}">${node.properties.description}</div></td>
       <td><div id="body_${node_index + 1}">${node.content}</div></td>
       <td>
          <div class="bar">
             <a href="#" onClick="populatepreview('${node_index + 1}')"><img src="${url.context}/images/icons/preview.gif"/></a>
             <a href="#" onClick="populate('${node_index + 1}','${node.nodeRef}')"><img src="${url.context}/images/icons/edit_icon.gif"/></a>
             <a href="${url.serviceContext}/api/node/content/${node.nodeRef.storeRef.protocol}/${node.nodeRef.storeRef.identifier}/${node.nodeRef.id}/${node.name?url}"><img src="${url.context}/images/icons/CheckOut_icon.gif"/></a>
             <a href="#" onClick="populateremove('${node_index + 1}','${node.nodeRef}')"><img src="${url.context}/images/icons/delete.gif"/></a>      
          </div>
       </td>
     </tr> 
     </#list>
   </tbody>
   </table>
   <div class="footer">
            Alfresco. &copy; 2009-2010 All rights reserved.
   </div>
</body>
</html>
13 REPLIES 13

jayjayecl
Confirmed Champ
Confirmed Champ
i changed the line to


         
   var nodeParent = companyhome.childByNamePath("Demo" + spaceName);

I thought your space "Demo" is in "User Homes", not in "Company Home"

Try by iteration :
logger.log("spaceName value : " + spaceName);
var userhomeNode = companyhome.childByNamePath("User Homes");
logger.log("userHomeNode value : " + userhomeNode.name);
var demoNode1 = userhomeNode.childByNamePath("Demo");
logger.log("demoNode1 value : " + demoNode1.name);
var demoNode2 = companyhome.childByNamePath("Demo/User Homes");
logger.log("demoNode2 value : " + demoNode2.name);

etc …

jayjayecl
Confirmed Champ
Confirmed Champ
please give us results about what you tried and what the logs are

mialfresco
Champ in-the-making
Champ in-the-making
Hi Jay,
I'm trying to do the same whatever you guys suggested. But still no luck.
I'm having the folder Demo under company home.

logger.log("spaceName value : " + spaceName);   — it is giving the name of the folder which i'm trying to  create

var userhomeNode = companyhome.childByNamePath("User Homes"); 
logger.log("userHomeNode value : " + userhomeNode.name); – it is also giving the Users Home
var demoNode1 = userhomeNode.childByNamePath("Demo");
logger.log("demoNode1 value : " + demoNode1.name);  – it is giving error bcoz there is no space named Demo under Comaopany Home/Users Home/
var demoNode2 = companyhome.childByNamePath("Demo/User Homes");
logger.log("demoNode2 value : " + demoNode2.name); – it is also giving error

in browser it is showing the following error.

The Web Script /alfresco/service/simpleui/document/createSpace has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   Wrapped Exception (with status template): Failed to execute script '/alfresco/demo/test/simpleui/FolderCreate.post.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': TypeError: Cannot call method "createFolder" of null (AlfrescoScript#33)
   
Exception:   org.mozilla.javascript.EcmaError - TypeError: Cannot call method "createFolder" of null (AlfrescoScript#33)
   
   org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)
   org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340)
   org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3356)
   org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3375)
   org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3394)
   org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2026)
   org.mozilla.javascript.gen.c75._c0(AlfrescoScript:33)
   org.mozilla.javascript.gen.c75.call(AlfrescoScript)

jayjayecl
Confirmed Champ
Confirmed Champ
Well, you did not understand what I told you by MP.
can you try to adapt what I wrote to your situation ???

If you don't have "Demo" under User Homes, of course this is silly to try
var demoNode1 = userhomeNode.childByNamePath("Demo"); 

You should not need anyone to do that :

var demoNode1 = companyhome.childByNamePath("Demo");
logger.log("demoNode1 value : " + demoNode1.name);
etc …