include request info on transport exception, sanity check tag parser results
[ajatus.git] / js / ajatus.elements.js
blobead79a01c8b398e0e59523cdb6e2cbd2d520bd27
1 /*
2 * This file is part of
4 * Ajatus - Distributed CRM
5 * @requires jQuery v1.2.1
6 *
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
15 (function($){
16 $.ajatus = $.ajatus || {};
17 $.ajatus.elements = $.ajatus.elements || {};
19 /**
20 * Ajatus Dialog
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');
28 this.options = {
29 modal: true,
30 overlay: 30,
31 closable: true,
32 dialog: {
33 width: 300,
34 height: 200,
35 nested: false
39 this.options = $.ajatus.utils.merge_configs(this.options, opts);
41 this.id = this.create(title, msg, opts);
42 return this;
44 $.extend($.ajatus.elements.dialog.prototype, {
45 create: function(title, msg, options)
47 var closable = true;
48 if ( typeof this.options.closable != 'undefined'
49 && this.options.closable == false)
51 this.options.modal = false;
52 closable = 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,
71 onHide: function(h) {
72 content_target.html('');
73 h.o.remove();
74 h.w.fadeOut(300);
76 }, this.options, options);
78 $('#' + id).jqm(options);
80 return id;
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);
105 open: function()
107 $('#' + this.id).jqmShow();
110 close: function()
112 $('#' + this.id).jqmHide();
115 destroy: function()
117 $('#' + this.id).jqmHide();
118 $('#' + this.id).remove();
121 _create_dialog_structure: function(id, closable)
123 var body = $('<div />')
124 .attr('id', id)
125 .addClass('jqmDialog')
126 .hide()
127 .css({
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'
143 && closable)
145 frame.append('<input type="image" src="' + $.ajatus.preferences.client.theme_url + 'css/jquery/plugins/dialog/close.gif" class="jqmdX jqmClose" />');
148 body.html(frame);
150 return body;
153 _generate_id: function()
155 return "ajatus_dialog_" + $.ajatus.utils.generate_id();
159 * Ajatus Dialog ends
162 $.ajatus.elements.messages = {
163 msgs: [],
164 watchers: [],
165 holder: null
167 $.extend($.ajatus.elements.messages, {
168 create: function(title, message, options)
170 if (typeof options == 'undefined') {
171 options = {
172 closable: true,
173 visible: 5
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);
187 if ( options.visible
188 && options.visible > 0)
190 var watcher_opts = {
191 auto_start: true,
192 safety_runs: 0,
193 interval: 200,
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);
202 return msg;
204 static: function(title, message, options)
206 var msg = new $.ajatus.elements.message(title, message, options);
207 return msg;
209 remove: function(msg_id)
211 $.ajatus.elements.messages.msgs = $.grep($.ajatus.elements.messages.msgs, function(n,i){
212 if (n.id == msg_id) {
213 n.remove();
214 return false;
215 } else {
216 return true;
220 clear: function()
222 $.ajatus.elements.messages.msgs = [];
223 $.ajatus.elements.messages.holder.html('');
225 gen_id: function()
227 var date = new Date();
228 var id = 'msg_' + date.getTime();
229 return id;
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({
243 auto_show: true,
244 disappear: false,
245 holder: false,
246 closable: false,
247 type: 'static'
248 }, options || {});
249 this.holder = this.options.holder;
250 this.body_div = null;
252 if (! this.holder) {
253 this.holder = $('<div />');
254 this.holder.appendTo($.ajatus.application_content_area);
257 this.id = this.create(title, msg);
258 return this;
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({
264 id: id
265 }).addClass(this.options.type).hide();
266 this.body_div.appendTo(this.holder);
268 if (this.options.closable) {
269 var self = this;
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) {
284 this.show();
287 return id;
289 show: function() {
290 this.fade('in');
291 //this.body_div.show();
293 hide: function() {
294 this.fade('out');
295 //this.body_div.hide();
297 fade: function(direction, destroy) {
298 var self = this;
299 if (direction == 'out') {
300 this.body_div.fadeOut('slow', function(){
301 if (destroy) {
302 self.destroy();
305 } else {
306 this.body_div.fadeIn('normal', function(){
310 remove: 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({
323 auto_show: false
324 }, options || {});
325 this.body_div = null;
327 this.label = label || $.ajatus.i10n.get('Loading');
329 this.id = this.create();
330 return this;
332 $.extend($.ajatus.elements.indicator.prototype, {
333 create: function() {
334 var id = this._gen_id();
336 this.body_div = jQuery('<div class="ajatus_elements_indicator" />').attr({
337 id: id
338 }).hide();
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) {
350 this.show();
353 return id;
355 show: function() {
356 this.body_div.show();
358 hide: function() {
359 this.body_div.hide();
361 close: function() {
362 this.hide();
363 this.body_div.remove();
365 _gen_id: function()
367 var date = new Date();
368 var id = 'indicator_' + date.getTime();
369 return id;
373 })(jQuery);