@@ -3,6 +3,37 @@ import React from 'react';
33class ModPacks extends React . Component {
44 constructor ( props ) {
55 super ( props )
6+ this . createModPack = this . createModPack . bind ( this ) ;
7+ this . removeModPack = this . removeModPack . bind ( this ) ;
8+ }
9+
10+ createModPack ( e , modpack ) {
11+ e . preventDefault ( ) ;
12+ self = this ;
13+
14+ let modpacks = { } ;
15+ modpacks [ "mods" ] = [ ] ;
16+ modpacks [ "title" ] = this . refs . modpackName . value ;
17+
18+ for ( var m in this . refs ) {
19+ if ( this . refs [ m ] . checked ) {
20+ modpacks [ "mods" ] . push ( this . refs [ m ] . id )
21+ }
22+ }
23+ $ . ajax ( {
24+ url : "/api/mods/packs/add" ,
25+ dataType : "json" ,
26+ type : "POST" ,
27+ data : JSON . stringify ( modpacks ) ,
28+ success : ( resp ) => {
29+ if ( resp . success === true ) {
30+ swal ( "Added modpack" , "Modpack: " + modpacks [ "title" ] + " added successfully" , "success" )
31+ self . props . loadModPackList ( ) ;
32+ } else {
33+ swal ( "Error" , "Could not create modpack " + modpacks [ "title" ] , "error" )
34+ }
35+ }
36+ } )
637 }
738
839 removeModPack ( modpack , e ) {
@@ -39,6 +70,34 @@ class ModPacks extends React.Component {
3970 </ div >
4071
4172 < div className = "box-body" >
73+ < div className = "box box-success collapsed-box" >
74+ < button type = "button" className = "btn btn-box-tool" data-widget = "collapse" >
75+ < div className = "box-header with-border" >
76+ < i className = "fa fa-plus fa-fw" > </ i > < h4 className = "box-title" > Create Mod Pack</ h4 >
77+ </ div >
78+ </ button >
79+ < div className = "box-body" style = { { display : "none" } } >
80+ < form onSubmit = { this . createModPack } >
81+ < label for = "modPack" > Mod Pack Name</ label >
82+ < div id = "modpack" className = "input-group" >
83+ < input ref = "modpackName" name = "modpack" id = "modpack" type = "text" className = "form-control" placeholder = "Enter Mod Pack Name..." />
84+ </ div >
85+ { this . props . installedMods . map ( ( mod , i ) => {
86+ return (
87+ < div className = "checkbox" key = { i } >
88+ < label for = { mod } >
89+ < input id = { mod } ref = { "mod-" + mod } type = "checkbox" />
90+ { mod }
91+ </ label >
92+ </ div >
93+ )
94+ } ) }
95+ < div className = "col-md-4" >
96+ < button className = "btn btn-block btn-success" type = "submit" > < i className = "fa fa-save fa-fw" > </ i > Create Mod Pack</ button >
97+ </ div >
98+ </ form >
99+ </ div >
100+ </ div >
42101 < table className = "table table-striped" >
43102 < thead >
44103 < tr >
@@ -49,7 +108,6 @@ class ModPacks extends React.Component {
49108 </ thead >
50109 < tbody >
51110 { this . props . modPacks . map ( ( mod , i ) => {
52- console . log ( mod )
53111 let dlURL = "/api/mods/packs/dl/" + mod
54112 return (
55113 < tr key = { i } >
@@ -75,6 +133,7 @@ class ModPacks extends React.Component {
75133}
76134
77135ModPacks . propTypes = {
136+ installedMods : React . PropTypes . array . isRequired ,
78137 modPacks : React . PropTypes . array . isRequired ,
79138 loadModPackList : React . PropTypes . func . isRequired ,
80139}
0 commit comments