Change Title On Save

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Change Title On Save

DeHaynes
I have a form.  I want the title to be changed to a combination of two fields on the form whenever it is saved.  Can someone point me in the right direction to learn how to accomplish this?

Sorry if this is a newbie question.  

Reply | Threaded
Open this post in threaded view
|

Re: Change Title On Save

Guillaume "Louis-Marie" Delhumeau
Do you really want the title to _store_ the 2 fields or you only expect it
to _display_ the 2 fields?

I assume it is the second case. You can use velocity in the title field of
a document.

So you can do something like:
$doc.get('field1') - $doc.get('field2")

I hope it helps,
LM


2014-03-18 20:23 GMT+01:00 DeHaynes <[hidden email]>:

> I have a form.  I want the title to be changed to a combination of two
> fields
> on the form whenever it is saved.  Can someone point me in the right
> direction to learn how to accomplish this?
>
> Sorry if this is a newbie question.
>
>
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667.html
> Sent from the XWiki- Dev mailing list archive at Nabble.com.
> _______________________________________________
> devs mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/devs
>
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: Change Title On Save

DeHaynes
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Change Title On Save

DeHaynes
This post was updated on .
Maybe if I explain in better detail.  I am creating 3 forms.
1. Person
2. Department
3. Company

The idea is that there is a Company Form for each company.  

In the Company Form, there is a Department TextArea section.  In that section would be links to various Department Forms.  

In the Department Form, there is a Personnel TextArea section.  In that section would be links to various Person Forms for people who work in that department.  

I would like to standardize the forms to have a consistent document name and title.  They would be:
1. Person - FirstName and LastName
2. Department - Department Name
3. Company - Company Name

I would like to save the document name and title when they save the document.  

For Company and Department, if I could expose the Title field to be edited by the user and just give it the "Department Name" or "Company Name" label, then that would work.  For the Person Form, I would have to combine two fields with a space between them.

I thought of using a JavascriptExtension to do this.  I saw where you can listen for the save event.  Unfortunately I could not find how to reference the various fields of the document from JavaScript.

Reply | Threaded
Open this post in threaded view
|

Re: Change Title On Save

Guillaume "Louis-Marie" Delhumeau
2014-03-19 21:22 GMT+01:00 DeHaynes <[hidden email]>:

> Maybe if I explain in better detail.  I am creating 3 forms.
> 1. Person
> 2. Department
> 3. Company
>
> The idea is that there is a Person document for each company.
>
> In the Company Form, there is a Department TextArea section.  In that
> section would be links to various Department Forms.
>
> In the Department Form, there is a Personnel TextArea section.  In that
> section would be links to various Person Forms for people who work in that
> department.
>
> I would like to standardize the forms to have a consistent document name
> and
> title.  They would be:
> 1. Person - FirstName and LastName
>

In the title of your sheet:
#set($obj = $doc.getObject('myClass'))$obj.display('firstName', 'view')
$obj.display('lastName', 'view')


> 2. Department - Department Name
>

In the title of your sheet:
#set($obj = $doc.getObject('myClass'))Department:
$obj.display('departmentName', 'view')


> 3. Company - Company Name
>

In the title of your sheet:
#set($obj = $doc.getObject('myClass'))Company: $obj.display('companyName',
'view')

And please see:
http://extensions.xwiki.org/xwiki/bin/view/Extension/Sheet+Module for more
informations about the Sheet system.

I hope it helps,
Louis-Marie
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: Change Title On Save

DeHaynes
Thank you very much for your response.  While this does change the Title that is displayed on the form, it doesn't change the name of the document.  I researched and found the following command in the API.

$doc.rename($doc.display('departmentName'))

I need to figure out how to apply it just before a save event.


Reply | Threaded
Open this post in threaded view
|

Re: Change Title On Save

Guillaume "Louis-Marie" Delhumeau
If you want to change the document name, it is more complicated, indeed. I
think you should dig into the javascript area.


2014-03-20 14:07 GMT+01:00 DeHaynes <[hidden email]>:

> Thank you very much for your response.  While this does change the Title
> that
> is displayed on the form, it doesn't change the name of the document.  I
> researched and found the following command in the API.
>
> $doc.rename($doc.display('departmentName'))
>
> I need to figure out how to apply it just before a save event.
>
>
>
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667p7589726.html
> Sent from the XWiki- Dev mailing list archive at Nabble.com.
> _______________________________________________
> devs mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/devs
>
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: Change Title On Save

DeHaynes
I thought so also, so I looked into the JavascriptExtension and put the following code into it.

document.observe("xwiki:actions:saved", function(event){
  var doContinue = event.memo['continue'];
  if (doContinue) {
    alert('Saved It.');
  }
});

The alert did not fire when I clicked the saved button.  So I moved the alert outside of the "If" block.  It still did not fire.  

While digging into this further, it occurred to me that I cannot just change the value of some "DocumentName" field on the form because the document document name is not on the form.  So I would have to reach into the XWiki object model somehow.  I could not find an example of that or an API listing.  I decided to drop this researching the javascript solution because what I really want to happen is going to occur at the server, not the browser.

So I am not trying to figure out if there is another way to approach this.  I would love to know your thoughts on my logic.  That could help me determine which way is the correct way to accomplish this.

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Change Title On Save

Guillaume "Louis-Marie" Delhumeau
2 approaches:

1 (easy) - write a form with some fields that create a new document with a
computed name. It will not rename the document if you change the fields
afterwards, but depending on your use-case, it might be enough.

2 (more complex) - write a listener component that rename the document, if
needed, every time a document is saved. It needs to be written in Groovy or
in Java. See:
http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyNotificationTutorialand
http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents

Louis-Marie


2014-03-20 15:53 GMT+01:00 DeHaynes <[hidden email]>:

> I thought so also, so I looked into the JavascriptExtension and put the
> following code into it.
>
> document.observe("xwiki:actions:saved", function(event){
>   var doContinue = event.memo['continue'];
>   if (doContinue) {
>     alert('Saved It.');
>   }
> });
>
> The alert did not fire when I clicked the saved button.  So I moved the
> alert outside of the "If" block.  It still did not fire.
>
> While digging into this further, it occurred to me that I cannot just
> change
> the value of some "DocumentName" field on the form because the document
> document name is not on the form.  So I would have to reach into the XWiki
> object model somehow.  I could not find an example of that or an API
> listing.  I decided to drop this researching the javascript solution
> because
> what I really want to happen is going to occur at the server, not the
> browser.
>
> So I am not trying to figure out if there is another way to approach this.
> I would love to know your thoughts on my logic.  That could help me
> determine which way is the correct way to accomplish this.
>
> Thank you.
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667p7589731.html
> Sent from the XWiki- Dev mailing list archive at Nabble.com.
> _______________________________________________
> devs mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/devs
>
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: Change Title On Save

Guillaume "Louis-Marie" Delhumeau
2014-03-20 16:20 GMT+01:00 Guillaume "Louis-Marie" Delhumeau <
[hidden email]>:

> 2 approaches:
>
> 1 (easy) - write a form with some fields that create a new document with a
> computed name. It will not rename the document if you change the fields
> afterwards, but depending on your use-case, it might be enough.
>

Note: this approach does not require you to know the Java language. It is
not the perfect solution, but I often do that.

Louis-Marie
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs