c1ae3088122b4c93dd297c9273ec26e65dcd4e94
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 Completed Info Maker secti...

Jeremy D authored 12 years ago

15) 	/* Kick things off by creating a new action. */
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

16) 	create_new_action();
17) 
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

19) 	$('#add_action').click(create_new_action);
20) 	$('#show_preview').click(show_instruct_preview);
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

21) 
22) 	/* The details and basic buttons. */
23) 	$('#collapse_basic').click(function(){$('#basic_info .info').hide(); $('#collapse_basic').hide(); $('#restore_basic').show();});
24) 	$('#restore_basic').click(function(){$('#basic_info .info').show(); $('#restore_basic').hide(); $('#collapse_basic').show();});
25) 	$('#collapse_details').click(function(){$('#details_info .info').hide(); $('#collapse_details').hide(); $('#restore_details').show();});
26) 	$('#restore_details').click(function(){$('#details_info .info').show(); $('#restore_details').hide(); $('#collapse_details').show();});
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

27) });
28) 
29) /* Handles adding actions */
30) function create_new_action()
31) {
32) 	/* We have been through this before */
33) 	$('#action_container').append($('#action_template').html().replace(/#ACTIONINDEX#/g, action_count));
34) 
35) 	/* We need to bind the new create instruct button */
36) 	$('.add_instruct').click(create_new_instruct);
37) 
38) 	/* Now we pretend to click said element */
39) 	$('#action-' + action_count).find('.add_instruct').click();
40) 
41) 	/* Now add some actions to our buttons */
42) 	$('#action-' + action_count + ' .collapse_action').click(collapse_action);
43) 	$('#action-' + action_count + ' .expand_action').click(expand_action);
44) 	$('#action-' + action_count + ' .delete_action').click(delete_action);
45) 	$('#action-' + action_count + ' .restore_action').click(restore_action);
46) 
47) 	/* Move the index and add defaults */
48) 	action_count++;
49) 	instruct_count[action_count] = 1;
50) 
51) 	/* Update our counter */
52) 	update_counter();
53) }
54) 
55) /* Handles adding of instructions */
56) function create_new_instruct()
57) {
58) 	action_index = $(this).attr('data-action');
59) 
60) 	$('#action-' + action_index + '-instruct_container').append($('#instruct_template').html().replace(/#ACTIONINDEX#/g, action_index).replace(/#INSTRUCTINDEX#/g, instruct_count[action_index]));
61) 
62) 	$('#action-' + action_index + '-instruct_container .collapse_change').click(collapse_instruct);
63) 	$('#action-' + action_index + '-instruct_container .expand_change').click(expand_instruct);
64) 	$('#action-' + action_index + '-instruct_container .delete_change').click(delete_instruct);
65) 	$('#action-' + action_index + '-instruct_container .restore_change').click(restore_instruct);
66) 
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

67) 	$('#action-' + action_index + '-instruct-' + instruct_count[action_index] + '-action').change(instruct_change);
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

68) 	$('#action-' + action_index + '-instruct-' + instruct_count[action_index] + '-action').change();
69) 
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

70) 	$('#action-' + action_index + '-instruct-' + instruct_count[action_index] + '-inline').change(instruct_inline);
71) 
Jeremy D Added Package Info stuff a...

Jeremy D authored 12 years ago

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) 
128) /* Handles clicking the inline button */
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

134) 
135) 	if (is_inline)
136) 	{
137) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .code_block').show();
138) 	}
139) 	else
140) 	{
141) 		$('#action-' + action_index + '-instruct-' + instruct_index + ' .code_block').hide();
142) 	}
143) }
144) 
145) /* Handles collapsing of the instruct */
146) function collapse_instruct()
147) {
148) 	action_index = $(this).attr('data-action');
149) 	instruct_index = $(this).attr('data-instruct');
150) 
151) 	/* Simply hide the instruct, and give a expand button */
152) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .edits').hide();
153) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .expand_change').show();
154) 	$(this).hide();
155) }
156) 
157) /* Handles expanding of the instruct */
158) function expand_instruct()
159) {
160) 	action_index = $(this).attr('data-action');
161) 	instruct_index = $(this).attr('data-instruct');
162) 
163) 	/* Simply show the instruct, and return to the original collapse button */
164) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .edits').show();
165) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .collapse_change').show();
166) 	$(this).hide();
167) }
168) 
169) /* Handles deleting a instruct */
170) function delete_instruct()
171) {
172) 	action_index = $(this).attr('data-action');
173) 	instruct_index = $(this).attr('data-instruct');
174) 
175) 	/* First we let the data know its deleted. */
176) 	$('#action-' + action_index + '-instruct-' + instruct_index + '-delete').val('1');
177) 
178) 	/* Then we hide this header, collapse the instruct and show the restore button */
179) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .edits').hide();
180) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .restore_change').show();
181) 	$(this).hide();
182) 
183) 	update_counter();
184) }
185) 
186) /* Handles restoring a instruct */
187) function restore_instruct()
188) {
189) 	action_index = $(this).attr('data-action');
190) 	instruct_index = $(this).attr('data-instruct');
191) 
192) 	/* First we let the data know its deleted. */
193) 	$('#action-' + action_index + '-instruct-' + instruct_index + '-delete').val('0');
194) 
195) 	/* Then we hide this header, collapse the instruct and show the restore button */
196) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .edits').show();
197) 	$('#action-' + action_index + '-instruct-' + instruct_index + ' .delete_change').show();
198) 	$(this).hide();
199) 
200) 	update_counter();
201) }
202) 
203) /* Handles collapsing of the action */
204) function collapse_action()
205) {
206) 	action_index = $(this).attr('data-action');
207) 
208) 	/* Simply hide the action, and give a expand button */
209) 	$('#action-' + action_index + '-instruct_container').hide();
210) 	$('#action-' + action_index + ' .expand_action').show();
211) 	$(this).hide();
212) }
213) 
214) /* Handles expanding of the action */
215) function expand_action()
216) {
217) 	action_index = $(this).attr('data-action');
218) 
219) 	/* Simply show the action, and return to the original collapse button */
220) 	$('#action-' + action_index + '-instruct_container').show();
221) 	$('#action-' + action_index + ' .collapse_action').show();
222) 	$(this).hide();
223) }
224) 
225) /* Handles deleting a action */
226) function delete_action()
227) {
228) 	action_index = $(this).attr('data-action');
229) 
230) 	/* First we let the data know its deleted. */
231) 	$('#action-' + action_index + '-delete').val('1');
232) 
233) 	/* Then we hide this header, collapse the instruct and show the restore button */
234) 	$('#action-' + action_index + '-instruct_container').hide();
235) 	$('#action-' + action_index + ' .restore_action').show();
236) 	$(this).hide();
237) 
238) 	update_counter();
239) }
240) 
241) /* Handles restoring a action */
242) function restore_action()
243) {
244) 	action_index = $(this).attr('data-action');
245) 
246) 	/* First we let the data know its deleted. */
247) 	$('#action-' + action_index + '-delete').val('0');
248) 
249) 	/* 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

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

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

340) 		</' + instruct_action + '>';
341) 				}
342) 				else
343) 				{
Jeremy D Completed Info Maker secti...

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

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

Jeremy D authored 12 years ago

394) 	});
395) }
396) 
397) function download_action_data()
398) {
399) 	show_instruct_preview();
400) 
401) 	data = $.base64.encode($('#preview').text());
402) 
403) 	/* No actionname can be specified by a data URI */
Jeremy D Made it so we can change t...

Jeremy D authored 12 years ago

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