@@ -8,6 +8,8 @@ class ContainersController extends AppController {
88
99 public $ _secure = true ;
1010
11+ public $ uses = ['Container ' , 'Location ' ];
12+
1113 public function beforeFilter () {
1214 parent ::beforeFilter ();
1315 $ this ->set ('active ' , 'containers.index ' );
@@ -17,7 +19,7 @@ public function dashboard() {
1719 $ this ->helpers [] = 'Time ' ;
1820 $ total_containers = $ this ->Container ->getTotalContainersPerUser ($ this ->Auth ->user ('id ' ));
1921 $ total_container_items = $ this ->Container ->getTotalContainerItemsPerUser ($ this ->Auth ->user ('id ' ));
20- $ total_locations = ClassRegistry:: init ( ' Location ' ) ->getTotalLocationsPerUser ($ this ->Auth ->user ('id ' ));
22+ $ total_locations = $ this -> Location ->getTotalLocationsPerUser ($ this ->Auth ->user ('id ' ));
2123
2224 // Recent items
2325 $ recent_items = $ this ->Container ->ContainerItem ->getRecentItems ($ this ->Auth ->user ('id ' ));
@@ -40,14 +42,14 @@ public function index() {
4042 $ this ->Session ->setFlash ('Start by creating a container. ' , 'notification/notice ' );
4143 $ this ->redirect (array ('action ' => 'add ' ));
4244 }
43-
45+
4446 // Check the cookie and render the view depending on what was selected
45- $ location_list = ClassRegistry:: init ( ' Location ' ) ->getLocationList ($ this ->Auth ->user ('id ' ), true );
47+ $ location_list = $ this -> Location ->getLocationList ($ this ->Auth ->user ('id ' ), true );
4648 array_unshift ($ location_list , array ('__UNASSIGNED__ ' => '-- Unassigned -- ' ));
4749 $ this ->set (compact ('containers ' , 'control ' , 'location_list ' ));
4850 $ this ->request ->data ['Location ' ]['uuid ' ] = !empty ($ this ->request ->params ['named ' ]['location ' ]) ? $ this ->request ->params ['named ' ]['location ' ] : null ;
4951 }
50-
52+
5153 public function change_view ($ view ) {
5254 $ this ->Session ->write ('Feature.change_view ' , $ view == 'list ' ? 'list ' : 'grid ' );
5355 $ this ->redirect ($ this ->referer ());
@@ -71,20 +73,27 @@ public function view($slug=null) {
7173 }
7274
7375 public function add () {
74- $ this ->set ('title_for_layout ' , __ ('Add New Container ' ));
76+ $ location_list = $ this ->Location ->getLocationList ($ this ->Auth ->user ('id ' ), true );
77+ $ this ->set (array (
78+ 'title_for_layout ' => __ ('Add New Container ' ),
79+ 'location_list ' => $ location_list
80+ ));
7581 if (!empty ($ this ->request ->data )) {
7682 $ this ->request ->data ['Container ' ]['user_id ' ] = $ this ->Auth ->user ('id ' );
77- $ results = $ this ->Container ->save ($ this ->request ->data );
83+ if (!empty ($ this ->request ->data ['Container ' ]['location_id ' ])) {
84+ $ this ->request ->data ['Container ' ]['location_id ' ] = $ this ->Location ->getIdByUUID ($ this ->request ->data ['Container ' ]['location_id ' ]);
85+ }
86+ $ this ->Container ->set ($ this ->request ->data );
87+ $ results = $ this ->Container ->save ();
7888 if ($ results ) {
7989 $ this ->Session ->setFlash ('Successfully added new container ' , 'notification/success ' );
80- $ page = (int ) ceil ($ this ->Container ->getTotalContainersPerUser ($ this ->Auth ->user ('id ' )) / $ this ->Container ->pagination_limit );
8190 $ this ->redirect (array ('controller ' => 'containers ' , 'action ' => 'view ' , $ results ['Container ' ]['slug ' ]));
8291 } else {
8392 $ this ->Session ->setFlash ('There was a problem saving your container. ' , 'notification/error ' );
8493 }
8594 }
8695 }
87-
96+
8897 public function ajax_add ($ container_item_id ) {
8998 $ this ->helpers [] = 'Time ' ;
9099 $ item = $ this ->Container ->ContainerItem ->find ('first ' , array (
@@ -112,7 +121,7 @@ public function edit($container_uuid='') {
112121 $ this ->Session ->setFlash (__ ('Unable to update the container. ' ), 'notification/error ' );
113122 }
114123 } else {
115- $ location_list = ClassRegistry:: init ( ' Location ' ) ->getLocationList ($ this ->Auth ->user ('id ' ));
124+ $ location_list = $ this -> Location ->getLocationList ($ this ->Auth ->user ('id ' ));
116125 $ this ->request ->data = $ this ->Container ->find ('first ' , array (
117126 'conditions ' => array ('uuid ' => $ container_uuid ),
118127 'contain ' => array ()
@@ -147,7 +156,7 @@ public function print_label($container_uuid) {
147156 'contain ' => array ()
148157 )));
149158 }
150-
159+
151160 public function export ($ container_uuid ) {
152161 $ this ->helpers [] = 'Csv ' ;
153162 $ this ->layout = false ;
@@ -164,7 +173,7 @@ public function export($container_uuid) {
164173 ));
165174 $ this ->set (compact ('data ' ));
166175 }
167-
176+
168177 public function bulk_print () {
169178 if (!empty ($ this ->request ->data )) {
170179 $ this ->helpers [] = 'GChart.QR ' ;
0 commit comments