Multiple results working with find in filenames

Title outside of results DIV, which is now the scrollable container
Rename all/replace all button wording
Handling both cases now, find & documents and filenames
The latter works by scanning IDs and building up array
Find in filenames also handles selected filenames as well as all
filenames
Can rename singularly, rename all or click link to open file
This commit is contained in:
Matt Pass
2012-07-10 07:08:25 +01:00
parent a5d473c546
commit a0dbbbe397

View File

@@ -10,17 +10,24 @@
<body class="results">
<h1 id="title"></h1>
<div class="resultsPane">
<h1 id="title"></h1>
<div id="results"></div>
</div>
<?php if (isset($_GET['replace'])) { ?>
<div class="replaceAll" id="replaceAll" onClick="replaceAll()" style="opacity: 0.1">replace all</div>
<div class="replaceAll" id="replaceAll" onClick="<?php if (isset($_GET['target'])) {echo 'renameAll()';} else {echo 'replaceAll()';}; ?>" style="opacity: 0.1"><?php if (isset($_GET['target'])) {echo 'rename all';} else {echo 'replace all';}; ?></div>
<?php ;}; ?>
<script>
var resultsDisplay = "";
var foundTabArray = [];
var foundArray = [];
foundInSelected = false;
userTarget = top.document.findAndReplace.target.value;
<?php
// Find in open docs?
if (!isset($_GET['target'])) {
$targetName = "document";
?>
var startTab = top.ICEcoder.selectedTab;
var rExp = new RegExp("<?php echo strClean($_GET['find']); ?>","g");
for (var i=1;i<=top.ICEcoder.openFiles.length;i++) {
@@ -33,20 +40,51 @@ for (var i=1;i<=top.ICEcoder.openFiles.length;i++) {
resultsDisplay += '<div class="replace" id="replace" onClick="replaceSingle('+i+');this.style.display=\'none\'">replace</div>';
<?php ;}; ?>
resultsDisplay += '<hr>';
foundTabArray.push(i);
foundArray.push(i);
}
}
if (startTab!=top.ICEcoder.selectedTab) {
top.ICEcoder.switchTab(startTab);
}
foundTabArray.length==0 ? showHide = "hide" : showHide = "show";
<?php
// Find in files or filenames
} else {
$targetName = "file/folder";
?>
var spansArray = top.ICEcoder.filesFrame.contentWindow.document.getElementsByTagName('span');
for (var i=0;i<spansArray.length;i++) {
targetURL = spansArray[i].id.replace(/\|/g,"/");
if (targetURL.indexOf('<?php echo strClean($_GET['find']); ?>')>-1 && targetURL.indexOf('_perms')>-1) {
if (userTarget.indexOf("selected")>-1) {
for (var j=0;j<top.ICEcoder.selectedFiles.length;j++) {
if (top.ICEcoder.selectedFiles[j].indexOf(targetURL.replace(/\//g,"|").replace(/_perms/g,""))>-1) {
foundInSelected = true;
}
}
}
if (userTarget.indexOf("all")>-1 || (userTarget.indexOf("selected")>-1 && foundInSelected)) {
resultsDisplay += '<a href="javascript:top.ICEcoder.openFile(\''+top.fullPath+targetURL.replace(/\|/g,"/").replace(/_perms/g,"")+'\');top.ICEcoder.showHide(\'hide\',top.document.getElementById(\'blackMask\'))">'+ targetURL.replace(/\|/g,"/").replace(/_perms/g,"").replace(/<?php echo str_replace("/","\/",strClean($_GET['find'])); ?>/g,"<b><?php echo strClean($_GET['find']); ?></b>")+ '</a><br><div id="foundCount'+i+'">'+spansArray[i].innerHTML+', rename to '+targetURL.replace(/\|/g,"/").replace(/_perms/g,"").replace(/<?php echo str_replace("/","\/",strClean($_GET['find'])); ?>/g,"<b><?php echo strClean($_GET['replace']);?></b>")+'</div>';
<?php if (isset($_GET['replace'])) { ?>
resultsDisplay += '<div class="replace" id="replace" onClick="renameSingle('+i+');this.style.display=\'none\'">rename</div>';
<?php ;}; ?>
resultsDisplay += '<hr>';
foundArray.push(i);
}
}
}
<?php
;}
?>
foundArray.length==0 ? showHide = "hide" : showHide = "show";
top.ICEcoder.showHide(showHide,top.document.getElementById('blackMask'));
if (foundTabArray.length==0) {top.ICEcoder.message('No matches found')};
if (foundArray.length==0) {top.ICEcoder.message('No matches found')};
<?php if (isset($_GET['replace'])) { ?>
if (foundTabArray.length!=0) {document.getElementById('replaceAll').style.opacity = 1};
if (foundArray.length!=0) {document.getElementById('replaceAll').style.opacity = 1};
<?php ;}; ?>
foundTabArray.length >= 2 ? plural = "s" : plural = "";
document.getElementById('title').innerHTML = "'<?php echo strClean($_GET['find']); ?>' found in "+foundTabArray.length+" file"+plural;
foundArray.length >= 2 ? plural = "s" : plural = "";
targetName = "<?php echo $targetName;?>";
foundInSelected ? selectedText = "selected " : selectedText = "";
document.getElementById('title').innerHTML = "'<?php echo strClean($_GET['find']); ?>' found in "+foundArray.length+" "+selectedText+targetName+plural;
document.getElementById('results').innerHTML = resultsDisplay;
var gotoTab = function(tab) {
@@ -63,8 +101,21 @@ var replaceSingle = function(tab) {
}
var replaceAll = function() {
for (var i=0;i<=foundTabArray.length-1;i++) {
replaceSingle(foundTabArray[i]);
for (var i=0;i<=foundArray.length-1;i++) {
replaceSingle(foundArray[i]);
}
top.ICEcoder.showHide('hide',top.document.getElementById('blackMask'));
}
var renameSingle = function(arrayRef) {
fileRef = top.fullPath+spansArray[arrayRef].id.replace(/\|/g,"/").replace(/_perms/g,"");
newName = spansArray[arrayRef].id.replace(/\|/g,"/").replace(/_perms/g,"").replace(/<?php echo str_replace("/","\/",strClean($_GET['find'])); ?>/g,"<?php echo strClean($_GET['replace']); ?>");
top.ICEcoder.renameFile(fileRef,newName);
}
var renameAll = function() {
for (var i=0;i<=foundArray.length-1;i++) {
renameSingle(foundArray[i]);
}
top.ICEcoder.showHide('hide',top.document.getElementById('blackMask'));
}