Commit c994b0a9 authored by The Great Git Migration's avatar The Great Git Migration
Browse files

This commit was manufactured as part of Drupal's Great Git Migration to

create tag 'DRUPAL-6--1-0-RC2'.

Sprout from DRUPAL-6--1 2010-03-16 22:58:06 UTC Eugen Mayer <eugen.mayer@kontextwork.de> 'Fixed: http://drupal.org/node/732094'
Cherrypick from DRUPAL-6--1 2010-03-23 15:17:53 UTC Eugen Mayer <eugen.mayer@kontextwork.de> 'Reworking locking and unlock messages':
    js/content_lock_init.js
    js/jquery.url.packed.js
    js/onUserExit.js
Delete:
    tests/content_lock.test
parent 8ea0aa96
(function($) {
window.content_lock_onleave = function () {
var nid = Drupal.settings.content_lock.nid;
var random = Math.random();
var aurl = "http:/ds.l"+Drupal.settings.basePath + 'index.php?q=ajax/content_lock/'+nid+'/canceledit&t='+random;
$.ajax({
url: aurl,
async: false,
cache:false
});
}
window.content_lock_confirm = function () {
return Drupal.t('Be aware, if you press "OK" now, ALL your changes will be lost!');
}
$(document).ready(function() {
$().onUserExit( {
execute: content_lock_onleave,
executeConfirm: content_lock_confirm,
internalURLs: 'canceledit|trash/confirm'
});
});
})(jQuery);
\ No newline at end of file
jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}();
\ No newline at end of file
/*
* onUserExit jQuery Plugin (http://www.userfirstinteractive.com/)
* @author Scott D. Brooks
* @created by UserFirst Interactive (creations@userfirstinteractive.com)
*
* @version 1.1
*
* @changelog
* v 1.0 -> Starting release [Dec. 27, 2008]
* v 1.1 -> Added support for detection of page refresh through F5 key and ctrl+r.
Added support for forms as well, so submissions don't trigger exit event. [Jan. 25, 2010]
*
*/
var movingWithinSite = false; // this is the var that determines if the unload was caused by a user leaving, or navigating in the site.
var codeToExecute = function() {};
function userMovingWithinSite() {
movingWithinSite = true;
}
// Code to detect refreshing of the page through keyboard use
var ctrlKeyIsDown = false;
function interceptKeyUp(e) {
if( !e ) {
if (window.event)
e = window.event;
else
return;
}
keyCode = e.keyCode;
if (keyCode == 17){
ctrlKeyIsDown = false;
}
}
function interceptKeyDown(e) {
if( !e ) {
if (window.event)
e = window.event;
else
return;
}
keyCode = e.keyCode;
// F5 detected
if ( keyCode == 116 ) {
userMovingWithinSite();
}
if (keyCode == 17){
ctrlKeyIsDown = true;
}
// then they are pressing Ctrl+R
if (ctrlKeyIsDown && keyCode == 82){
userMovingWithinSite();
}
}
function interceptKeyPress(e) {
if( !e ) {
if (window.event)
e = window.event;
else
return;
}
var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : void 0;
if(e.charCode == null || e.charCode == 0 ) {
// F5 pressed
if ( keyCode == 116 ) {
userMovingWithinSite();
}
}
}
function attachEventListener( obj, type, func, capture ) {
if(window.addEventListener) {
//Mozilla, Netscape, Firefox
obj.addEventListener( type, func, capture );
} else {
//IE
obj.attachEvent( 'on' + type, func );
}
}
(function($){
$.fn.onUserExit = function(options) {
var defaults = {
execute: "", // no function assigned by default
executeConfirm: "", // executed when its confirmed
internalURLs: "" // used to detect whether the url is internal or not (you can add subdomains to this list so when a user hops between sites, they are still considered to be internal.
};
var options = $.extend(defaults, options);
if (options.execute == "") {
alert("The onUserExit jQuery Plugin has been misconfigured. Please add the function you wish to execute.");
}
if (options.internalURLs == "") {
alert("The onUserExit jQuery Plugin has been misconfigured. Please add internal URLs so it know when the user is navigating internally.");
}
codeToExecute = options.execute;
// add onClick function to all internal links
$("a").each(function() {
var obj = $(this);
var linkIsInternal = false;
var myInternalURLs = options.internalURLs.split("|");
for (i = 0; i < myInternalURLs.length; i++) {
if (obj.attr("href") != undefined && obj.attr("href").indexOf(myInternalURLs[i]) !== -1) {
linkIsInternal = true;
}
}
if (linkIsInternal == true) {
obj.bind("click", function(){
userMovingWithinSite();
});
}
});
$("form").each(function() {
var obj = $(this);
currentonSubmit = obj.attr("onSubmit");
if (currentonSubmit === undefined) {
currentonSubmit = "";
}
obj.attr("onSubmit", currentonSubmit + " userMovingWithinSite();");
});
// for Refresh Detection
attachEventListener(document,"keydown",interceptKeyDown,true);
attachEventListener(document,"keyup",interceptKeyUp,true);
attachEventListener(document,"keypress",interceptKeyPress,true);
window.onbeforeunload = function(){
if (movingWithinSite == false) {
return options.executeConfirm();
}
}
};
window.onunload = function() {
// unloading the page when the user is leaving
if (movingWithinSite == false) {
codeToExecute();
}
};
})(jQuery);
<?php
// $Id$
/**
* @file
* Backport of Drupal 7 block.test with modifications, see BACKPORT.txt.
*
* Copyright 2008-2009 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
*/
class ContentLockTestCase extends DrupalWebTestCase {
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => 'Content lock functionality',
'description' => t('Tests locking'),
'group' => 'Edit',
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('content_lock');
// Create and login user
$author = $this->drupalCreateUser(array('check out documents','edit any page content'));
$this->drupalLogin($author);
}
function testSetupNodeForLocking() {
// Add a new box by filling out the input form on the admin/build/block/add page.
/*$this->drupalPost('http://dst.l/admin/content/node-type/page',array(
))*/
}
function testConcurrentEditing() {
// TODO
}
function testLocking() {
// Add a new box by filling out the input form on the admin/build/block/add page.
$n = $this->DrupalCreateNode(array(
'type' => 'page', // This replaces the default type
));
$this->drupalGet('node/'.$n->nid.'/edit');
$this->assertTrue($this->_checkLock($n->nid,true),'Checking edit lock when user is editing');
}
function testLockingNotAllowed() {
// Add a new box by filling out the input form on the admin/build/block/add page.
$author = $this->drupalCreateUser(array('edit any page content'));
$this->drupalLogin($author);
$n = $this->DrupalCreateNode(array(
'type' => 'page', // This replaces the default type
));
$this->drupalGet('node/'.$n->nid.'/edit');
$this->assertTrue($this->_checkLock($n->nid,false),'Edit lock is not set, when user is editing and has no "checkout out decuments" permission');
}
protected function _checkLock($nid,$bool) {
$lock = content_lock_fetch_lock($nid);
if(is_object($lock) && $bool) {
return true;
}
else if($lock === false && $bool === false) {
return true;
}
// else
return true;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment