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

Custom callback and Error Handling for Destroy in ImageBrowser

1 Answer 117 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Ramoji
Top achievements
Rank 1
Ramoji asked on 17 Jan 2014, 04:57 PM

Hi Team,

I am using ImageBrowser as a part of editor widget in my screen . I need to delete an image only if it is not used by other resources. I wired the destroy to an action that checks whether its in use or not. If its in use I would return a message saying it could not be deleted .I got stuck on how to return this message to destroy and stop it from deleting the image from the library.
As the documentation says the configuration values will be sent to jquery.Ajax() function I tried using the success and error functions in the destroy configuration but could not handle the request. It always shows up as undefined.This is how I configured my imagebrowser.

01.imageBrowser: {
02.           path: "/BroadcastType/",
03.           transport: {
04.                read: {
05.                    url: function () { $(".k-breadcrumbs.k-textbox").css('display', 'none'); return "../ImageBrowser/Read" },
06.                    type: "POST"
07.                },
08.                destroy: {
09.                    url: "../ImageBrowser/Destroy",
10.                    type: "POST" ,
11.                    success:function(){},
12.                   error:function(){}
13.                },
14.                thumbnailUrl: "../ImageBrowser/Thumbnail",
15.                uploadUrl: "../ImageBrowser/Upload",
16.                imageUrl: "../ImageBrowser/Image?name={0}"
17.            }
18.        }
In short,
How to stop image from being destroyed from the library until I get a response from backend?
How to handle any errors while backend execution?
Can we override the callback functions in the destroy configuration or should we deal with them at the transport level?

Any pointer to the right direction will be appreciated .

Thanks,
Ramoji.




1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 21 Jan 2014, 09:10 AM
Hello Ramoji,

Please avoid posting duplicate forum threads and support tickets.

===

The DataSouce transport and its CRUD request types do not have success and error callbacks. The Kendo UI DataSouce itself has an error event, which the ImageBrowser widget uses internally. In your case you can throw an HTTP Exception in the Destroy action method. The ImageBrowser will display the custom error message automatically.

http://msdn.microsoft.com/en-us/library/bazc3hww(v=vs.110).aspx

An alternative, but more complex approach would be to configure the destroy property of the Transport as a custom function, which will allow you to handle the custom request's success and error events:

http://docs.kendoui.com/api/framework/datasource#configuration-transport.destroy


Regards,
Dimo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Editor
Asked by
Ramoji
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or