I've created doc type with property e.g. (Name = "ItemId" Type = "Label") When i try to "Save and Publish" node with current doc type i set some value to this label. (note that i override SendAsync method)
currentContent.SetValue("ItemIdAlias","guidvalue");
It sets value correctly, but label still appears to be empty. So if i click on "Save and Publish" second time it sends an empty value still... I need somehow to refresh page because on second time i need "guidvalue" to update other items
If you're using Umbraco 6, you'll need to get your event handler to emit some JS to refresh the page. You can do this by calling the following code in your Event Handler:
BasePage.Current.ClientTools.ChangeContentFrameUrl(string.Concat("editContent.aspx?id=", docId));
Where docId is the id of the page you are editing. This will force a full reload of the page, and your label should then have a value!
If you're using Umbraco 7, you're out of luck, there's currently no way to do this from the server side. You might be able to listen to the angular save event and do something there maybe? But I'm not 100% if that's possible currently.
Related
I have an application that uses a combination of ContentService.Saved & ContentService.Saving to extend Umbraco to manage content.
I have two websites in one Umbraco installation I am using those methods to keep content up to date in different parts of the tree.
So far I have got everything working the way I wanted to.
Now I want to add a feature that: depending on which Umbraco User is logged in, will either publish the content or simply send it for approval.
So I have changed some lines of code from:
cs.SaveAndPublishWithStatus(savedNode, 0, false)
To this:
cs.SendToPublication(savedNode);
Now the problem that I am finding is that unlike the SaveAndPublishWithStatus() method, the cs.SendToPublication(); doesn't have the option of passing false so that a save event is not raised. So I get into an infinite loop.
When I attach the debugger and manually stop the infinite loop the first time it calls cs.SendToPublication(savedNode); I get exactly the behavior I want.
Any ideas about how I can get round this problem? Is there a different method that I should be using?
You are correct in saying that it currently isn't possible to set raiseEvents to false when sending an item to publication - that's a problem.
I've added that overload in v. 7.6 (http://issues.umbraco.org/issue/U4-9490).
However considering that you need this now, an interim solution could be that you make sure your code is only run once when triggered by the .Saved / .Saving events.
One way to do this would be to check the last saved date (UpdateDate) in your code. If the content was saved within the last second of the current save operation, you know that this is a save event triggered by the save happening in SendToPublication action. Then you also know that the item has already been sent to publication and that this doesn't need to be done again - thereby preventing the endless loop from happening.
I want to display last updated date in umbraco 4.7
Say if i even make a small change in content from the admin panel, it has to pull the updated date so that i can show that in footer of the website dynamically.
Thanks.
Every node has a property called updateDate which you can get in razor by using:
#Model.UpdateDate
If I understand this correctly, you want it so that any update to any content item updates the "last updated" information in your footer.
I'd hook into the publish event (this link should get you started),create a variable to store the date, and update it every time a node gets published, then read and output it in the code that generates your footer.
Trying to implement Fine-Uploader for first time.
There's a way I can add a text-field for each file pending uploading?
I want the user to comment the content of each file and than save these informations.
Thanks for explanations.
Dario.
If you want to add an input text field next to each file represented in the UI (I'm assuming you are using FineUploader mode), you can do the following:
Set the autoUpload option to false. This seems obvious, but I thought I should list it anyway. If you don't set this to false, files will be uploaded immediately after the user selects them. I'm guessing this would not fit into your workflow.
Define an onSubmitted callback handler. In this handler, you can use the id parameter to get a handler on the associated getItemByFileId API method.
Once you have the element that represents the file in the UI, you can add an input field next to it. Perhaps you should add a data attribute or a css class that you can later use to associate this field with the file.
I assume you intend to create a button that a user will click when they are ready to start uploading all selected files, presumably after they have filled out any text fields associated with these files. So, you can add a click handler to this button that calls the uploadStoredFiles API method.
You will also need to contribute an onUpload callback handler. When your handler is invoked (once for each file, before it is uploaded), grab the value from the associated text field and then use the setParams API method to send this value with the upload (POST) request for this file as a parameter. Don't forget to include the file ID as the last parameter when you call setParams.
I am working on a website created in ModX. I need to know the way I could execute a php code when any resource is created and also edit template variable associated to the created resource.
You can do this using a plugin, set to run on the OnDocFormSave event. This event has a mode property which will be set to new when the document being saved has just been created - you can do a simple check for this to prevent the plugin being run every time a document is saved.
To set a TV value for the current resource, do this:
// get the required TV object by name (or id)
$tv = $modx->getObject('modTemplateVar',array('name'=>'tvName'));
// set the new value and save it
$tv->setValue($modx->resource->get('id'), $newValue);
$tv->save();
The answer by okyanet is correct, but I've added details for those unfamiliar with MODX.
Create a plugin, and configure it to execute on the two system events 'onBeforeDocFormSave' and 'onDocFormSave'. The two events are fired just before and just after a resource is saved. When a resource is saved, the $mode variable is available to your plugin, and if it is a new resource it's value is modSystemEvent::MODE_NEW and if an update its value is modSystemEvent:MODE_UPD
I've written a gist that includes the full code with examples:
https://gist.github.com/2768300
This example shows you how to target either event through a switch statement, and how to further target the 'new' or 'update' status of the action. For intercepting and changing resource fields, its quite easy using the onBeforeDocFormSave event as you can simply change any resource fieldname with $resource->set('yourFieldname'). There is no $resource->save() required as this happens automatically after this event.
It's apparently much more difficult to save a tv using the onBeforeDocFormSave event, because of the way tvs are processed, so therefore the example shows how to update a tv using the system event 'onDocFormSave'. Again there is no $resource->save() required as tvs are saved immediately when you call 'setValue' on them.
A plugin could be made to function requiring only one of the system events, but as there are advantages to using both states as shown above, and to help explain, I have used both.
I'm developing a firefox extension. Inside my extension I use:
content.location.assign(url)
Depending on the users input content.location.assign(url) gets called again after a short time. It seems like my 2nd assign gets ignored. I'm looking for a way to abort the in process request to push trough the current one.
If I'm not wrong, try using either of this methods:-
reload(forceget)
Reload the document from the current URL. forceget is a boolean, which, when it is true, causes the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache.
replace(url)
Replace the current document with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.
You shouldn't use content.location to load a new page into the browser; instead use loadURI(url[, referrer[, postData[, allowThirdPartyFixup]]]) to load a page and BrowserStop() to cancel a load.