Don't create a new event on eventReceive with Full Calendar - fullcalendar

I'm working on a page where events are creating by dragging from a list onto a full calendar object. I'm then opening a dialog (bootstrap modal) to let the user edit the event.
During the edit, they might change the date or time of the initial drop. They could also conceivably cancel the event creation.
What I'd like to do is:
Don't create the initial event and just save after the modal is responded to. That is, I'd like eventReceive to fire, so I can trap it, but not have FullCalendar add the event to the calendar.

It's all here, just not in a 'recipe' manner: https://fullcalendar.io/docs/external-dragging
Set create to false in the Draggable and handle the drag with the drop event.

Related

How to set current item in App Maker datasource?

This seems basic but I can't seem to figure out how to manually set the current item to work with from the datasource?
To illustrate: I have a table and I notice that when I select a row to edit a field, the item of that row becomes the current item, so if I have a link on that row to Navigate to a page, the row of the item selected will be the datasource.item for the navigated page.
However, I also notice that if I just hover over a row, without selecting to edit a field, if then I click on a link to Navigate to a page, it loads the data of whatever row was previously selected/edited. Therefore I'm wondering how to make it so that just on a mouse:over (or click on the shortcut without a prior click on another field in the row) the datasource.item will update to the the row the mouse has gone over instead of requiring to edit a field on the row first. I hope that makes sense.
Assistance is much appreciated. Thank you!
Why it happens:
AM code: generate button click event
User code: handle button's click event
User code: navigate user to different page
AM code: destroy DOM of current page
AM code: build DOM for new page
-- dead code after this line
AM code: row click event handler
AM code: change datasource's current item
Row's click event handler never gets control, because row is destroyed by user's code.
What Morfinismo's solution does?
AM code: generate button click event
User code: handle button's click event
AM code: row click event handler
AM code: change datasource's current item
-- moved lines
User code: navigate user to different page
AM code: destroy DOM of current page
AM code: build DOM for new page
Here are more tech details: Event Loop
In App Maker this problem can be solved with
setTimeout
Force current item update in user code
// button's onClick event handler
app.datasource.ListDatasource.selectKey(widget.datasource.item._key);
CustomProperties
// button's onClick event handler
app.pages.ShowMeNext.properties.Key = widget.datasource.item._key;
app.showPage(app.pages.ShowMeNext);
// next page's onAttach event handler
app.datasources.RecordDatasource.filters._key._equals = app.currentPage.properties.Key;
app.datasources.RecordDatasource.load();
URL parameters and history - this approach is used in most template apps, because it also implements deep linking on some extent.
// button's onClick event handler
var params = {
key: widget.datasource.item._key
};
var page = app.pages.ShowMeNext;
app.showPage(page);
google.script.history.replace(null, params, page.name);
// next page's onAttach event handler
google.script.url.getLocation(function(location) {
app.datasources.RecordDatasource.filters._key._equals = location.parameters.key;
});
Passing value between pages using global scope
// button's onClick event handler
window.key = widget.datasource.item._key;
// next page's onAttach event handler
app.datasources.RecordDatasource.filters._key._equals = window.key;
ListDatasource - list/grid/table datasource
RecordDatasource - datasource dedicated for a specific record (single-record datasource)
Use a timeout function. This happens because it takes some time for appmaker to change the item in the datasource. You can use something like this on the onClick event handler of the button or link that will take you to the other page:
setTimeout(function(){
app.showPage(app.pages.pageToNavigate);
},200);
That should take care of the issue. I hope this helps!

Does full calendar have to re-render every event after an external event is dropped on the calendar?

