Event DeletedPage gives me wrong PageLink when emptying wastebin - episerver

I wired up the DeletedPage event in my Global.asax like this:
DataFactory.Instance.DeletedPage += this.Instance_DeletedPage;
And my handler:
private void Instance_DeletedPage(object sender, PageEventArgs pageEventArgs)
{
DeleteCustomerRoles(pageEventArgs.PageLink);
}
When I move a page to the wastebin, nothing fires of course since it is moved. When I delete the page from the wastebin - the event fires and I get the deleted page's PageLink in pageEventArgs.
But... When I instead select the wastebin and clicks on the "Empty wastebin" button, I get the PageLink corresponding to the wastebin - not my deleted page!
Is this a feature or a bug? I see that there is some sort of list of linked pages on the page object in the pageEventArgs, but I assume that all pages that are deleted (even children) will trigger the DeletedPage event. Is this not true?

Ok, this seems to be a known behaviour:
http://world.episerver.com/Support/Bug-list-beta/bug/33750/
Although there is a setting to revert some of the peculiar behavior, the wastebin part of it remains. I find this really odd, but it seems I'll have to look elsewhere to find a workaround for really getting to know when a page is deleted, regardless of how.

Seems to be a way to get this working that neither or us apparently knew about:
http://world.episerver.com/Forum/Developer-forum/-EPiServer-75-CMS/Thread-Container/2014/8/Datafactory-deleted-page-event1/
http://world.episerver.com/Forum/Developer-forum/-EPiServer-75-CMS/Thread-Container/2014/5/Bug-in-DeletingPage/
Hope you will find this information helpful!
/Martin

Related

Smoothstate : Get $(document) in onReady

How to get to $(document) in the onReady method ?
I've tried with smoothState.cache[smoothState.href] but couldn't make it works.
(fantastic plugin)
Thanks
I'm assuming you want to get at the document for the new page that's being loaded. Technically, $(document) exists in onReady, and it's the first document you visited on the site. After that, smoothState just dynamically updates it by swapping out content. So whatever existed on the previous page you were viewing is there as normal. Once the line $container.html( $newContent ); runs in your onReady method (assuming your code follows all the smoothState examples), you new content should be available.
However, if you want to get at the actual, full document for the new page that got loaded up, not just what's contained in your wrapper div that gets swapped out, it's contained in smoothState.cache[smoothState.href].doc. It's got the header, the body, everything.
A little reading of the smoothState source code shows that you can pull it into a useful format this way:
var $newDoc = $("<html></html>").append( $(smoothState.cache[smoothState.href].doc) );
At this point, you can run find queries or whatever you need to go look through things.

Usually the form is POST, but in a single instance it is GET

I do a standard pattern in my application - a link to /controller/delete/object_id, then a post form to "confirm", a check if $this->request->is('post') and if true - the controller deletes the object from database.
What is weird is that for a single, particular object_id, my browser (Firefox) forces the form to be a GET one. With any other object_id everything is ok, but with this particular one, despite all declarations within form tag and etc. brower generates a GET request.
Do you have any clue what this might be?! I even tried to use brower's private mode, because I thought it can be some garbage in browser cache, but the bug is still here.
I managed to bypass this problem:
define a specific action in form->create, pointing to your controller' method
add a hidden field with object_id
add some additional code in the controller method to get object_id from $this->request->data, because a hidden post field is not passed as an argument to method, as it is with GET method.
This way, to some unknown reason, it just works. Anyway, I still feel I'm doing something wrong. It's not as "clean" as I would expect.

Reload Grid in ATK4

I'm trying to learn enough to create a website that lets people answer quiz questions using Agile Toolkit 4.2.
I have a page that displays one question and its answer choices from the 'sampleq' model. I want to make a button that displays the next record in the model.
I've tried a bunch of different ways to get the js()->reload() command to work properly, but I haven't been able to do it. I get AJAX "unexpected identifier" error. I've been through the related questions on this site and looked for documentation on the ATK site, but I haven't found an example that works for me.
Can anybody tell me how to get the button to properly reload the grid?
function init(){
parent::init();
$page=$this;
}
function page_qlisting() {
$qid=$this->recall('value',1);
echo $qid;
$NextB=$this->add('Button')->SetLabel('Next Question '.$qid);
$grid=$this->add('Grid');
$grid->setModel('sampleq',array('question','A1','A2','A3'));
$grid->dq->where('id=',$qid);
if($NextB->isClicked()){
//$this->memorize('value',$qid+1);
$grid->js()->reload();
}
}
function page_qentry() {
$this->api->auth->check();
$this->add('Html')->set('Welcome to the question entry page.<br>');
$this->add('CRUD')->setModel('sampleq');
}
}
Edit:
After reading Romans' answer, I first tried this:
$qid=$this->recall('value',1);
$grid=$this->add('Grid');
$grid->setModel('sampleq',array('id','question','A1','A2','A3'));
$grid->dq->where('id=',$qid);
$this->add('Button')->SetLabel('Next Question')->js('click', $this->memorize('value',$qid+1))->js('click', $grid->js()->reload());
That actually works - it displays only one record at a time, and it displays the next one when I click the button. Next I tried adding a "Previous" button like so:
$qid=$this->recall('value',1);
$grid=$this->add('Grid');
$grid->setModel('sampleq',array('id','question','A1','A2','A3'));
$grid->dq->where('id=',$qid);
$this->add('Button')->SetLabel('Previous Question')->js('click', $this->memorize('value',$qid-1))->js('click', $grid->js()->reload());
$this->add('Button')->SetLabel('Next Question ')->js('click', $this->memorize('value',$qid+1))->js('click', $grid->js()->reload());
This doesn't work, though. Both buttons are decrementing. I tried laying it out like your adjuster buttons example here. Here's what my increment button code looks like in that attempt:
$incr=$this->add('Button')->SetLabel('Next Question');
if($incr->isClicked()){
$this->memorize('value',$qid+1);
$grid->js()->reload();
}
In that case, I get "Error in AJAXec response: SyntaxError: Unexpected identifier" when I click the button.
Can you offer any advice on how to make increment and decrement work with a grid (or crud)? Why doesn't the adjuster example work when you try to refresh a grid instead of refreshing the button? Thanks for the previous answer, and thanks in advance for any additional guidance that you may have time to offer.
This should be it:
$this->add('Button')->js('click', $grid->js()->reload());
If you use CRUD you might want to reload CRUD instead.

