@@ -38,9 +38,6 @@ export default Ember.Object.extend({
3838orientation :{
3939names :[ 'any' , 'natural' , 'landscape' , 'portrait' , 'portrait-primary' , 'portrait-secondary' , 'landscape-primary' , 'landscape-secondary' ]
4040} ,
41- formattedManifest :function ( ) {
42- return new Ember . Handlebars . SafeString ( "<code class='language-javascript'>" + JSON . stringify ( this . get ( 'manifest' ) , null , ' ' ) + "</code>" ) ;
43- } . property ( 'manifest' ) ,
4441save :function ( ) {
4542this . set ( 'isSaving' , true ) ;
4643if ( ! this . manifestId ) {
@@ -49,6 +46,24 @@ export default Ember.Object.extend({
4946this . update ( ) ;
5047}
5148} ,
49+ processResult :function ( result ) {
50+ this . set ( 'manifest' , result . content ) ;
51+ this . set ( 'manifestId' , result . id ) ;
52+ this . set ( 'manifest.display' , 'fullscreen' ) ;
53+ this . set ( 'manifest.orientation' , 'any' ) ;
54+ if ( ! this . get ( 'manifest.icons' ) ) {
55+ this . set ( 'manifest.icons' , [ ] ) ;
56+ }
57+ if ( result . suggestions ) {
58+ this . set ( 'suggestions' , result . suggestions ) ;
59+ }
60+ if ( result . warnings ) {
61+ this . set ( 'warnings' , result . warnings ) ;
62+ }
63+ if ( result . errors ) {
64+ this . set ( 'errors' , result . errors ) ;
65+ }
66+ } ,
5267create :function ( ) {
5368var self = this ;
5469ajax ( {
@@ -58,74 +73,32 @@ export default Ember.Object.extend({
5873dataType :'json' ,
5974contentType :'application/json; charset=utf-8'
6075} ) . then ( function ( result ) {
61- self . set ( 'manifest' , result . content ) ;
62- self . set ( 'manifestId' , result . id ) ;
63-
64- //Set Defaults
65- self . set ( 'manifest.display' , 'fullscreen' ) ;
66- self . set ( 'manifest.orientation' , 'any' ) ;
67-
68- if ( ! self . get ( 'manifest.icons' ) ) {
69- self . set ( 'manifest.icons' , [ ] ) ;
70- }
71-
72- if ( result . suggestions ) {
73- self . set ( 'suggestions' , result . suggestions ) ;
74- }
75-
76- if ( result . warnings ) {
77- self . set ( 'warnings' , result . warnings ) ;
78- }
79-
80- if ( result . errors ) {
81- self . set ( 'errors' , result . errors ) ;
82- }
83-
84- self . save ( ) ;
85-
76+ self . processResult ( result ) ;
8677self . set ( 'isSaving' , false ) ;
87-
8878} ) . catch ( function ( ) {
8979self . set ( 'isSaving' , false ) ;
9080} ) ;
9181} ,
9282update :function ( ) {
93- var self = this ,
94- manifest = self . get ( 'manifest' ) ;
95-
83+ var self = this ;
84+ var manifest = self . get ( 'manifest' ) ;
9685manifest = _ . omit ( manifest , function ( prop ) {
97- if ( _ . isString ( prop ) ) {
98- return _ . isEmpty ( prop ) ;
99- } else if ( _ . isObject ( prop ) ) {
100- return _ . isUndefined ( prop ) ;
101- }
102-
103- return false ;
86+ if ( _ . isString ( prop ) ) {
87+ return _ . isEmpty ( prop ) ;
88+ } else if ( _ . isObject ( prop ) ) {
89+ return _ . isUndefined ( prop ) ;
90+ }
91+ return false ;
10492} ) ;
105-
10693ajax ( {
10794url :config . APP . API_URL + '/manifests/' + this . get ( 'manifestId' ) ,
10895type :'PUT' ,
10996data :JSON . stringify ( manifest ) ,
11097dataType :'json' ,
11198contentType :'application/json; charset=utf-8'
11299} ) . then ( function ( result ) {
113- self . set ( 'manifest' , result . content ) ;
114-
115- if ( result . suggestions ) {
116- self . set ( 'suggestions' , result . suggestions ) ;
117- }
118-
119- if ( result . warnings ) {
120- self . set ( 'warnings' , result . warnings ) ;
121- }
122-
123- if ( result . errors ) {
124- self . set ( 'errors' , result . errors ) ;
125- }
126-
100+ self . processResult ( result ) ;
127101self . set ( 'isSaving' , false ) ;
128-
129102} ) . catch ( function ( ) {
130103self . set ( 'isSaving' , false ) ;
131104} ) ;
@@ -142,5 +115,28 @@ export default Ember.Object.extend({
142115} ) . catch ( function ( ) {
143116self . set ( 'isBuilding' , false ) ;
144117} ) ;
118+ } ,
119+ generateFormData :function ( file ) {
120+ var formData = new FormData ( ) ;
121+ formData . append ( 'file' , file ) ;
122+ return formData ;
123+ } ,
124+ upload :function ( file ) {
125+ var self = this ;
126+ var data = this . generateFormData ( file ) ;
127+ this . set ( 'isSaving' , true ) ;
128+ ajax ( {
129+ url :config . APP . API_URL + '/manifests' ,
130+ type :'POST' ,
131+ data :data ,
132+ contentType :false ,
133+ processData :false ,
134+ cache :false
135+ } ) . then ( function ( result ) {
136+ self . processResult ( result ) ;
137+ self . set ( 'isSaving' , false ) ;
138+ } ) . catch ( function ( ) {
139+ self . set ( 'isSaving' , false ) ;
140+ } ) ;
145141}
146142} ) ;