1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by the
7 * Free Software Foundation with the addition of the following permission added
8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * You should have received a copy of the GNU Affero General Public License along with
18 * this program; if not, see http://www.gnu.org/licenses or write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32 * technical reasons, the Appropriate Legal Notices must display the words
33 * "Powered by SugarCRM".
34 ********************************************************************************/
38 SUGAR.tour = function() {
41 init: function(params) {
42 var modals = params.modals;
44 tourModal = $('<div id="'+params.id+'" class="modal"></div>').modal({backdrop: false}).draggable({handle: ".modal-header"});
46 var tourIdSel = "#"+params.id;
50 success: function(data){
51 $(tourIdSel).html(data);
53 $(tourIdSel+'Start a.btn.btn-primary').on("click",function(e){
54 $(tourIdSel+'Start').css("display","none");
55 $(tourIdSel+'End').css("display","block");
56 tourModal.modal("hide");
57 modalArray[0].modal('show');
58 $(modals[0].target).popoverext('show');
60 $(tourIdSel+'Start a.btn').not('.btn-primary').on("click",function(e){
61 $(tourIdSel+'Start').css("display","none");
62 $(tourIdSel+'End').css("display","block");
65 $(tourIdSel+' a.close').on("click",function(e){
66 tourModal.modal("hide");
67 SUGAR.tour.saveUserPref(params.prefUrl);
68 params.onTourFinish();
70 $(tourIdSel+'End a.btn.btn-primary').on("click",function(e){
71 tourModal.modal("hide");
72 SUGAR.tour.saveUserPref(params.prefUrl);
73 params.onTourFinish();
78 $('<div style="position: absolute;" id="tourArrow">arrow</div>');
79 var modalArray = new Array();
81 for(var i=0; i<modals.length; i++) {
82 var modalId = modals[i].target.replace("#","")+"_modal";
83 modalArray[i] = $('<div id="'+modalId+'" class="modal '+params.className+'"></div>').modal({backdrop: false}).draggable({handle: ".modal-header"});
84 // modalArray[i].modal('show');
85 var modalContent = "<div class=\"modal-header\"><a class=\"close\" data-dismiss=\"modal\">×</a><h3>"+modals[i].title+"</h3></div>";
87 modalContent += "<div class=\"modal-body\">"+modals[i].content+"</div>" ;
89 modalContent += footerTemplate(i,modals);
90 $('#'+modalId).html(modalContent);
91 modalArray[i].modal("hide");
94 $(modals[i].target).ready(function(){
97 if (modals[i].placement == "top right") {
99 direction = "down right"
100 } else if (modals[i].placement == "top left") {
102 direction = "down left"
103 } else if(modals[i].placement == "top") {
106 } else if (modals[i].placement == "bottom right") {
107 bounce = "down right";
108 direction = "up right"
109 } else if (modals[i].placement == "bottom left") {
110 bounce = "down left";
111 direction = "up left"
117 $(modals[i].target).popoverext({
121 placement: modals[i].placement,
125 template: '<div class="popover arrow"><div class="pointer ' +direction+'"></div></div>',
127 $('.pointer').css('top','0px');
129 $(".popover .pointer")
130 .effect("custombounce", { times:1000, direction: bounce, distance: 50, gravity: false }, 2000,
133 // $('.pointer').attr('style','');
138 leftOffset: modals[i].leftOffset ? modals[i].leftOffset : 0,
139 topOffset: modals[i].topOffset ? modals[i].topOffset : 0,
144 //empty popover div and insert arrow
145 $(modals[i].target+"Popover").empty().html("arrow");
149 $(window).resize(function() {
152 function centerModal() {
153 $(tourIdSel).css("left",$(window).width()/2 - $(tourIdSel).width()/2);
154 $(tourIdSel).css("margin-top",-$(tourIdSel).height()/2);
157 function nextModal (i) {
160 if(modals.length - 1 != i) {
161 $(modals[i].target).popoverext('hide');
162 $(modals[i+1].target).popoverext('show');
163 modalArray[i].modal('hide');
164 modalArray[i+1].modal('show');
166 $(modals[i].target).popoverext('hide');
167 modalArray[i].modal('hide');
168 tourModal.modal("show");
174 function prevModal (i){
176 $(modals[i].target).popoverext('hide');
177 $(modals[i-1].target).popoverext('show');
178 modalArray[i].modal('hide');
179 modalArray[i-1].modal('show');
183 function skipTour (i) {
184 $(modals[i].target).popoverext('hide');
185 modalArray[i].modal('hide');
186 tourModal.modal("show");
190 function footerTemplate (i,modals) {
191 var content = $('<div></div>')
192 var footer = $("<div class=\"modal-footer\"></div>");
194 var skip = $("<a href=\"#\" class=\"btn btn-invisible\" id=\"skipTour\">"+SUGAR.language.get('app_strings', 'LBL_TOUR_SKIP')+"</a>");
195 var next = $('<a class="btn btn-primary" id="nextModal'+i+'" href="#">'+SUGAR.language.get('app_strings', 'LBL_TOUR_NEXT')+' <i class="icon-play icon-xsm"></i></a>');
196 content.append(footer);
197 footer.append(skip).append(next);
199 var back = $('<a class="btn" href="#" id="prevModal'+i+'">'+SUGAR.language.get('app_strings', 'LBL_TOUR_BACK')+'</a>');
202 $('#nextModal'+i).live("click", function(){
206 $('#prevModal'+i).live("click", function(){
210 $('#skipTour').live("click", function(){
220 return content.html();
230 saveUserPref: function(url) {