Backbone events firing multiple times even though I am following proper standards

I have a table that when I click on a row, in a side div I display the details. I have created an event on the row (tr) that is fired every time that row is clicked. The problem I have is that the event is being fired multiple times. It is acting as if a new view is being created everytime the event is fired, but a new view is not being created. Here is the code:
GroupView = class App.GroupView extends Backbone.View
template: App.Utils.getTemplate 'group'
selectedId: 0
events:
'click tr': 'selectGroup'
selectGroup: (e) ->
thisEl = $(e.currentTarget)
$(thisEl).closest('tr').siblings().removeClass 'selected'
$(thisEl).closest('tr').addClass 'selected'
#selectedId = $(thisEl).data().id
#getGroupDetails #selectedId
render: ->
$(#$el).html #template
groups: #collection.models
if #selectedId is 0
firstRowEl = $(#$el).find('tr:first')
$(firstRowEl).addClass 'selected'
#selectedId = $(firstRowEl).data().id
#getGroupDetails #selectedId
getGroupDetails: (id, platform) ->
$('<img/>',
src: 'img/ajax_loader_2.gif'
class: 'ajax-loader'
).appendTo '.group-details'
renderGroupDetails id
groupDetails = new GroupDetailsView
el: '.group-details'
model: groupDetailsModel
renderGroupDetails = (id)->
groupDetails.el = '.group-details'
groupDetails.stopListening groupDetailsModel
groupDetails.listenTo groupDetailsModel, 'change', ->
groupDetails.model =
groupDetails: groupDetailsModel.toJSON()
groupDetails.render()
groupDetailsModel.fetch
data:
id: id
processData: true
The issue is that when I use the groupDetails.stopListening groupDetailsModel, the multiple event firing issue is resolved but then NONE of the events in the groupDetails view is being fired.
Any help is appreciated.
Cheers,
Kianosh
So, giving you a specific answer is difficult: the code you've pasted is a bit hard to follow, and seems like it might be missing bits (eg. what's a groupDetailsModel? Does it have any logic that affects it's view?). That's ok though, because I think what you need here is more debugging help than a specific answer.
If I understand you correctly, your problem is that groupDetails.render() is being invoked extra times, and you're not sure why or what is invoking it: is that correct? If so, your trusty debugger can answer this in a matter of seconds.
NOTE: Everything I'm about to say applies to Chrome (with the built-in developer tools up) or Firefox (with the Firebug extension up) for sure. It probably applies to other browsers with their tools too, I just can't say for sure since I don't use them.
Approach #1: Debugger
With your debugger up, add a debugger; line as the first thing inside your GroupDetails.prototype.render method. This will make your browser pause on that line whenever it hits it. While its paused you can check the "call stack" on the right-hand side, and that will show you exactly what bit of your code just called that render. You can also use the debugger to inspect the values of the different variables in your environment to try and understand why your code is calling render.
Approach #2: Console.trace
If you're not a fan of using the debugger, there's another tool that's also perfect for answering this sort of question. Simply add console.trace() as the first line in your render method, then run your code as normal. This time your browser will log (to the "console") a stack trace generated from that point in the code. This stack trace is similar to the call stack that you can see when you use debugger, and thus it will tell you exactly what code invoked the render each time.
Hope that helps.

Dojo : FilteringSelect : problems with coming back to valid state

I've came across this issue today and I think I might need some help. We are using 1.6.1 version of Dojo, but this is cross version issue.
Steps to reproduce the following issue are pretty simple:
click the dojo doc link for Filtering Select dijit.form.FilteringSelect
On the documentation page, click the first FilteringSelect sample
In the Codeglass window sample, click the filteringselect and add "x" to "California", thus bringing it to invalid state
While focused, delete the "x" letter.
and here comes the problem. Technically the value is correct, but the dijit is still like in error state (unless it loses focus).
I'd like to get the dijit react and render correctly straightaway I delete the character causing the invalid state without losing focus.
Any ideas for the workaround?
Thank you.
ok. for eveyryone else interested the solution was 'quite' simple, just use the dijit.form.FilteringSelect._refreshState() .The underscore prefix is might not be someone's cup of tea but that was the only way to get it in correct state.
in our case it was a bit tricky as we are using the dojox.data.QueryReadStore wrapped in our own object and I needed the proper trigger which I've found in connecting to onComplete event of the inherited fetch() method.

Resources