5b70d58e971dffbf23f873cd08d01bdc049025a5
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

1) /*
2)  * SMF Package Manager Generator
3)  * Author: SleePy (JeremyD)
4)  * Repository: https://github.com/jdarwood007/smf_package_maker
5)  * License: BSD 3 Clause; See license.txt
6) */
7) 
8) /* This gets things going once the document has loaded, also makes sure JQuery is here. */
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

9) $(document).ready(function(){
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

10) 	/* Start off some counting */
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

11) 	action_count = 1;
12) 	instruct_count =new Array();
13) 	instruct_count[action_count] = 1;
14) 
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

15) 	/* Bind some stuff to our actions, using live so they auto update as new stuff is added. */
16) 	$('.collapse_action').live('click', collapse_action);
17) 	$('.expand_action').live('click', expand_action);
18) 	$('.delete_action').live('click', delete_action);
19) 	$('.restore_action').live('click', restore_action);
20) 
21) 	/* Now we will bind to the actual changes, again using live. */
22) 	$('.collapse_change').live('click', collapse_instruct);
23) 	$('.expand_change').live('click', expand_instruct);
24) 	$('.delete_change').live('click', delete_instruct);
25) 	$('.restore_change').live('cick', restore_instruct);
26) 
27) 	/* Now we will bind to some toggles in those changes, again using live. */
28) 	$('.instruct_action').live('change', instruct_change);
29) 	$('.inline_check').live('change', instruct_inline);
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

30) 
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

31) 	/* Give our buttons some actions. */
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

32) 	$('#add_action').click(create_new_action);
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

33) 	$('.add_instruct').live('click', create_new_instruct);
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

34) 	$('#show_preview').click(show_instruct_preview);
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

35) 
36) 	/* The details and basic buttons. */
37) 	$('#collapse_basic').click(function(){$('#basic_info .info').hide(); $('#collapse_basic').hide(); $('#restore_basic').show();});
38) 	$('#restore_basic').click(function(){$('#basic_info .info').show(); $('#restore_basic').hide(); $('#collapse_basic').show();});
39) 	$('#collapse_details').click(function(){$('#details_info .info').hide(); $('#collapse_details').hide(); $('#restore_details').show();});
40) 	$('#restore_details').click(function(){$('#details_info .info').show(); $('#restore_details').hide(); $('#collapse_details').show();});
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

41) 
42) 	/* Kick things off by creating a new action. */
43) 	create_new_action();
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

44) });
45) 
46) /* Handles adding actions */
47) function create_new_action()
48) {
49) 	/* We have been through this before */
50) 	$('#action_container').append($('#action_template').html().replace(/#ACTIONINDEX#/g, action_count));
51) 
52) 	/* Now we pretend to click said element */
53) 	$('#action-' + action_count).find('.add_instruct').click();
54) 
55) 	/* Move the index and add defaults */
56) 	action_count++;
57) 	instruct_count[action_count] = 1;
58) 
59) 	/* Update our counter */
60) 	update_counter();
61) }
62) 
63) /* Handles adding of instructions */
64) function create_new_instruct()
65) {
66) 	action_index = $(this).attr('data-action');
67) 
68) 	$('#action-' + action_index + '-instruct_container').append($('#instruct_template').html().replace(/#ACTIONINDEX#/g, action_index).replace(/#INSTRUCTINDEX#/g, instruct_count[action_index]));
69) 
70) 	$('#action-' + action_index + '-instruct-' + instruct_count[action_index] + '-action').change();
71) 
72) 	instruct_count[action_index]++;
73) 
74) 	update_counter();
75) }
76) 
77) /* Handles a change in the instruction */
78) function instruct_change()
79) {
80) 	action_index = $(this).attr('data-action');
81) 	instruct_index = $(this).attr('data-instruct');
82) 	this_act = $(this).val();
83) 
84) 	/* Then choose how to hide them */
85) 	if (this_act == 'modification')
86) 	{
87) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .destination').hide();
88) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .inline').hide();
89) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .code_block').hide();
90) 
91) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .reverse').show();
92) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .source').show();
93) 	}
94) 	else if ($.inArray(this_act, ["create-dir", "create-file", "remove-dir", "remove-file"]) > -1)
95) 	{
96) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .reverse').hide();
97) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .inline').hide();
98) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .code_block').hide();
99) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .source').hide();
100) 
101) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .destination').show();
102) 	}
103) 	else if ($.inArray(this_act, ["require-dir", "require-file", "move-dir", "move-file"]) > -1)
104) 	{
105) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .reverse').hide();
106) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .inline').hide();
107) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .code_block').hide();
108) 
109) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .source').show();
110) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .destination').show();
111) 	}
112) 	else if ($.inArray(this_act, ["code", "database", "readme"]) > -1)
113) 	{
114) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .reverse').hide();
115) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .destination').hide();
116) 
117) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .source').show();
118) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .inline').show();
119) 	}
120) 	else
121) 	{
122) 		/* We don't know what to do here! */
123) 		console.log("Unknown instruction action selected" [this_act, action_index, instruct_index], this);
124) 	}
125) }
126) 
127) /* Handles clicking the inline button */
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

128) function instruct_inline()
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

129) {
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

130) 	action_index = $(this).attr('data-action');
131) 	instruct_index = $(this).attr('data-instruct');
132) 	is_inline = $(this).is(':checked');
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

133) 
134) 	if (is_inline)
135) 	{
136) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .code_block').show();
137) 	}
138) 	else
139) 	{
140) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .code_block').hide();
141) 	}
142) }
143) 
144) /* Handles collapsing of the instruct */
145) function collapse_instruct()
146) {
147) 	action_index = $(this).attr('data-action');
148) 	instruct_index = $(this).attr('data-instruct');
149) 
150) 	/* Simply hide the instruct, and give a expand button */
151) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .edits').hide();
152) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .expand_change').show();
153) 	$(this).hide();
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

154) 
155) 	return false;
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

156) }
157) 
158) /* Handles expanding of the instruct */
159) function expand_instruct()
160) {
161) 	action_index = $(this).attr('data-action');
162) 	instruct_index = $(this).attr('data-instruct');
163) 
164) 	/* Simply show the instruct, and return to the original collapse button */
165) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .edits').show();
166) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .collapse_change').show();
167) 	$(this).hide();
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

168) 
169) 	return false;
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

170) }
171) 
172) /* Handles deleting a instruct */
173) function delete_instruct()
174) {
175) 	action_index = $(this).attr('data-action');
176) 	instruct_index = $(this).attr('data-instruct');
177) 
178) 	/* First we let the data know its deleted. */
179) 	$('#action-' + action_index + '-instruct-' + instruct_index + '-delete').val('1');
180) 
181) 	/* Then we hide this header, collapse the instruct and show the restore button */
182) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .edits').hide();
183) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .restore_change').show();
184) 	$(this).hide();
185) 
186) 	update_counter();
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

187) 	return false;
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

188) }
189) 
190) /* Handles restoring a instruct */
191) function restore_instruct()
192) {
193) 	action_index = $(this).attr('data-action');
194) 	instruct_index = $(this).attr('data-instruct');
195) 
196) 	/* First we let the data know its deleted. */
197) 	$('#action-' + action_index + '-instruct-' + instruct_index + '-delete').val('0');
198) 
199) 	/* Then we hide this header, collapse the instruct and show the restore button */
200) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .edits').show();
201) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .delete_change').show();
202) 	$(this).hide();
203) 
204) 	update_counter();
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

205) 	return false;
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

206) }
207) 
208) /* Handles collapsing of the action */
209) function collapse_action()
210) {
211) 	action_index = $(this).attr('data-action');
212) 
213) 	/* Simply hide the action, and give a expand button */
214) 	$('#action-' + action_index + '-instruct_container').hide();
215) 	$('#action-' + action_index + ' .expand_action').show();
216) 	$(this).hide();
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

217) 
218) 	return false;
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

