4 * Ajatus - Distributed CRM
5 * @requires jQuery v1.2.1
7 * Copyright (c) 2007 Jerry Jalava <jerry.jalava@gmail.com>
8 * Copyright (c) 2007 Nemein Oy <http://nemein.com>
9 * Website: http://ajatus.info
10 * Licensed under the GPL license
11 * http://www.gnu.org/licenses/gpl.html
16 $.ajatus
= $.ajatus
|| {};
17 $.ajatus
.elements
= $.ajatus
.elements
|| {};
22 $.ajatus
.elements
.dialog = function(title
, msg
, opts
)
24 $.ajatus
.layout
.styles
.load($.ajatus
.preferences
.client
.theme_url
+ 'css/jquery/plugins/jqModal.css');
25 $.ajatus
.layout
.styles
.load($.ajatus
.preferences
.client
.theme_url
+ 'css/jquery/plugins/dialog/dialog.css');
27 this.holder
= $('#dynamic-elements');
39 this.options
= $.ajatus
.utils
.merge_configs(this.options
, opts
);
41 this.id
= this.create(title
, msg
, opts
);
44 $.extend($.ajatus
.elements
.dialog
.prototype, {
45 create: function(title
, msg
, options
)
48 if ( typeof this.options
.closable
!= 'undefined'
49 && this.options
.closable
== false)
51 this.options
.modal
= false;
55 var id
= this._generate_id();
56 var dialog
= this._create_dialog_structure(id
, closable
);
58 if (typeof title
!= 'undefined') {
59 $('.jqmdTC',dialog
).html(title
);
61 if (typeof msg
!= 'undefined') {
62 $('.jqmdMSG',dialog
).html(msg
);
65 this.holder
.append(dialog
);
67 var content_target
= $('.jqmdMSG',dialog
);
69 var options
= $.extend({
70 target
: content_target
,
72 content_target
.html('');
76 }, this.options
, options
);
78 $('#' + id
).jqm(options
);
83 get_dialog: function() {
84 return $('#' + this.id
);
87 get_content_holder: function() {
88 return $('#' + this.id
+ ' .jqmdMSG');
91 set_content: function(content
) {
92 $('#' + this.id
+ ' .jqmdMSG').html(content
);
95 append_content: function(content
)
97 $('#' + this.id
+ ' .jqmdMSG').append(content
);
100 prepend_content: function(content
)
102 $('#' + this.id
+ ' .jqmdMSG').prepend(content
);
107 $('#' + this.id
).jqmShow();
112 $('#' + this.id
).jqmHide();
117 $('#' + this.id
).jqmHide();
118 $('#' + this.id
).remove();
121 _create_dialog_structure: function(id
, closable
)
123 var body
= $('<div />')
125 .addClass('jqmDialog')
128 width
: this.options
.dialog
.width
+"px",
129 height
: this.options
.dialog
.height
+"px"
132 if (this.options
.dialog
.nested
) {
133 body
.addClass('jqmdAbove');
136 var frame
= $('<div class="jqmdTL"><div class="jqmdTR"><div class="jqmdTC"></div></div></div><div class="jqmdBL"><div class="jqmdBR"><div class="jqmdBC"><div class="jqmdMSG"></div></div></div></div>');
138 $('.jqmdBC', frame
).css({
139 height
: this.options
.dialog
.height
- 70 + "px"
142 if ( typeof closable
== 'undefined'
145 frame
.append('<input type="image" src="' + $.ajatus
.preferences
.client
.theme_url
+ 'css/jquery/plugins/dialog/close.gif" class="jqmdX jqmClose" />');
153 _generate_id: function()
155 return "ajatus_dialog_" + $.ajatus
.utils
.generate_id();
162 $.ajatus
.elements
.messages
= {
167 $.extend($.ajatus
.elements
.messages
, {
168 create: function(title
, message
, options
)
170 if (typeof options
== 'undefined') {
176 if (typeof options
.type
== 'undefined') {
177 options
.type
= 'notification';
179 if (typeof options
.closable
== 'undefined') {
180 options
.closable
= true;
182 options
.holder
= $.ajatus
.elements
.messages
.holder
;
183 var msg
= new $.ajatus
.elements
.message(title
, message
, options
);
185 $.ajatus
.elements
.messages
.msgs
.push(msg
);
188 && options
.visible
> 0)
194 timed
: (options
.visible
* 1000)
196 var watcher
= new $.ajatus
.events
.watcher(watcher_opts
);
197 watcher
.element
.bind('on_stop', function(e
, watcher_id
){
198 msg
.fade('out', true);
204 static: function(title
, message
, options
)
206 var msg
= new $.ajatus
.elements
.message(title
, message
, options
);
209 remove: function(msg_id
)
211 $.ajatus
.elements
.messages
.msgs
= $.grep($.ajatus
.elements
.messages
.msgs
, function(n
,i
){
212 if (n
.id
== msg_id
) {
222 $.ajatus
.elements
.messages
.msgs
= [];
223 $.ajatus
.elements
.messages
.holder
.html('');
227 var date
= new Date();
228 var id
= 'msg_' + date
.getTime();
231 set_holder: function(holder
)
233 if (typeof holder
== 'undefined') {
234 var holder
= $('#system_messages', $.ajatus
.application_element
);
236 $.ajatus
.elements
.messages
.holder
= holder
;
240 $.ajatus
.elements
.message = function(title
, msg
, options
)
242 this.options
= $.extend({
249 this.holder
= this.options
.holder
;
250 this.body_div
= null;
253 this.holder
= $('<div />');
254 this.holder
.appendTo($.ajatus
.application_content_area
);
257 this.id
= this.create(title
, msg
);
260 $.extend($.ajatus
.elements
.message
.prototype, {
261 create: function(title
, msg
) {
262 var id
= $.ajatus
.elements
.messages
.gen_id();
263 this.body_div
= jQuery('<div class="ajatus_elements_message" />').attr({
265 }).addClass(this.options
.type
).hide();
266 this.body_div
.appendTo(this.holder
);
268 if (this.options
.closable
) {
270 var close_handle
= jQuery('<div class="close_handle" />')
271 close_handle
.appendTo(this.body_div
)
272 close_handle
.bind('click', function(){
273 self
.fade('out', true);
277 var title_item
= jQuery('<h2 />').attr('class', 'title').html(title
);
278 title_item
.appendTo(this.body_div
);
280 var msg_item
= jQuery('<div />').attr('class', 'message').html(msg
);
281 msg_item
.appendTo(this.body_div
);
283 if (this.options
.auto_show
) {
291 //this.body_div.show();
295 //this.body_div.hide();
297 fade: function(direction
, destroy
) {
299 if (direction
== 'out') {
300 this.body_div
.fadeOut('slow', function(){
306 this.body_div
.fadeIn('normal', function(){
311 this.body_div
.remove();
313 destroy: function() {
314 $.ajatus
.elements
.messages
.remove(this.id
);
316 bind_in_content: function(action
, selector
, func
) {
317 $(selector
, this.body_div
).bind(action
, func
);
321 $.ajatus
.elements
.indicator = function(label
, options
) {
322 this.options
= $.extend({
325 this.body_div
= null;
327 this.label
= label
|| $.ajatus
.i10n
.get('Loading');
329 this.id
= this.create();
332 $.extend($.ajatus
.elements
.indicator
.prototype, {
334 var id
= this._gen_id();
336 this.body_div
= jQuery('<div class="ajatus_elements_indicator" />').attr({
339 this.body_div
.appendTo($.ajatus
.application_dynamic_elements
);
341 if (this.label
!= '') {
342 var label_item
= jQuery('<div />').attr('class', 'label').html(this.label
);
343 label_item
.appendTo(this.body_div
);
346 // var indicator = jQuery('<div />').attr('class', 'loader');
347 // indicator.appendTo(this.body_div);
349 if (this.options
.auto_show
) {
356 this.body_div
.show();
359 this.body_div
.hide();
363 this.body_div
.remove();
367 var date
= new Date();
368 var id
= 'indicator_' + date
.getTime();