2011-03-26 13:10:41 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2009 Google Inc.
|
2011-07-07 17:59:34 +00:00
|
|
|
*
|
2011-03-26 13:10:41 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-07-07 17:59:34 +00:00
|
|
|
*
|
2011-03-26 13:10:41 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-07-07 17:59:34 +00:00
|
|
|
*
|
2011-03-26 13:10:41 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-07-07 17:59:34 +00:00
|
|
|
var padmodals = (function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
|
2011-07-07 17:59:34 +00:00
|
|
|
/*var clearFeedbackEmail = function() {};
|
2011-03-26 13:10:41 +00:00
|
|
|
function clearFeedback() {
|
|
|
|
clearFeedbackEmail();
|
|
|
|
$("#feedbackbox-message").val('');
|
|
|
|
}
|
|
|
|
|
|
|
|
var sendingFeedback = false;
|
|
|
|
function setSendingFeedback(v) {
|
|
|
|
v = !! v;
|
|
|
|
if (sendingFeedback != v) {
|
|
|
|
sendingFeedback = v;
|
|
|
|
if (v) {
|
|
|
|
$("#feedbackbox-send").css('opacity', 0.75);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#feedbackbox-send").css('opacity', 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
var sendingInvite = false;
|
2011-07-07 17:59:34 +00:00
|
|
|
|
|
|
|
function setSendingInvite(v)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
v = !! v;
|
2011-07-07 17:59:34 +00:00
|
|
|
if (sendingInvite != v)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
sendingInvite = v;
|
2011-07-07 17:59:34 +00:00
|
|
|
if (v)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
$(".sharebox-send").css('opacity', 0.75);
|
|
|
|
}
|
2011-07-07 17:59:34 +00:00
|
|
|
else
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
$("#sharebox-send").css('opacity', 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:59:34 +00:00
|
|
|
var clearShareBoxTo = function()
|
|
|
|
{};
|
|
|
|
|
|
|
|
function clearShareBox()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
clearShareBoxTo();
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = {
|
2011-07-07 17:59:34 +00:00
|
|
|
init: function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
self.initFeedback();
|
|
|
|
self.initShareBox();
|
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
initFeedback: function()
|
|
|
|
{
|
|
|
|
/*var emailField = $("#feedbackbox-email");
|
2011-03-26 13:10:41 +00:00
|
|
|
clearFeedbackEmail =
|
|
|
|
padutils.makeFieldLabeledWhenEmpty(emailField, '(your email address)').clear;
|
|
|
|
clearFeedback();*/
|
|
|
|
|
2011-07-07 17:59:34 +00:00
|
|
|
$("#feedbackbox-hide").click(function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
self.hideModal();
|
|
|
|
});
|
2011-07-07 17:59:34 +00:00
|
|
|
/*$("#feedbackbox-send").click(function() {
|
2011-03-26 13:10:41 +00:00
|
|
|
self.sendFeedbackEmail();
|
|
|
|
});*/
|
|
|
|
|
2011-07-07 17:59:34 +00:00
|
|
|
$("#feedbackbutton").click(function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
self.showFeedback();
|
|
|
|
});
|
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
initShareBox: function()
|
|
|
|
{
|
|
|
|
$("#sharebutton").click(function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
self.showShareBox();
|
|
|
|
});
|
2011-07-07 17:59:34 +00:00
|
|
|
$("#sharebox-hide").click(function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
self.hideModal();
|
|
|
|
});
|
2011-07-07 17:59:34 +00:00
|
|
|
$("#sharebox-send").click(function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
self.sendInvite();
|
|
|
|
});
|
|
|
|
|
2011-07-07 17:59:34 +00:00
|
|
|
$("#sharebox-url").click(function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
$("#sharebox-url").focus().select();
|
|
|
|
});
|
|
|
|
|
2011-07-07 17:59:34 +00:00
|
|
|
clearShareBoxTo = padutils.makeFieldLabeledWhenEmpty($("#sharebox-to"), "(email addresses)").clear;
|
2011-03-26 13:10:41 +00:00
|
|
|
clearShareBox();
|
|
|
|
|
|
|
|
$("#sharebox-subject").val(self.getDefaultShareBoxSubjectForName(pad.getUserName()));
|
|
|
|
$("#sharebox-message").val(self.getDefaultShareBoxMessageForName(pad.getUserName()));
|
|
|
|
|
2011-07-07 17:59:34 +00:00
|
|
|
$("#sharebox-stripe .setsecurity").click(function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
self.hideModal();
|
|
|
|
paddocbar.setShownPanel('security');
|
|
|
|
});
|
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
getDefaultShareBoxMessageForName: function(name)
|
|
|
|
{
|
|
|
|
return (name || "Somebody") + " has shared an EtherPad document with you." + "\n\n" + "View it here:\n\n" + padutils.escapeHtml($(".sharebox-url").val() + "\n");
|
2011-03-26 13:10:41 +00:00
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
getDefaultShareBoxSubjectForName: function(name)
|
|
|
|
{
|
|
|
|
return (name || "Somebody") + " invited you to an EtherPad document";
|
2011-03-26 13:10:41 +00:00
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
relayoutWithBottom: function(px)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
$("#modaloverlay").height(px);
|
2011-07-07 17:59:34 +00:00
|
|
|
$("#sharebox").css('left', Math.floor(($(window).width() - $("#sharebox").outerWidth()) / 2));
|
|
|
|
$("#feedbackbox").css('left', Math.floor(($(window).width() - $("#feedbackbox").outerWidth()) / 2));
|
2011-03-26 13:10:41 +00:00
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
showFeedback: function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
self.showModal("#feedbackbox");
|
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
showShareBox: function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
// when showing the dialog, if it still says "Somebody" invited you
|
|
|
|
// then we fill in the updated username if there is one;
|
|
|
|
// otherwise, we don't touch it, perhaps the user is happy with it
|
|
|
|
var msgbox = $("#sharebox-message");
|
2011-07-07 17:59:34 +00:00
|
|
|
if (msgbox.val() == self.getDefaultShareBoxMessageForName(null))
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
msgbox.val(self.getDefaultShareBoxMessageForName(pad.getUserName()));
|
|
|
|
}
|
|
|
|
var subjBox = $("#sharebox-subject");
|
2011-07-07 17:59:34 +00:00
|
|
|
if (subjBox.val() == self.getDefaultShareBoxSubjectForName(null))
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
subjBox.val(self.getDefaultShareBoxSubjectForName(pad.getUserName()));
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:59:34 +00:00
|
|
|
if (pad.isPadPublic())
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
$("#sharebox-stripe").get(0).className = 'sharebox-stripe-public';
|
|
|
|
}
|
2011-07-07 17:59:34 +00:00
|
|
|
else
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
$("#sharebox-stripe").get(0).className = 'sharebox-stripe-private';
|
|
|
|
}
|
|
|
|
|
|
|
|
self.showModal("#sharebox", 500);
|
|
|
|
$("#sharebox-url").focus().select();
|
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
showModal: function(modalId, duration)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
$(".modaldialog").hide();
|
2011-07-07 17:59:34 +00:00
|
|
|
$(modalId).show().css(
|
|
|
|
{
|
|
|
|
'opacity': 0
|
|
|
|
}).animate(
|
|
|
|
{
|
|
|
|
'opacity': 1
|
|
|
|
}, duration);
|
|
|
|
$("#modaloverlay").show().css(
|
|
|
|
{
|
|
|
|
'opacity': 0
|
|
|
|
}).animate(
|
|
|
|
{
|
|
|
|
'opacity': 1
|
|
|
|
}, duration);
|
2011-03-26 13:10:41 +00:00
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
hideModal: function(duration)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
padutils.cancelActions('hide-feedbackbox');
|
|
|
|
padutils.cancelActions('hide-sharebox');
|
|
|
|
$("#sharebox-response").hide();
|
2011-07-07 17:59:34 +00:00
|
|
|
$(".modaldialog").animate(
|
|
|
|
{
|
|
|
|
'opacity': 0
|
|
|
|
}, duration, function()
|
|
|
|
{
|
|
|
|
$("#modaloverlay").hide();
|
|
|
|
});
|
|
|
|
$("#modaloverlay").animate(
|
|
|
|
{
|
|
|
|
'opacity': 0
|
|
|
|
}, duration, function()
|
|
|
|
{
|
|
|
|
$("#modaloverlay").hide();
|
|
|
|
});
|
2011-03-26 13:10:41 +00:00
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
hideFeedbackLaterIfNoOtherInteraction: function()
|
|
|
|
{
|
|
|
|
return padutils.getCancellableAction('hide-feedbackbox', function()
|
|
|
|
{
|
|
|
|
self.hideModal();
|
|
|
|
});
|
2011-03-26 13:10:41 +00:00
|
|
|
},
|
2011-07-07 17:59:34 +00:00
|
|
|
hideShareboxLaterIfNoOtherInteraction: function()
|
|
|
|
{
|
|
|
|
return padutils.getCancellableAction('hide-sharebox', function()
|
|
|
|
{
|
|
|
|
self.hideModal();
|
|
|
|
});
|
2011-03-26 13:10:41 +00:00
|
|
|
},
|
|
|
|
/* sendFeedbackEmail: function() {
|
|
|
|
if (sendingFeedback) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var message = $("#feedbackbox-message").val();
|
|
|
|
if (! message) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var email = ($("#feedbackbox-email").hasClass('editempty') ? '' :
|
|
|
|
$("#feedbackbox-email").val());
|
|
|
|
var padId = pad.getPadId();
|
|
|
|
var username = pad.getUserName();
|
|
|
|
setSendingFeedback(true);
|
|
|
|
$("#feedbackbox-response").html("Sending...").get(0).className = '';
|
|
|
|
$("#feedbackbox-response").show();
|
|
|
|
$.ajax({
|
|
|
|
type: 'post',
|
|
|
|
url: '/ep/pad/feedback',
|
|
|
|
data: {
|
|
|
|
feedback: message,
|
|
|
|
padId: padId,
|
|
|
|
username: username,
|
|
|
|
email: email
|
|
|
|
},
|
|
|
|
success: success,
|
|
|
|
error: error
|
|
|
|
});
|
|
|
|
var hideCall = self.hideFeedbackLaterIfNoOtherInteraction();
|
|
|
|
function success(msg) {
|
|
|
|
setSendingFeedback(false);
|
|
|
|
clearFeedback();
|
|
|
|
$("#feedbackbox-response").html("Thanks for your feedback").get(0).className = 'goodresponse';
|
|
|
|
$("#feedbackbox-response").show();
|
|
|
|
window.setTimeout(function() {
|
|
|
|
$("#feedbackbox-response").fadeOut('slow', function() {
|
|
|
|
hideCall();
|
|
|
|
});
|
|
|
|
}, 1500);
|
|
|
|
}
|
|
|
|
function error(e) {
|
|
|
|
setSendingFeedback(false);
|
|
|
|
$("#feedbackbox-response").html("Could not send feedback. Please email us at feedback"+"@"+"etherpad.com instead.").get(0).className = 'badresponse';
|
|
|
|
$("#feedbackbox-response").show();
|
|
|
|
}
|
|
|
|
},*/
|
2011-07-07 17:59:34 +00:00
|
|
|
sendInvite: function()
|
|
|
|
{
|
|
|
|
if (sendingInvite)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-07-07 17:59:34 +00:00
|
|
|
if (!pad.isFullyConnected())
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
displayErrorMessage("Error: Connection to the server is down or flaky.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var message = $("#sharebox-message").val();
|
2011-07-07 17:59:34 +00:00
|
|
|
if (!message)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
displayErrorMessage("Please enter a message body before sending.");
|
|
|
|
return;
|
|
|
|
}
|
2011-07-07 17:59:34 +00:00
|
|
|
var emails = ($("#sharebox-to").hasClass('editempty') ? '' : $("#sharebox-to").val()) || '';
|
2011-03-26 13:10:41 +00:00
|
|
|
// find runs of characters that aren't obviously non-email punctuation
|
|
|
|
var emailArray = emails.match(/[^\s,:;<>\"\'\/\(\)\[\]{}]+/g) || [];
|
2011-07-07 17:59:34 +00:00
|
|
|
if (emailArray.length == 0)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
displayErrorMessage('Please enter at least one "To:" address.');
|
|
|
|
$("#sharebox-to").focus().select();
|
|
|
|
return;
|
|
|
|
}
|
2011-07-07 17:59:34 +00:00
|
|
|
for (var i = 0; i < emailArray.length; i++)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
var addr = emailArray[i];
|
2011-07-07 17:59:34 +00:00
|
|
|
if (!addr.match(/^[\w\.\_\+\-]+\@[\w\_\-]+\.[\w\_\-\.]+$/))
|
|
|
|
{
|
|
|
|
displayErrorMessage('"' + padutils.escapeHtml(addr) + '" does not appear to be a valid email address.');
|
2011-03-26 13:10:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var subject = $("#sharebox-subject").val();
|
2011-07-07 17:59:34 +00:00
|
|
|
if (!subject)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
subject = self.getDefaultShareBoxSubjectForName(pad.getUserName());
|
|
|
|
$("#sharebox-subject").val(subject); // force the default subject
|
|
|
|
}
|
|
|
|
|
|
|
|
var padId = pad.getPadId();
|
|
|
|
var username = pad.getUserName();
|
|
|
|
setSendingInvite(true);
|
|
|
|
$("#sharebox-response").html("Sending...").get(0).className = '';
|
|
|
|
$("#sharebox-response").show();
|
2011-07-07 17:59:34 +00:00
|
|
|
$.ajax(
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
type: 'post',
|
|
|
|
url: '/ep/pad/emailinvite',
|
|
|
|
data: {
|
|
|
|
message: message,
|
|
|
|
toEmails: emailArray.join(','),
|
|
|
|
subject: subject,
|
|
|
|
username: username,
|
|
|
|
padId: padId
|
|
|
|
},
|
|
|
|
success: success,
|
|
|
|
error: error
|
|
|
|
});
|
|
|
|
var hideCall = self.hideShareboxLaterIfNoOtherInteraction();
|
2011-07-07 17:59:34 +00:00
|
|
|
|
|
|
|
function success(msg)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
setSendingInvite(false);
|
|
|
|
$("#sharebox-response").html("Email invitation sent!").get(0).className = 'goodresponse';
|
|
|
|
$("#sharebox-response").show();
|
2011-07-07 17:59:34 +00:00
|
|
|
window.setTimeout(function()
|
|
|
|
{
|
|
|
|
$("#sharebox-response").fadeOut('slow', function()
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
hideCall();
|
|
|
|
});
|
|
|
|
}, 1500);
|
|
|
|
}
|
2011-07-07 17:59:34 +00:00
|
|
|
|
|
|
|
function error(e)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
setSendingFeedback(false);
|
|
|
|
$("#sharebox-response").html("An error occurred; no email was sent.").get(0).className = 'badresponse';
|
|
|
|
$("#sharebox-response").show();
|
|
|
|
}
|
2011-07-07 17:59:34 +00:00
|
|
|
|
|
|
|
function displayErrorMessage(msgHtml)
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
$("#sharebox-response").html(msgHtml).get(0).className = 'badresponse';
|
|
|
|
$("#sharebox-response").show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return self;
|
|
|
|
}());
|