Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-06-2012, 12:36 AM   PM User | #1
jimcj1301
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
jimcj1301 is an unknown quantity at this point
Post Build Search and Replace Web form?

I want to know how or what would be the best way to achieve the following.If im not in the correct forum im sorry, I thought Javascript would be the best way.

I work with a large eCommerce company and we have to constantly replace images with new images and then clear the cache using a pre-made template. I'll show a small example of the template it's a *.txt file template that I use for refreshing content on "Akamai edge control"

There is about 100 different lines in the text file each a little different but they all contain to sets of generic variables.

(example excerpt below - using the PHP box to show my sample but its just links)

PHP Code:
http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image250 
http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image500 
http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image800 
http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image1000 
That is just an example of what it looks like in the text file. The thing we do is open the file with Notepad and press Ctrl+h and the replace box pops up. I put in a number could be i.e. "123456" to replace the xxxxxx but I then have to go back to the number and manually change it to "123000" mind you we are only making changes to the xxxxxx and the zzzzzz. They are just place holders. So my end result would be like this...

Ps. on the zzzzzz it always ends with "000"

PHP Code:
http://www.mysite.com/file/folder/blah/123456/_something_else here/123000/image250 
http://www.mysite.com/file/folder/blah/123456/_something_else here/123000/image500 
http://www.mysite.com/file/folder/blah/123456/_something_else here/123000/image800 
http://www.mysite.com/file/folder/blah/123456/_something_else here/123000/image1000 
My main question is... is there already some sort of program that can run this process a bit more automatically by just selecting my template file and pasting in my only "123456" and getting all the lines the change while adding the zzzzzz with the zero's also.

I'm trying to eliminate a ton of work and make the process more efficient. My example of "123456" could also be up to "1234567". Maybe even pasting in more then one number separated with commas kind of like "123456,123457,123458" then it runs sample process generating a block of text for each number like it was found and replaced manually.

Ideally I would like to just have a web based form like the image mock up below to perform the task, unless there is another way without installing software on over 1000 computers. Hope this make sense. Thanks in advance for any input.

http://i.stack.imgur.com/6Kc5B.jpg
jimcj1301 is offline   Reply With Quote
Old 12-06-2012, 05:42 AM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
not 100% sure what you need, but hopefully you can modify this to work for you:

Code:
<!DOCTYPE html>
<html>
  <head>
    <title>file reps</title>

</head>
<body style="zoom: 1.5"> <center>
	<input type="file" onchange='readText(this)' /> <br />

	<textarea rows=10 cols=84 id="txtReps">123456, 123000</textarea> <br />
		<button onclick="rip()">run script</button>
		<button onclick="output.value=output.defaultValue;">reset</button>
	<br />

	<textarea rows=10 cols=84 id="output">http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image250  
http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image500  
http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image800  
http://www.mysite.com/file/folder/blah/xxxxxx/_something_else here/zzzzzz/image1000  </textarea>
	

	
    <script type="text/javascript">

		var reader = new FileReader();

		function rip(e) {  
			var out=(e && e.target && e.target.result) || output.value ;
			var reps=txtReps.value.split(/\s*,\s*/);
			
			output.value= out.split("\n").map(function(a){
				return a	.split("xxxxxx").join(reps[0])
						.split("zzzzzz").join(reps[1]);
			}).join("\n");
		}
					

		function readText(that){

			if(that.files && that.files[0]){
				var reader = new FileReader();
				reader.onload = rip;
				reader.readAsText(that.files[0]);
			}//end if html5 filelist support
		} 

</script>

</center>  </body>
</html>
i budgeted 15 mins, spent 14m37s
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 12-06-2012 at 05:47 AM..
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
jimcj1301 (12-07-2012)
Old 12-07-2012, 04:15 AM   PM User | #3
jimcj1301
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
jimcj1301 is an unknown quantity at this point
wow, almost exactly what I was looking for. I made a new image sample that might show a little bit more clear what I want it to do. Not sure what to tweak to get it to split the xxxxxx numbers and add the 000's

I just want to be able to add " 123456,123457,123458,123459, etc...endless" and then get the output to automatically take each of those numbers and plug them into the "xxxxxx" while also replacing the last three numbers with 000 and plugging into the "zzzzzz"

Maybe even a COPY button at the bottom that will select the output script and/or copy





I realllly appreciate your help.
jimcj1301 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:22 AM.


Advertisement
Log in to turn off these ads.