This is a migrated thread and some comments may be shown as answers.

cannot cancel OnClientAppointmentWebServiceInserting

17 Answers 198 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Fabian Gehri
Top achievements
Rank 1
Fabian Gehri asked on 03 Mar 2010, 02:02 PM
Hi.

I'm integrating RadScheduler in an ASP.NET MVC 2 application and therefore have to use WebService binding (this is still true, right?)

My Problem now is that I want to cancel the insertion of an appointment if some conditions are fulfilled (e.g. the user did not specify the subject or did not specify a resource). Since I am using WebService binding I have to use the OnClientAppointmentWebServiceInserting method because server-side events are not called (correct me if I'm wrong).

My function looks like this:
OnClientAppointmentWebServiceInserting="inserting"  
function inserting(sender, eventArgs) { 
    var app = eventArgs.get_appointment(); 
    var error = false
 
    // set error = true if appointment is not valid... 
 
    if (error) { 
        alert("error"); 
        eventArgs.set_cancel(true); 
    } 

The behaviour I would expect is that the insertion of the appointment is cancelled and the inserting form does not hide. Unfortunately after the alert the form hides and - even worse - the appointment is shown in the Scheduler until I rebind.

By writing
if (error) { 
       alert("error"); 
       eventArgs.set_cancel(true); 
       sender.rebind(); 
 } 
I can achieve that the appointment is not shown, but still I want the form to remain visible so that the user can correct the errors without losing the data he already entered.

How can I achieve this behaviour? Or is it just not possible?

Any Feedback would be appreciated.

Thanks,
Fabian

PS: The demo at http://demos.telerik.com/aspnet-ajax/scheduler/examples/webservice/defaultcs.aspx allows appointments without a subject to be inserted whereas this demo at http://demos.telerik.com/aspnet-ajax/scheduler/examples/clientsideevents/defaultcs.aspx (which does not use WebService binding) does not, at least in the advanced form.

17 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 08 Mar 2010, 03:42 PM
Hi Fabian,

I can confirm that cancelling the appointmentWebServiceInserting event will have exactly this effect - the appointment will be rendered, but it won't be sent to the web service. We'll definitely consider firing the event earlier or providing a new event altogether.

For the moment you can override the insertAppointment function in order to abort the insert operation:

<script type="text/javascript">
    (function() {
        var oldFunc = Telerik.Web.UI.RadScheduler.prototype.insertAppointment;
        Telerik.Web.UI.RadScheduler.prototype.insertAppointment = function (appointment)
        {
            if (...)
                return; // Cancel inserting
                 
            oldFunc.call(this, appointment);
        };
    })();
</script>


I can also confirm the problem with the subject validator in the advanced form. We've fixed it and the fix will be part of the official Q1 release.

As a token of our gratitude for your involvement, your Telerik points have been updated.

Best wishes,
Tsvetomir Tsonev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fabian Gehri
Top achievements
Rank 1
answered on 09 Mar 2010, 11:20 AM
Hi Tsvetomir,

thanks a lot for your answer.

Overriding the insertAppointment function works fine, the appointment is not rendered and I don't have to rebind. So, of course, this is now faster than before. Also I have done the same for the updateAppointment function..

But still, the inserting/updating form hides when I cancel insert/updateAppointment. Did I understand you right that it will not be possible to not hide it until you fire the event earlier or provide a new event? If so, can you say approximately when you will consider this?

Thanks,
Fabian
0
T. Tsonev
Telerik team
answered on 12 Mar 2010, 09:59 AM
Hi Fabian,

You're right - I didn't consider that overriding these methods will still close the form. Back to square one, then.

I think the best place to put the validator code is in the save button click handler:

<script type="text/javascript">
 
    (function() {
        var oldFunc = Telerik.Web.UI.InlineTemplate.prototype._saveClicked;
        Telerik.Web.UI.InlineTemplate.prototype._saveClicked = function (e)
        {
            var subjectTextBox = $get('<%= RadScheduler1.ClientID %>' + '_SubjectTextBox');
            if (subjectTextBox && subjectTextBox.value == "")
            {
                // Cancel the event to prevent the browser from navigating
                $telerik.cancelRawEvent(e);
                return false;
            }
         
            oldFunc.call(this, e);
        }
    })();
 
</script>

We'll definitely consider adding a public event for implementing such validation in a more 'civilized' manner. I hope this helps.

Best wishes,
Tsvetomir Tsonev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fabian Gehri
Top achievements
Rank 1
answered on 12 Mar 2010, 05:27 PM
Hi Tsvetomir,

thanks for the updated code. I would like to implement it like this, but unfortunately I am not using inline form but the advanced insert/update form.

Do I have to override theTelerik.Web.UI.InlineTemplate.prototype._saveClicked anyway or is there a different function for the advanced form? (I couldn't find anything like Telerik.Web.UI.AdvancedTemplate)

How can I find the Resource dropdowns? $get('<%= RadScheduler1.ClientID %>' + '_SubjectTextBox')is nice but with the Q1 2010 release the subject is now validated automatically but I still need to validate the resources.

Thanks a lot for your continual support!

Fabian
0
T. Tsonev
Telerik team
answered on 17 Mar 2010, 05:22 PM
Hello Fabian,

Indeed, saveClicked is the place to validate for resources. The easiest way to do it is to check for the resources after _saveResources has been called:

this._saveResources(apt);
 
if (apt.get_resources().getResourceByType("User") == null)
{
    // Show error message
    return;
}      
 
this._saveAttributes(apt);

Hope this helps.

Regards,
Tsvetomir Tsonev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Yves
Top achievements
Rank 1
answered on 12 Apr 2010, 01:58 PM
Hi Tsvetomir,

since Fabian is away for half a year, i'm working on his projects.
the solution you provided did not work for me since this functions is never called.
we are using the Q1 2010 build.

 

 

(function() {   
    var oldFunc = Telerik.Web.UI.InlineTemplate.prototype._saveClicked;   
   
    Telerik.Web.UI.InlineTemplate.prototype._saveClicked = function(e) {   
         alert('this should be called');   
    }   
})();  
 


best wishes

Yves

 

0
T. Tsonev
Telerik team
answered on 15 Apr 2010, 04:57 PM
Hello Yves,

Please, accept my apologies for the late reply.

Fabian mentioned that you were using the advanced form, but I must have missed that. In this case you need to change the code to:

(function() {
    var oldFunc = Telerik.Web.UI.Scheduling.AdvancedTemplate.prototype._saveClicked;
    Telerik.Web.UI.Scheduling.AdvancedTemplate.prototype._saveClicked = function (e)
    {
        var calendarComboBox = $find(this._templateId + "_Res" + "Calendar");
        if (calendarComboBox && calendarComboBox.get_value() == "NULL")
        {
            // Cancel the event to prevent the browser from navigating
            $telerik.cancelRawEvent(e);
            return false;
        }
      
        oldFunc.call(this, e);
    }
})();

Change the resource name(s) to match yours. I hope this helps.

Sincerely yours,
Tsvetomir Tsonev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Yves
Top achievements
Rank 1
answered on 16 Apr 2010, 05:19 PM
Dear Tsvetomir



thanks you very much for the fast reply. The windows stays open now.
my (hopefully) last question: how do i get the selected resource-value ?

from the following line i get a encrypted code like " /wECAQ== "

calendarComboBox.get_value() 

Best wishes

Yves

0
Yves
Top achievements
Rank 1
answered on 16 Apr 2010, 05:24 PM
Dear Tsvetomir

Nevermind.. i found the answer already: get_text()

:)
0
Yves
Top achievements
Rank 1
answered on 08 Jul 2010, 11:53 AM
Dear Tsvetomir

i have another problem with the current solution. i changed your code to the following

(function() {
            var oldFunc = Telerik.Web.UI.Scheduling.AdvancedTemplate.prototype._saveClicked;
            Telerik.Web.UI.Scheduling.AdvancedTemplate.prototype._saveClicked = function(e) {
                var category = $find(this._templateId + "_ResCategory");
                var participant = $find(this._templateId + "_ResParticipant");
 
                if (!isValid(category, participant, null)) {
                    $telerik.cancelRawEvent(e);
                    return false;
                }
 
                oldFunc.call(this, e);
            }
        })();

On Server-Side i fill the participant resource with data like:
resources.Add(new Resource(resourceType, participant.ID + "," + participant.Data, participant.Name));

In tha javascript-function i would like to access the resource-data for validation purposes, like (marked with DUMMY CODE):

(function() {
            var oldFunc = Telerik.Web.UI.Scheduling.AdvancedTemplate.prototype._saveClicked;
            Telerik.Web.UI.Scheduling.AdvancedTemplate.prototype._saveClicked = function(e) {
                var category = $find(this._templateId + "_ResCategory");
                var participant = $find(this._templateId + "_ResParticipant");
 
                // DUMMY CODE
                var selectedParticipantsData = participant.selected.resource_data;
  
                if (!isValid(category, participant, null)) {
                    $telerik.cancelRawEvent(e);
                    return false;
                }
  
                oldFunc.call(this, e);
            }
        })();

is this possible?

thanks for the reply
0
T. Tsonev
Telerik team
answered on 14 Jul 2010, 01:51 PM
Hello Yves,

I recommend you to use resource attributes to associate additional data to the resources. For example:

var res = new Resource(resourceType, participant.ID, participant.Name);
res.Attributes.Add("Data", participant.Data);

Then you can access them on the client:

var resources = this._appointment.get_resources();
var participant = resources.getResourceByType("Participant");
if (participant)
{
    var selectedParticipantsData = participant.get_attributes().getAttribute("Data");
}

I hope this helps.

Sincerely yours,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yves
Top achievements
Rank 1
answered on 15 Jul 2010, 10:04 AM
Dear Tsvetomir

This doesnt work for me. Before we hooked into the _saveClicked function this worked. Maybe it has something to do with that function?

followed you find the code i'm using.
Server-Side:

public class CoachSchedulerProvider : SchedulerProviderBase
....
....
public override IEnumerable<Resource> GetResourcesByType(RadScheduler owner, string resourceType)
        {
            List<Resource> resources = new List<Resource>();
             
                    if (_coach == null)
                    {
                        Guid uid = new Guid(SessionHandler.Get(HttpContext.Current.Request.Cookies, "userid"));
                        _coach = new Coach(uid);
                    }
                    // add all active participants of this coach (also those without any budget left,
                    // but not those who passed the 2 years or don't have a total budget)
                    foreach (Participant participant in _coach.getParticipants().Where(par => par.Status == STATUS.active && par.HasTimeLeft && par.HasBudgetTotal))
                    {
                        // add job status to the resource key
                        resources.Add(new Resource(resourceType, participant.ID + "," + (participant.HasJob ? 1 : 0), participant.Name));
                    }
            return resources;
        }
....
....
}

Client-Side:
(function() {
            var oldFunc = Telerik.Web.UI.Scheduling.AdvancedTemplate.prototype._saveClicked;
            Telerik.Web.UI.Scheduling.AdvancedTemplate.prototype._saveClicked = function(e) {
                //var category = $find(this._templateId + "_ResCategory");
                //var participant = $find(this._templateId + "_ResParticipant");
 
                var tmpResources = this._appointment.get_resources();
                alert(tmpResources.get_count());
 
oldFunc.call(this, e);
            }
        })();

The alert return 0 always.

Best Regards

Yves
0
T. Tsonev
Telerik team
answered on 21 Jul 2010, 12:03 PM
Hello Yves,

My mistake here - we should read the resources from the form before looking for them:

this._saveResources(this._appointment);
var tmpResources = this._appointment.get_resources();

The code I've sent previously is indeed meant to run in the  _saveClicked function override.

I hope this helps.

Kind regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yves
Top achievements
Rank 1
answered on 21 Jul 2010, 06:22 PM
Dear Tsvetomir

Hopefully my last question about this topic ;-)

