1 /*! 2 * This file is part of Aloha Editor Project http://aloha-editor.org 3 * Copyright � 2010-2011 Gentics Software GmbH, aloha@gentics.com 4 * Contributors http://aloha-editor.org/contribution.php 5 * Licensed unter the terms of http://www.aloha-editor.org/license.html 6 *//* 7 * Aloha Editor is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU Affero General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version.* 11 * 12 * Aloha Editor is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU Affero General Public License for more details. 16 * 17 * You should have received a copy of the GNU Affero General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 define( [ 22 'aloha/jquery', 23 'aloha/ext', 24 'aloha/repositorymanager', 25 'aloha/console', 26 'i18n!aloha/nls/i18n' 27 ], function ( jQuery, Ext, RepositoryManager, console ) { 28 'use strict'; 29 30 Ext.data.AlohaProxy = function () { 31 // Must define a dummy api with "read" action to satisfy 32 // Ext.data.Api#prepare *before* calling super 33 var api = {}; 34 api[ Ext.data.Api.actions.read ] = true; 35 Ext.data.AlohaProxy.superclass.constructor.call( this, { api: api } ); 36 37 this.params = { 38 queryString : null, 39 objectTypeFilter : null, 40 filter : null, 41 inFolderId : null, 42 orderBy : null, 43 maxItems : null, 44 skipCount : null, 45 renditionFilter : null, 46 repositoryId : null 47 }; 48 }; 49 50 var i18n = Aloha.require( 'i18n!aloha/nls/i18n' ); 51 52 Ext.extend( Ext.data.AlohaProxy, Ext.data.DataProxy, { 53 54 doRequest: function ( action, rs, params, reader, cb, scope, arg ) { 55 jQuery.extend( this.params, params ); 56 57 try { 58 RepositoryManager.query( this.params, function ( items ) { 59 cb.call( scope, reader.readRecords( items ), arg, true ); 60 } ); 61 } catch ( ex ) { 62 console.error( 'Ext.data.AlohaProxy', 63 'An error occured while querying repositories.' ); 64 65 this.fireEvent( 'loadexception', this, null, arg, ex ); 66 this.fireEvent( 'exception', this, 'response', action, arg, null, ex ); 67 68 return false; 69 } 70 }, 71 72 setObjectTypeFilter: function ( otFilter ) { 73 this.params.objectTypeFilter = otFilter; 74 }, 75 76 getObjectTypeFilter: function () { 77 return this.params.objectTypeFilter; 78 }, 79 80 setParams: function ( p ) { 81 jQuery.extend( this.params, p ); 82 } 83 84 } ); 85 86 } ); 87