@@ -34,41 +34,63 @@ mediaflow.filter('sizeConverter', function () {
34
34
}
35
35
} ) ;
36
36
37
- mediaflow . controller ( 'MediaFlowFieldCtrl ' , function ( $scope , $http , $upload ) {
37
+ mediaflow . controller ( 'MediaFlowCtrl ' , function ( $scope , $http , $upload ) {
38
38
$scope . connection = true ;
39
- $scope . showMedia = false ;
40
- $scope . spin = false ;
41
- $scope . searchText = '' ;
42
39
$scope . media = [ ] ;
43
-
40
+ $scope . spin = true ;
41
+ $scope . searchText = '' ;
44
42
$scope . testConnection = function ( ) {
45
43
$http . get ( '/admin/mediaflow/check' ) . success ( function ( result ) {
46
44
$scope . connection = result ;
47
45
} ) ;
48
46
} ;
49
-
50
47
$scope . testConnection ( ) ;
51
48
52
49
$scope . getMedia = function ( search ) {
53
50
var url = '/admin/mediaflow/media' ;
54
51
var config = { } ;
55
52
if ( search ) config . params = { q : search } ;
56
- $scope . spin = true ;
57
- $http . get ( url , config ) . success ( function ( result ) {
58
- $scope . media = result ;
59
- $scope . spin = false ;
60
- } ) ;
53
+ return $http . get ( url , config ) ;
61
54
} ;
62
55
63
- $scope . getMedia ( ) ;
56
+ $scope . onFileSelect = function ( $files ) {
57
+ $scope . spin = true ;
58
+ for ( var i = 0 ; i < $files . length ; i ++ ) {
59
+ var $file = $files [ i ] ;
60
+ $scope . upload = $upload . upload ( {
61
+ url : '/admin/mediaflow/upload' ,
62
+ file : $file
63
+ } ) . then ( function ( args ) {
64
+ $scope . media . unshift ( args . data ) ;
65
+ $scope . spin = false ;
66
+ } , function ( args ) {
67
+ console . log ( 'err' , args ) ;
68
+ $scope . spin = false ;
69
+ } ) ;
70
+ }
71
+ }
72
+ } ) ;
73
+
74
+ mediaflow . controller ( 'MediaFlowFieldCtrl' , function ( $scope , $http , $upload ) {
75
+ $scope . showMedia = false ;
76
+
77
+ var updateMedia = function ( search ) {
78
+ $scope . spin = true ;
79
+ $scope
80
+ . getMedia ( search )
81
+ . success ( function ( results ) {
82
+ $scope . media . splice
83
+ . bind ( $scope . media , 0 , $scope . media . length - 1 )
84
+ . apply ( $scope . media , results ) ;
85
+ $scope . spin = false ;
86
+ } ) ;
87
+ } ;
88
+ updateMedia ( ) ;
64
89
65
90
$scope . $watch ( 'searchText' , function ( searchText , ov ) {
66
- if ( searchText === ov ) return ;
67
- setTimeout ( function ( ) {
68
- if ( searchText == $scope . searchText ) {
69
- $scope . getMedia ( $scope . searchText ) ;
70
- }
71
- } , 250 ) ;
91
+ if ( searchText !== ov ) {
92
+ setTimeout ( updateMedia , 250 , searchText ) ;
93
+ }
72
94
} ) ;
73
95
74
96
$scope . select = function ( medium ) {
@@ -85,73 +107,27 @@ mediaflow.controller('MediaFlowFieldCtrl', function ($scope, $http, $upload) {
85
107
if ( ! $el ) { return ; }
86
108
$el . click ( ) ;
87
109
} ;
88
-
89
- $scope . onFileSelect = function ( $files ) {
90
- $scope . spin = true ;
91
- for ( var i = 0 ; i < $files . length ; i ++ ) {
92
- var $file = $files [ i ] ;
93
- $scope . upload = $upload . upload ( {
94
- url : '/admin/mediaflow/upload' ,
95
- file : $file ,
96
- progress : function ( evt ) {
97
- // TODO
98
- }
99
- } ) . then ( function ( args ) {
100
- $scope . media . unshift ( args . data ) ;
101
- $scope . spin = false ;
102
- } , function ( args ) {
103
- console . log ( 'err' , args ) ;
104
- $scope . spin = false ;
105
- } ) ;
106
- }
107
- }
108
110
} ) ;
109
111
110
112
mediaflow . controller ( 'MediaFlowBrowseCtrl' , function ( $scope , $http , $upload ) {
111
- $scope . connection = true ;
112
- $scope . searching = false ;
113
- $scope . searchText = '' ;
114
113
$scope . view = 'list' ;
115
- $scope . media = [ ] ;
116
- $scope . testConnection = function ( ) {
117
- $http . get ( '/admin/mediaflow/check' ) . success ( function ( result ) {
118
- $scope . connection = result ;
119
- } ) ;
120
- } ;
121
- $scope . testConnection ( ) ;
122
- $scope . getMedia = function ( search ) {
123
- var url = '/admin/mediaflow/media' ;
124
- var config = { } ;
125
- if ( search ) config . params = { q : search } ;
126
- $scope . searching = true ;
127
- $http . get ( url , config ) . success ( function ( result ) {
128
- $scope . media = result ;
129
- $scope . searching = false ;
130
- } ) ;
114
+
115
+ var updateMedia = function ( search ) {
116
+ $scope . spin = true ;
117
+ $scope
118
+ . getMedia ( search )
119
+ . success ( function ( results ) {
120
+ $scope . media . splice
121
+ . bind ( $scope . media , 0 , $scope . media . length - 1 )
122
+ . apply ( $scope . media , results ) ;
123
+ $scope . spin = false ;
124
+ } ) ;
131
125
} ;
132
- $scope . getMedia ( ) ;
126
+ updateMedia ( ) ;
133
127
134
128
$scope . $watch ( 'searchText' , function ( searchText , ov ) {
135
- if ( searchText === ov ) return ;
136
- setTimeout ( function ( ) {
137
- if ( searchText == $scope . searchText ) {
138
- $scope . getMedia ( $scope . searchText ) ;
139
- }
140
- } , 250 ) ;
141
- } ) ;
142
-
143
- $scope . onFileSelect = function ( $files ) {
144
- for ( var i = 0 ; i < $files . length ; i ++ ) {
145
- var $file = $files [ i ] ;
146
- $scope . upload = $upload . upload ( {
147
- url : '/admin/mediaflow/upload' ,
148
- file : $file ,
149
- progress : function ( evt ) {
150
- // TODO
151
- }
152
- } ) . success ( function ( data , status , headers , config ) {
153
- $scope . getMedia ( ) ;
154
- } ) ;
129
+ if ( searchText !== ov ) {
130
+ setTimeout ( updateMedia , 250 , searchText ) ;
155
131
}
156
- }
132
+ } ) ;
157
133
} ) ;
0 commit comments