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 if ( typeof opts != 'undefined'
40 && typeof opts.dialog != 'undefined')
42 this.options.dialog = $.extend({}, this.options.dialog, opts.dialog);
45 this.id = this.create(title, msg, opts);
48 $.extend($.ajatus.elements.dialog.prototype, {
49 create: function(title, msg, options)
52 if ( typeof this.options.closable != 'undefined'
53 && this.options.closable == false)
55 this.options.modal = false;
59 var id = this._generate_id();
60 var dialog = this._create_dialog_structure(id, closable);
62 if (typeof title != 'undefined') {
63 $('.jqmdTC',dialog).html(title);
65 if (typeof msg != 'undefined') {
66 $('.jqmdMSG',dialog).html(msg);
69 this.holder.append(dialog);
71 var content_target = $('.jqmdMSG',dialog);
73 var options = $.extend({
74 target: content_target,
76 content_target.html('');
80 }, this.options, options);
82 $('#' + id).jqm(options);
87 get_dialog: function() {
88 return $('#' + this.id);
91 get_content_holder: function() {
92 return $('#' + this.id + ' .jqmdMSG');
95 set_content: function(content) {
96 $('#' + this.id + ' .jqmdMSG').html(content);
99 append_content: function(content)
101 $('#' + this.id + ' .jqmdMSG').append(content);
104 prepend_content: function(content)
106 $('#' + this.id + ' .jqmdMSG').prepend(content);
111 $('#' + this.id).jqmShow();
116 $('#' + this.id).jqmHide();
121 $('#' + this.id).jqmHide();
122 $('#' + this.id).remove();
125 _create_dialog_structure: function(id, closable)
127 var body = $('<div />')
129 .addClass('jqmDialog')
131 .css({width: this.options.dialog.width+"px", height: this.options.dialog.height+"px"});
133 if (this.options.dialog.nested) {
134 body.addClass('jqmdAbove');
137 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>');
139 $('.jqmdBC', frame).css({
140 height: this.options.dialog.height - 70 + "px"
143 if ( typeof closable == 'undefined'
146 frame.append('<input type="image" src="' + $.ajatus.preferences.client.theme_url + 'css/jquery/plugins/dialog/close.gif" class="jqmdX jqmClose" />');
154 _generate_id: function()
156 return "ajatus_dialog_" + $.ajatus.utils.generate_id();
163 $.ajatus.elements.messages = {
168 $.extend($.ajatus.elements.messages, {
169 create: function(title, message, options)
171 if (typeof options == 'undefined') {
177 if (typeof options.type == 'undefined') {
178 options.type = 'notification';
180 if (typeof options.closable == 'undefined') {
181 options.closable = true;
183 options.holder = $.ajatus.elements.messages.holder;
184 var msg = new $.ajatus.elements.message(title, message, options);
186 $.ajatus.elements.messages.msgs.push(msg);
189 && options.visible > 0)
195 timed: (options.visible * 1000)
197 var watcher = new $.ajatus.events.watcher(watcher_opts);
198 watcher.element.bind('on_stop', function(e, watcher_id){
199 msg.fade('out', true);
205 static: function(title, message, options)
207 var msg = new $.ajatus.elements.message(title, message, options);
210 remove: function(msg_id)
212 $.ajatus.elements.messages.msgs = $.grep($.ajatus.elements.messages.msgs, function(n,i){
213 if (n.id == msg_id) {
223 $.ajatus.elements.messages.msgs = [];
224 $.ajatus.elements.messages.holder.html('');
228 var date = new Date();
229 var id = 'msg_' + date.getTime();
232 set_holder: function(holder)
234 if (typeof holder == 'undefined') {
235 var holder = $('#system_messages', $.ajatus.application_element);
237 $.ajatus.elements.messages.holder = holder;
241 $.ajatus.elements.message = function(title, msg, options)
243 this.options = $.extend({
250 this.holder = this.options.holder;
251 this.body_div = null;
254 this.holder = $('<div />');
255 this.holder.appendTo($.ajatus.application_content_area);
258 this.id = this.create(title, msg);
261 $.extend($.ajatus.elements.message.prototype, {
262 create: function(title, msg) {
263 var id = $.ajatus.elements.messages.gen_id();
264 this.body_div = jQuery('<div class="ajatus_elements_message" />').attr({
266 }).addClass(this.options.type).hide();
267 this.body_div.appendTo(this.holder);
269 if (this.options.closable) {
271 var close_handle = jQuery('<div class="close_handle" />')
272 close_handle.appendTo(this.body_div)
273 close_handle.bind('click', function(){
274 self.fade('out', true);
278 var title_item = jQuery('<h2 />').attr('class', 'title').html(title);
279 title_item.appendTo(this.body_div);
281 var msg_item = jQuery('<div />').attr('class', 'message').html(msg);
282 msg_item.appendTo(this.body_div);
284 if (this.options.auto_show) {
292 //this.body_div.show();
296 //this.body_div.hide();
298 fade: function(direction, destroy) {
300 if (direction == 'out') {
301 this.body_div.fadeOut('slow', function(){
307 this.body_div.fadeIn('normal', function(){
312 this.body_div.remove();
314 destroy: function() {
315 $.ajatus.elements.messages.remove(this.id);
317 bind_in_content: function(action, selector, func) {
318 $(selector, this.body_div).bind(action, func);