From 4a2721032e5adb4ad2460befd9af77be4996d2a0 Mon Sep 17 00:00:00 2001 From: ewinslow Date: Mon, 1 Nov 2010 22:11:20 +0000 Subject: Refs #2538: Added some models, inheritance, more bootstrapping code git-svn-id: http://code.elgg.org/elgg/trunk@7183 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/js/classes/ElggEntity.js | 20 ++++++++++++++++++++ engine/js/classes/ElggUser.js | 12 ++---------- engine/js/lib/elgglib.js | 29 +++++++++++++++++------------ engine/js/lib/languages.js | 4 +--- engine/js/tests/ElggLibTest.js | 11 +++++++++++ 5 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 engine/js/classes/ElggEntity.js (limited to 'engine/js') diff --git a/engine/js/classes/ElggEntity.js b/engine/js/classes/ElggEntity.js new file mode 100644 index 000000000..9461a463f --- /dev/null +++ b/engine/js/classes/ElggEntity.js @@ -0,0 +1,20 @@ +/** + * Create a new ElggEntity + * + * @class Represents an ElggEntity + * @property {number} guid + * @property {string} type + * @property {string} subtype + * @property {number} owner_guid + * @property {number} site_guid + * @property {number} container_guid + * @property {number} access_id + * @property {number} time_created + * @property {number} time_updated + * @property {number} last_action + * @property {string} enabled + * + */ +elgg.ElggEntity = function(o) { + $.extend(this, o); +}; \ No newline at end of file diff --git a/engine/js/classes/ElggUser.js b/engine/js/classes/ElggUser.js index dec7431de..8a7a8b7eb 100644 --- a/engine/js/classes/ElggUser.js +++ b/engine/js/classes/ElggUser.js @@ -8,15 +8,7 @@ * @property {string} username */ elgg.ElggUser = function(o) { - //elgg.ElggEntity.call(this, o); - this = o; + elgg.ElggEntity.call(this, o); }; -//elgg.inherit(elgg.ElggUser, elgg.ElggEntity); - -/** - * @return {boolean} Whether the user is an admin - */ -elgg.ElggUser.prototype.isAdmin = function() { - return this.admin === 'yes'; -}; \ No newline at end of file +elgg.inherit(elgg.ElggUser, elgg.ElggEntity); \ No newline at end of file diff --git a/engine/js/lib/elgglib.js b/engine/js/lib/elgglib.js index 28cae8f8f..208c02716 100644 --- a/engine/js/lib/elgglib.js +++ b/engine/js/lib/elgglib.js @@ -92,7 +92,8 @@ elgg.provide = function(pkg) { * @param {Function} parentCtor Parent class. */ elgg.inherit = function(Child, Parent) { - Child.prototype = Parent; + Child.prototype = new Parent(); + Child.prototype.constructor = Child; }; /** @@ -130,9 +131,9 @@ elgg.system_messages = function(msgs, delay, type) { delay = 6000; } - var messages_class = 'messages'; + classes = ['elgg_system_message', 'radius8']; if (type == 'error') { - messages_class = 'messages_error'; + classes.push('messages_error'); } //Handle non-arrays @@ -140,16 +141,20 @@ elgg.system_messages = function(msgs, delay, type) { msgs = [msgs]; } - var messages_html = '
' - + '' - + '' - + elgg.echo('systemmessages:dismiss') - + '' - + '' - + '

' + msgs.join('

') + '

' - + '
'; + var messages_html = []; - $(messages_html).appendTo('#elgg_system_messages').show().animate({opacity:'1.0'},delay).fadeOut('slow'); + for (var i in msgs) { + messages_html.push('
' + + '' + + '' + + elgg.echo('systemmessages:dismiss') + + '' + + '' + + '

' + msgs[i] + '

' + + '
'); + } + + $(messages_html.join('')).appendTo('#elgg_system_messages').animate({opacity:'1.0'},delay).fadeOut('slow'); }; /** diff --git a/engine/js/lib/languages.js b/engine/js/lib/languages.js index 7bae74e6b..6ac83f350 100644 --- a/engine/js/lib/languages.js +++ b/engine/js/lib/languages.js @@ -12,9 +12,7 @@ elgg.config.translations.init = function() { elgg.add_translation = function(lang, translations) { elgg.provide('elgg.config.translations.' + lang); - var t = elgg.config.translations; - - t[lang] = $.extend(t[lang], translations); + $.extend(elgg.config.translations[lang], translations); } /** diff --git a/engine/js/tests/ElggLibTest.js b/engine/js/tests/ElggLibTest.js index d5474c605..920296408 100644 --- a/engine/js/tests/ElggLibTest.js +++ b/engine/js/tests/ElggLibTest.js @@ -33,6 +33,17 @@ ElggLibTest.prototype.testRequire = function() { assertNoException(function(){ elgg.require('elgg.security'); }); }; +ElggLibTest.prototype.testInherit = function() { + function Base() {} + function Child() {} + + elgg.inherit(Child, Base); + + + assertInstanceOf(Base, new Child()); + assertEquals(Child, Child.prototype.constructor); +}; + ElggLibTest.prototype.testExtendUrl = function() { var url; elgg.config.wwwroot = "http://www.elgg.org/"; -- cgit v1.2.3