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
, options
)
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');
33 this.id
= this.create(title
, msg
, options
);
36 $.extend($.ajatus
.elements
.dialog
.prototype, {
37 create: function(title
, msg
, options
)
40 if (this.options
.closable
!= undefined) {
41 closable
= this.options
.closable
;
44 var id
= this._generate_id();
45 var dialog
= this._create_dialog_structure(id
, closable
);
47 if (typeof title
!= 'undefined') {
48 $('.jqmdTC',dialog
).html(title
);
50 if (typeof msg
!= 'undefined') {
51 $('.jqmdMSG',dialog
).html(msg
);
54 this.holder
.html(dialog
);
56 var content_target
= $('.jqmdMSG',dialog
);
58 var options
= $.extend({
59 target
: content_target
,
61 content_target
.html('');
65 }, this.options
, options
);
67 $('#' + id
).jqm(options
);
72 set_content: function(content
) {
73 $('#' + this.id
+ ' .jqmdMSG').html(content
);
76 append_content: function(content
)
78 $('#' + this.id
+ ' .jqmdMSG').append(content
);
81 prepend_content: function(content
)
83 $('#' + this.id
+ ' .jqmdMSG').prepend(content
);
88 $('#' + this.id
).jqmShow();
93 $('#' + this.id
).jqmHide();
98 $('#' + this.id
).jqmHide();
99 $('#' + this.id
).remove();
102 _create_dialog_structure: function(id
, closable
)
104 var body
= $('<div />')
106 .addClass('jqmDialog')
108 .css({width
: 300, height
: 450});
110 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>');
112 if ( typeof closable
== 'undefined'
113 || closable
!= false)
115 frame
.append('<input type="image" src="' + $.ajatus
.preferences
.client
.theme_url
+ 'css/jquery/plugins/dialog/close.gif" class="jqmdX jqmClose" />');
123 _generate_id: function()
125 return "ajatus_dialog_" + $.ajatus
.utils
.generate_id();
132 $.ajatus
.elements
.messages
= {
137 $.extend($.ajatus
.elements
.messages
, {
138 create: function(title
, message
, options
)
140 if (typeof options
== 'undefined') {
146 if (typeof options
.type
== 'undefined') {
147 options
.type
= 'notification';
149 if (typeof options
.closable
== 'undefined') {
150 options
.closable
= true;
152 options
.holder
= $.ajatus
.elements
.messages
.holder
;
153 var msg
= new $.ajatus
.elements
.message(title
, message
, options
);
155 $.ajatus
.elements
.messages
.msgs
.push(msg
);
158 && options
.visible
> 0)
164 timed
: (options
.visible
* 1000)
166 var watcher
= new $.ajatus
.events
.watcher(watcher_opts
);
167 watcher
.element
.bind('on_stop', function(e
, watcher_id
){
168 msg
.fade('out', true);
174 static: function(title
, message
, options
)
176 var msg
= new $.ajatus
.elements
.message(title
, message
, options
);
179 remove: function(msg_id
)
181 $.ajatus
.elements
.messages
.msgs
= $.grep($.ajatus
.elements
.messages
.msgs
, function(n
,i
){
182 if (n
.id
== msg_id
) {
192 $.ajatus
.elements
.messages
.msgs
= [];
193 $.ajatus
.elements
.messages
.holder
.html('');
197 var date
= new Date();
198 var id
= 'msg_' + date
.getTime();
201 set_holder: function(holder
)
203 if (typeof holder
== 'undefined') {
204 var holder
= $('#system_messages', $.ajatus
.application_element
);
206 $.ajatus
.elements
.messages
.holder
= holder
;
210 $.ajatus
.elements
.message = function(title
, msg
, options
)
212 this.options
= $.extend({
219 this.holder
= this.options
.holder
;
220 this.body_div
= null;
223 this.holder
= $('<div />');
224 this.holder
.appendTo($.ajatus
.application_content_area
);
227 this.id
= this.create(title
, msg
);
230 $.extend($.ajatus
.elements
.message
.prototype, {
231 create: function(title
, msg
) {
232 var id
= $.ajatus
.elements
.messages
.gen_id();
233 this.body_div
= jQuery('<div class="ajatus_elements_message" />').attr({
235 }).addClass(this.options
.type
).hide();
236 this.body_div
.appendTo(this.holder
);
238 if (this.options
.closable
) {
240 var close_handle
= jQuery('<div class="close_handle" />')
241 close_handle
.appendTo(this.body_div
)
242 close_handle
.bind('click', function(){
243 self
.fade('out', true);
247 var title_item
= jQuery('<h2 />').attr('class', 'title').html(title
);
248 title_item
.appendTo(this.body_div
);
250 var msg_item
= jQuery('<div />').attr('class', 'message').html(msg
);
251 msg_item
.appendTo(this.body_div
);
253 if (this.options
.auto_show
) {
261 //this.body_div.show();
265 //this.body_div.hide();
267 fade: function(direction
, destroy
) {
269 if (direction
== 'out') {
270 this.body_div
.fadeOut('slow', function(){
276 this.body_div
.fadeIn('normal', function(){
281 this.body_div
.remove();
283 destroy: function() {
284 $.ajatus
.elements
.messages
.remove(this.id
);
286 bind_in_content: function(action
, selector
, func
) {
287 $(selector
, this.body_div
).bind(action
, func
);