219) }
220) 
221) /* Handles expanding of the action */
222) function expand_action()
223) {
224) 	action_index = $(this).attr('data-action');
225) 
226) 	/* Simply show the action, and return to the original collapse button */
227) 	$('#action-' + action_index + '-instruct_container').show();
228) 	$('#action-' + action_index + ' .collapse_action').show();
229) 	$(this).hide();
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

230) 
231) 	return false;
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

232) }
233) 
234) /* Handles deleting a action */
235) function delete_action()
236) {
237) 	action_index = $(this).attr('data-action');
238) 
239) 	/* First we let the data know its deleted. */
240) 	$('#action-' + action_index + '-delete').val('1');
241) 
242) 	/* Then we hide this header, collapse the instruct and show the restore button */
243) 	$('#action-' + action_index + '-instruct_container').hide();
244) 	$('#action-' + action_index + ' .restore_action').show();
245) 	$(this).hide();
246) 
247) 	update_counter();
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

248) 	return false;
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

249) }
250) 
251) /* Handles restoring a action */
252) function restore_action()
253) {
254) 	action_index = $(this).attr('data-action');
255) 
256) 	/* First we let the data know its deleted. */
257) 	$('#action-' + action_index + '-delete').val('0');
258) 
259) 	/* Then we hide this header, collapse the instruct and show the restore button */
Jeremy D Couldn't restore a file/ac...

Jeremy D authored 12 years ago

260) 	$('#action-' + action_index + '-instruct_container').show();
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

261) 	$('#action-' + action_index + ' .delete_action').show();
262) 	$(this).hide();
263) 
264) 	update_counter();
Jeremy D Forgot about using live, i...

Jeremy D authored 12 years ago

265) 	return false;
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

266) }
267) 
268) /* This is the nasty guy */
269) function show_instruct_preview()
270) {
271) 	$('#preview_container').show();
272) 
273) 	author = $('#basic_info_name').val().replace(/ /g,'_');
274) 	name = $('#basic_info_mod').val().replace(/ /g,'_');
275) 	version = $('#basic_info_version').val().replace(/ /g,'_');
276) 	type = $('#basic_info_type').val();
277) 
278) 	preview = '<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">' + "\n" + '\
279) <!-- This package was generated by SleePys Package Maker at http://sleepycode.com -->' + "\n" + '\
280) <package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">' + "\n" + '\
281) 	<id>' + author + ':' + name + '</id>' + "\n" + '\
282) 	<name>' + name + '</name>' + "\n" + '\
283) 	<version>' + version + '</version>' + "\n" + '\
284) 	<type>' + type + '</type>' + "\n";
285) 
286) 	i = 1;
287) 	for (i = 1; i < action_count; i++)
288) 	{
289) 		/* Skip this instruct if we deleted it. */
290) 		if ($('#action-' + i + '-delete').val() == '1')
291) 		{
292) 			continue;
293) 		}
294) 
295) 		/* Get the action info */
296) 		action_type = $('#action-' + i + '-type').val();
297) 		action_smf_versions = $('#action-' + i + '-smf_versions').val();
298) 
299) 		/* We only want valid actions */
300) 		if ($.inArray(action_type, ["install", "upgrade", "uninstall"]) > -1)
301) 		{
302) 			preview += "\n" + '\
303) 	<' + action_type;
304) 		}
305) 		else
306) 		{
307) 			preview += "\n" + '\
308) 	<install';
309) 		}
310) 
311) 		/* Maybe we are limiting this to specific SMF versions. */
312) 		if (action_smf_versions != '')
313) 		{
314) 			preview += ' for="' + action_smf_versions + '"';
315) 		}
316) 		preview += '>';
317) 
318) 		/* Now onto the individual instructions we made! */
319) 		for (j = 1; j < instruct_count[i]; j++)
320) 		{
321) 			/* Skip this instruct if we deleted it. */
322) 			if ($('#action-' + i + '-instruct-' + j + '-delete').val() == '1')
323) 			{
324) 				continue;
325) 			}
326) 
327) 			/* Get our instruction info */
328) 			instruct_action		=	$('#action-' + i + '-instruct-' + j + '-action').val();
329) 			instruct_reverse	=	$('#action-' + i + '-instruct-' + j + '-reverse').is(':checked');
330) 			instruct_inline		=	$('#action-' + i + '-instruct-' + j + '-reverse').is(':checked');
331) 			instruct_source		=	$('#action-' + i + '-instruct-' + j + '-source').val();
332) 			instruct_destination=	$('#action-' + i + '-instruct-' + j + '-destination').val();
333) 			instruct_block		=	$('#action-' + i + '-instruct-' + j + '-block').val().replace('<' + '?php', '').replace('?' + '>', '');
334) 
335) 			/* Try to make it easier to handle these */
336) 			if ($.inArray(instruct_action, ["modification", "code", "database", "readme"]) > -1)
337) 			{
338) 				preview += "\n" + '\
339) 		<' + instruct_action;
340) 
341) 				/* Technically only modification should use reverse.
342) 					Code can just check $context['uninstall'] or use another file*/
343) 				if (instruct_reverse && instruct_action == 'modification')
344) 				{
Jeremy D Some more fixes and code c...

Jeremy D authored 12 years ago

345) 					preview += ' reverse="true"';
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

