/*
 *  Copyright 2015 Anyware Services
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 * The dashboard DAO.
 */
 Ext.define('Ametys.cms.dashboard.DashboardDAO', {
 	singleton: true,
 	
 	/**
 	 * Asks the server to retrieve the tasks.
 	 * @param {Function} callback The callback function called after retrieving the tasks.
 	 */
 	getTasks: function(callback)
 	{
 		Ametys.data.ServerComm.send({
 			plugin: 'dashboard',
 			url: 'tasks.xml',
 			parameters: {},
			priority: Ametys.data.ServerComm.PRIORITY_MAJOR,
			waitMessage: false,
			responseType: 'xml',
			callback: {
				handler: this._getTasksCb,
				scope: this,
				arguments: {
					callback: callback
				}
			}
 		});
 	},
 	
 	/**
 	 * Callback function called after {@link #getTasks} has been processed.
 	 * @param {HTMLElement} response The text response provided by the {@link Ametys.data.ServerComm}
 	 * @param {Object} params The callback parameters passed to the {@link Ametys.data.ServerComm#callMethod} method
 	 * @private
 	 */
 	_getTasksCb: function(response, params)
 	{
 		var callback = params.callback;
 		var result = Ext.dom.Query.selectNode('tasks', response);
 		
 		if (Ext.isFunction(callback))
 		{
 			callback(result);
 		}
 	}
 	
 });