I have access to the resource now!

then i tried your version with adding attributes on the server side.
i cannot read the attributes in javascripot. Is it possible that i have to load them specifically in a similar way as you load the resources?
this._saveResources(this._appointment);

is there a load method for attributes, which i have to call first?

Regards

Yves
0
T. Tsonev
Telerik team
answered on 27 Jul 2010, 03:47 PM
Hello Yves,

We're still talking about attributes associated with resources, right? You should be accessing them like this:

this._saveResources(this._appointment);
var tmpResources = this._appointment.get_resources();


var participant = tmpResources.getResourceByType("Participant");
if (participant)
{
    var selectedParticipantsData = participant.get_attributes().getAttribute("Data");
}

The resources populated by _saveResources should contain all attributes associated with them.

Best wishes,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Olle
Top achievements
Rank 1
answered on 27 Dec 2012, 12:52 PM
Hi!

If I want to do the same but from the standard insert-form and from the standard update-form, how do i set the handlers to _saveClicked then?

(I just want to check that i number from a certain serie always exists somewhere in the text)

/Olle
0
Boyan Dimitrov
Telerik team
answered on 02 Jan 2013, 05:26 PM
Hello Olle,

The code snippet below would prevent inserting an appointment if subject field is empty. Of course you are free to modify the condition in order to fit your requirement. The following sample code will work fine with the inline insert and edit forms.
//JavaScript
<script type="text/javascript">
    (function () {
        var oldFunc = Telerik.Web.UI.InlineTemplate.prototype._saveClicked;
        Telerik.Web.UI.InlineTemplate.prototype._saveClicked = function (e) {
            var subjectTextBox = $get('<%= RadScheduler1.ClientID %>' + '_SubjectTextBox');
            if (subjectTextBox && subjectTextBox.value == "") {
                // Cancel the event to prevent the browser from navigating
                $telerik.cancelRawEvent(e);
                return false;
            }
 
            oldFunc.call(this, e);
        }
    })();
</script>


Regards,
Boyan Dimitrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Scheduler
Asked by
Fabian Gehri
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Fabian Gehri
Top achievements
Rank 1
Yves
Top achievements
Rank 1
Olle
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or