I'm building a calendar that allows users to drag external events onto the calendar. When they do this an ajax call fires of and saves the event to the database. In order to understand what event is then resized or indeed rescheduled i update the event with the id of the event ive just created in the database. This means that if i need to further update the event. i.e someone moves the event or indeed changes the duration etc i can fire of the id with another ajax call and update the event.
The issue is that each time an event is dropped on the calendar, every event seems to re-render wiping out the id's that id added to each event. Are there any ways to prevent a full re-render? or a way to preserve id's on the element? you can see below i add the id occurance-387 to the html however when i add another event this gets wiped out. Any help would be appreciated! :-)
<a class="fc-day-grid-event fc-event fc-start fc-end fc-draggable fc-resizable _fc4" id="occurance-387"><div class="fc-content"> <span class="fc-title">A Very Short Introduction to… Anxiety</span></div><div class="fc-resizer"></div></a>
Don't add your id to the html. You should be storing your id as a property in the eventObject. Then, when you need to update your database, you can get the id out of the eventObject.
eventResize: function(event){
$.ajax('http://myendpoint.com/?saveNewEndDate", {id:event.id,newEndTime: event.end.format()},function(data){
if(data) {alert('Success!');}
});
}
There are other variables passed to the function that could be useful: delta, revertFunc. Check the documentation for details.
In my implementation, anytime a new event is saved to the calendar with drop callback function, my ajax response returns a json representation of a calendar eventObject and then I call renderEvent method to add it to the calendar. My json event object contains an id property.
$(#calendarContainer').fullCalendar('renderEvent', results.calendarEvent);

Which page event could be used for the following purpose?

I have a page which is having the following
Some ddl's for Filter the data
A Submit button
A export Button
A GridView
In general We show/hide Export button if submit query results more than zero rows/ no rows
NOTE:
It is not only the case for one button but there would be more and i will have to check for the permission for every where i show /hide the buttons
For Example
Page_Load
showHideAsPerPermission(btnExport);
BtnSubmitClick()
if rows>0
btnExport.Visible = true;
else
btnExport.Visible = false;
But for the purpose of Permission
I want to set Export button visibility to true/false after BtnSubmit_click (or all controls events like selected index change, textChanged etc.) event has fired
A little Explanation of my problem
Say if you have permission to export then it only visible when rows>0 and if you don't have then it invisible even rows>0 but if i set the permission on page load and then i set exports visibility true for rows > 0 then it is visible even you don't have permission so is there any event which fires after control events
Is there any method which i can utilize for this purpose
I have read the following events and tried Page_Unload event which actually does nothing cause page is already rendered
So is there any method which could accomplish my task
Note:
As per my Knowledge there is no such Event so can i create a custom page event?
Just do it in Page_Load.
Keep in mind, on BtnSubmit_click, the page will post back, Page_Load is going to execute again (so you'll probably need something like if (!IsPostback)...), and then BtnSubmit_click.

Button in CustomControl added in OnClick doesn't postback until second click

I have the following scenario:
UserControlA contains a <asp:Button id="bSomeid" onClick="AddItem" /> with some code to an item to a shopping basket in AddItem.
UserControlB contains some LinkButton's that dynamically add a selection of UserControlA to the page in the OnClick event.
This is all done in an UpdatePanel. It is a little more complicated but I have pruned the information to what I believe is causing the problem, I will add more information if necessary.
The problem I have is that it takes 2 clicks for the AddItem event to trigger after I have added the items to the page after clicking the LinkButton.
I understand why this is happening - it is to late in the page cycle to register events for the next post back in the onclick - but can anyone think of a way around this? Can I force an event to be triggered on the next postback? I have tried to think of a way to run my code in page_load but I requuire access to the sender in the onClick.
Using .NET 4.0.
EDIT
I managed to find a way to get the link button sending the request in the Page_Load (using Request.Form["__EVENTTARGET"];) so I moved my code to the Page_load event. It still requires 2 clicks so I am assuming it isn't something to do with the onClick being registered to late.
Are there any other general things to check that could cause a button to require 2 clicks to post an event properly?
If your suspicion about being late in page life cycle is true then you can try using ScriptManager.RegisterAsyncPostBackControl method to register dynamically added controls in the link button click - considering that your button is within user control, you need to add public method into UserControlA that would actually register the button bSomeid1 and link button click from UserControlB would actually call the A control's method.
EDIT :
Another cause for button click not happening can be that button being dynamic control is not added in the page hierarchy when post-back happens (or it gets added very late in the page life cycle when the post back data is already processed). A really full-proof solution should add dynamic controls back to the page hierarchy in page_load it-self (and strictly maintaining same controls ids within hierarchy). If that's not possible then you can sniff the request (Request.Form) to detect the post-back.
In your case, you should ascertain if the button is indeed causing the post-back on each click. If yes, what is the POST data (Request.Form) for the first request - what is the __EVENTTARGET value on the first click (and post-back)? That should start your trouble-shooting.
On the other hand, a simple work-around could be to use html anchor element (you can still use link button) and have a javascript handler in the click event that would set some hidden variable and then submit the form (you can simulate the click on hidden button to trigger ASP.NET client side submit pipeline) . Now the hidden variable value can be used on the post-back to determine which link button has been clicked.
"Are there any other general things to check that could cause a button to require 2 clicks to post an event properly?"
Does it require two clicks on the control, or does it take accept a single click elsewhere on the screen, and then fire first time with a single click on the control?
I have my own (similar) issue with the Updatepanel where the first (expected) trigger does not fire and it seems that a single click elsewhere, and then the subsequent triggers fires first time (which totals 2 clicks)
[edit] Since you are working on this ATM, it may help me as well. Do you have a textbox with a trigger event on it? I do, and if I leave this blank (so that it does not fire) then there is no need for a second click.

vs2008 web express: detailsview can not hide new button

On details view, I would like to hide the new button.
On page load I have successfully done so by the following code:
dtvwMyProfile.Rows[5].Cells[0].Controls[2].Visible = false;
But how do I hide the New button when I hit cancel or update button after I am done editing.
The New button keeps showing up. How do I hide it completely from the screen.
In some event, the visible property keeps changing to true and how do i find out that event?
I want to be able to do it at run time instead of design time.
Dynamically changing the properties of child controls created by the DetailsView is not recommended.
If the button is being created by the DetailsView itself then all you need to do is set AutoGenerateInsertButton to false and you can do that in Page_Load.
I do not recommend randomly selecting a page event and handling it. If you do that then chances are it will just break again when you change something else.
Maybe try to do that in the ModeChanged event handler, which fires after the mode changes... But can you ensure new is always at position 2? You may want to verify the button by its text or command name.

Resources