346) 				}
347) 
348) 				if (instruct_inline && $.inArray(instruct_action, ["code", "database", "readme"]) > -1)
349) 				{
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

350) 					preview += ' inline="true">' + "\n" + instruct_block + "\n" + '\
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

351) 		</' + instruct_action + '>';
352) 				}
353) 				else
354) 				{
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

355) 					preview += '>' + instruct_source + '</' + instruct_action + ">\n";
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

356) 				}
357) 			}
358) 			else if ($.inArray(instruct_action, ["create-dir", "create-file", "remove-dir", "remove-file"]) > -1)
359) 			{
360) 				/* It may seem confusing to use destination here as name while the others use source.
361) 					Logic is just easier to follow from the GUI to think of destination as what happens to the SMF install,
362) 					While source is where it is in the modification. */
363) 				preview += "\n" + '\
364) 		<' + instruct_action + ' name="' + instruct_destination + '" />';
365) 			}
366) 			else if ($.inArray(instruct_action, ["require-dir", "require-file", "move-dir", "move-file"]) > -1)
367) 			{
368) 				/* We use source and destination correctly here, see note above for those actions. */
369) 				preview += "\n" + '\
370) 		<' + instruct_action + ' name="' + instruct_source + '" destination="' + instruct_destination + '" />';
371) 			}
372) 			else
373) 			{
374) 				/* We don't know what to do here! */
375) 				console.log("Unknown instruction action selected" [instruct_action, i, j], this);
376) 			}
377) 
378) 		}
379) 
380) 		/* Close up the action instruct */
381) 		if ($.inArray(action_type, ["install", "upgrade", "uninstall"]) > -1)
382) 		{
383) 			preview += "\n" + '\
384) 	</' + action_type + '>';
385) 		}
386) 		else
387) 		{
388) 			preview += "\n" + '\
389) 	</install>';
390) 		}
391) 
392) 	}
393) 
394) 	$('#preview').text(preview);
395) }
396) 
397) function download_action_generate()
398) {
399) 	show_instruct_preview();
400) 
Jeremy D Fixed downloads on info se...

Jeremy D authored 12 years ago

401) 	$.generateFile({
402) 		filename	: 'package-info.xml',
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

403) 		content		: $('#preview').text(),
Jeremy D Made it so we can change t...

Jeremy D authored 12 years ago

404) 		script		: $('#downloadername').val() + '?download'
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

405) 	});
406) }
407) 
408) function download_action_data()
409) {
410) 	show_instruct_preview();
411) 
412) 	data = $.base64.encode($('#preview').text());
413) 
414) 	/* No actionname can be specified by a data URI */
Jeremy D Made it so we can change t...

Jeremy D authored 12 years ago

415) 	window.location = 'data:application/octet-stream;charset=utf-8;base64,' + data;