/* repository.js is part of Aloha Editor project http://aloha-editor.org * * Aloha Editor is a WYSIWYG HTML5 inline editing library and editor. * Copyright (c) 2010-2012 Gentics Software GmbH, Vienna, Austria. * Contributors http://aloha-editor.org/contribution.php * * Aloha Editor is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * Aloha Editor is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * As an additional permission to the GNU GPL version 2, you may distribute * non-source (e.g., minimized or compacted) forms of the Aloha-Editor * source code without the copy of the GNU GPL normally required, * provided you include this license notice and a URL through which * recipients can access the Corresponding Source. */ define([ 'aloha/core', 'util/class', 'aloha/repositorymanager' ], function ( Aloha, Class, RepositoryManager ) { "use strict"; // var // $ = jQuery, // GENTICS = window.GENTICS, // Aloha = window.Aloha, // Class = window.Class; /** * Abstract Repository Class. Implement that class for your own repository. * @namespace Aloha.Repository * @class Repository * @constructor * @param {String} repositoryId unique repository identifier * @param {String} repositoryName (optional) is the displyed name for this Repository instance */ var AbstractRepository = Class.extend({ _constructor: function (repositoryId, repositoryName) { /** * @property repositoryId is the unique Id for this Repository instance */ this.repositoryId = repositoryId; /** * contains the repository's settings object * @property settings {Object} the repository's settings stored in an object */ this.settings = {}; /** * @property repositoryName is the name for this Repository instance */ this.repositoryName = repositoryName || repositoryId; RepositoryManager.register(this); }, /** * Init method of the repository. Called from Aloha Core to initialize this repository * @return void * @hide */ init: function () {}, /** * Searches a repository for object items matching queryString if none found returns null. * The returned object items must be an array of Aloha.Repository.Object *
// simple delicious implementation
Aloha.Repositories.myRepository.query = function (params, callback) {
// make local var of this to use in ajax function
var that = this;
// handle each word as tag
var tags = p.queryString.split(' ');
// if we have a query and no tag matching return
if ( p.queryString && tags.length == 0 ) {
callback.call( that, []);
return;
}
// no handling of objectTypeFilter, filter, inFolderId, etc...
// in real implementation you should handle all parameters
jQuery.ajax({ type: "GET",
dataType: "jsonp",
url: 'http://feeds.delicious.com/v2/json/' + tags.join('+'),
success: function(data) {
var items = [];
// convert data to Aloha objects
for (var i = 0; i < data.length; i++) {
if (typeof data[i] != 'function' ) {
items.push(new Aloha.Repository.Document ({
id: data[i].u,
name: data[i].d,
repositoryId: that.repositoryId,
type: 'website',
url: data[i].u
}));
}
}
callback.call( that, items);
}
});
};
*
* @param {object} params object with properties
* queryString
: String objectTypeFilter
: array (optional) filter
: array (optional) inFolderId
: boolean (optional) inTreeId
: boolean (optional) orderBy
: array (optional) maxItems
: Integer (optional) skipCount
: Integer (optional) renditionFilter
: array (optional) objectTypeFilter
: array (optional) filter
: array (optional) inFolderId
: boolean (optional) orderBy
: array (optional) maxItems
: Integer (optional) skipCount
: Integer (optional) renditionFilter
: array (optional)
Aloha.Repositories.myRepository.makeClean = function (obj) {
obj.removeAttr('data-myRepository-name');
};
* @param {jQuery} obj jQuery object to make clean
* @return void
*/
makeClean: function (obj) {},
/**
* This method will be called when a user chooses an item from a repository and wants
* to insert this item in his content.
* Mark or modify an object as needed by that repository for handling, processing or identification.
* Objects can be any DOM object as A, SPAN, ABBR, etc. or
* special objects such as aloha-aloha_block elements.
* (see http://dev.w3.org/html5/spec/elements.html#embedding-custom-non-visible-data)
*
Aloha.Repositories.myRepository.markObject = function (obj, resourceItem) {
obj.attr('data-myRepository-name').text(resourceItem.name);
};
*
*
* @param obj jQuery target object to which the repositoryItem will be applied
* @param repositoryItem The selected item. A class constructed from Document or Folder.
* @return void
*/
markObject: function (obj, repositoryItem) {},
/**
* Set a template for rendering objects of this repository
* @param {String} template
* @return void
* @method
*/
setTemplate: function (template) {
if (template) {
this.template = template;
} else {
this.template = null;
}
},
/**
* Checks whether the repository has a template
* @return {boolean} true when the repository has a template, false if not
* @method
*/
hasTemplate: function () {
return this.template ? true : false;
},
/**
* Get the parsed template
* @return {Object} parsed template
* @method
*/
getTemplate: function () {
return this.template;
},
/**
* Get the repositoryItem with given id
* @param itemId {String} id of the repository item to fetch
* @param callback {function} callback function
* @return {Aloha.Repository.Object} item with given id
*/
getObjectById: function (itemId, callback) {
return true;
}
});
// expose the AbstractRepository
Aloha.AbstractRepository = AbstractRepository;
return AbstractRepository;
});