move folder funciton
[sgn.git] / mason / breeders_toolbox / folder / folder_move.mas
blob99d830e0abd9b77e339327c3d50eed6093183283
2 <%args>
3 $project_type => undef
4 $folder_id => undef
5 $folder_name => undef
6 $parent_folder_id => undef
7 $parent_folder_name => undef
8 $breeding_program_id => undef
9 $breeding_program_name => undef
10 </%args>
12 <& /util/import_javascript.mas, classes => [ 'CXGN.TrialTreeFolders' ] &>
13 % my $dialog_type;
14 % my $folder_for_trials;
15 % my $folder_for_crosses;
16 % my $folder_for_genotyping_trials;
17 % my $folder_for_genotyping_projects;
18 % my $folder_for_tracking_activities;
19 % if ($project_type eq 'field_trial') { $folder_for_trials = 1;  $dialog_type = 'trial'}
20 % if ($project_type eq 'genotyping_plate') { $folder_for_genotyping_trials = 1; $dialog_type = 'genotyping plate' }
21 % if ($project_type eq 'crossing_experiment') { $folder_for_crosses = 1; $dialog_type = 'crossing experiment' }
22 % if ($project_type eq 'genotyping_project') { $folder_for_genotyping_projects = 1; $dialog_type = 'genotyping project' }
23 % if ($project_type eq 'activity_record') { $folder_for_tracking_activities = 1; $dialog_type = 'tracking activities' }
25 <div class="modal fade" id="move_folder_dialog" name="move_folder_dialog" tabindex="-1" role="dialog" aria-labelledby="moveFolderDialog">
26   <div class="modal-dialog" role="document">
27     <div class="modal-content">
28       <div class="modal-header">
29         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
30         <h4 class="modal-title" id="moveFolderDialog">Move a <% $dialog_type %> folder</h4>
31       </div>
32       <div class="modal-body">
33         <div class="container-fluid">
35                <form class="form-horizontal" role="form" method="post" id="move_folder_dialog_form" name="move_folder_dialog_form">
36           <div class="form-group">
37              <label class="col-sm-3 control-label">Breeding Program: </label>
38              <div class="col-sm-9" >
39                <div id="move_folder_breeding_program_select_div">
40 % if ($breeding_program_id) {
41                <input type="text" class="form-control" value="<% $breeding_program_name %>" disabled/>
42                <input type="hidden" id="move_folder_breeding_program_id" name="move_folder_breeding_program_id" value="<% $breeding_program_id %>" />
43 % } else {
44  [Loading...]
45 % }
46                </div>
47              </div>
48           </div>
49           <div class="form-group">
50               <label class="col-sm-3 control-label">Parent Folder: </label>
51               <div class="col-sm-9" >
52                 <div id="move_folder_parent_folder_select_div">
53 % if ($parent_folder_id) {
54                   <input type="text" class="form-control" value="<% $parent_folder_name %>" disabled/>
55                   <input type="hidden" id="move_folder_parent_folder_id" name="move_folder_parent_folder_id" value="<% $parent_folder_id %>" />
56 % } else {
57   [Loading...]
58 % }
59                 </div>
60               </div>
61                 </div>
62                 <div class="form-group">
63               <label class="col-sm-3 control-label">Folder Name: </label>
64               <div class="col-sm-9" >
65                 <div id="move_folder_select_div">
66 % if ($folder_id) {
67               <input type="text" class="form-control" value="<% $folder_name %>" disabled/>
68               <input type="hidden" id="move_folder_id" name="move_folder_id" value="<% $folder_id %>" />
69 % } else {
70 [Loading...]
71 % }
72                 </div>
73               </div>
74                 </div>
75                </form><br/>
76         </div>
77       </div>
78       <div class="modal-footer">
79         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
80               <button type="button" class="btn btn-primary" name="move_folder_submit" id="move_folder_submit" title="Move folder">Save</button>
81       </div>
82     </div>
83   </div>
84 </div>
86 <div class="modal fade" id="folder_move_success_dialog_message" name="folder_move_success_dialog_message" tabindex="-1" role="dialog" aria-labelledby="moveFolderSuccessDialog">
87     <div class="modal-dialog" role="document">
88         <div class="modal-content">
89             <div class="modal-header" style="text-align: center">
90                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
91                 <h4 class="modal-title" id="moveFolderSuccessDialog">Folder Move Successful</h4>
92             </div>
93             <div class="modal-body">
94                 <div class="container-fluid">
95                     <p>
96                         <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
97                         The folder was moved successfully
98                     </p>
99                 </div>
100             </div>
101             <div class="modal-footer">
102                 <button id="close_move_folder_success_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
103             </div>
104         </div>
105     </div>
106 </div>
108 <script defer="defer">
109 jQuery(document).ready(function() {
111   if(jQuery("#move_folder_breeding_program_id").length == 0) {
112     get_select_box('breeding_programs', 'move_folder_breeding_program_select_div', { 'name' : 'move_folder_breeding_program_id', 'id' : 'move_folder_breeding_program_id' });
113   }
115   jQuery('#move_folder_dialog_link').click( function() {
116     jQuery('#move_folder_dialog').modal("show");
117     if(jQuery("#move_folder_parent_folder_id").length == 0) {
118       breeding_program_change_move_parent_folders();
119     }
120     if(jQuery("#move_folder_id").length == 0) {
121       breeding_program_change_move_folders();
122     }
123   });
125   jQuery("#move_folder_breeding_program_select_div").on('change', "#move_folder_breeding_program_id", function() {
126     breeding_program_change_move_parent_folders();
127     breeding_program_change_move_folders();
128   });
130   jQuery('#move_folder_submit').click( function() {
131     move_folder();
132   });
134   jQuery('#folder_move_success_dialog_message').on('hidden.bs.modal', function () {
135       location.reload();
136   })
140 function breeding_program_change_move_parent_folders() {
141     var breeding_program_id = jQuery("#move_folder_breeding_program_id").val();
142     var folder_for_trials;
143     var folder_for_crosses;
144     var folder_for_genotyping_trials;
145     var folder_for_genotyping_projects;
146     var folder_for_tracking_activities;
148 % if ($folder_for_trials){
149     folder_for_trials = true;
150 % }
151 % if ($folder_for_crosses){
152     folder_for_crosses = true;
153 % }
154 % if ($folder_for_genotyping_trials){
155     folder_for_genotyping_trials = true;
156 % }
157 % if ($folder_for_genotyping_projects){
158     folder_for_genotyping_projects = true;
159 % }
160 % if ($folder_for_tracking_activities){
161     folder_for_tracking_activities = true;
162 % }
164   get_select_box('folders', 'move_folder_parent_folder_select_div', { 'name' : 'move_folder_parent_folder_id', 'id' : 'move_folder_parent_folder_id', 'breeding_program_id' : breeding_program_id, 'empty' : 1, 'folder_for_trials' : folder_for_trials, 'folder_for_crosses' : folder_for_crosses, 'folder_for_genotyping_trials': folder_for_genotyping_trials, 'folder_for_genotyping_projects': folder_for_genotyping_projects , 'folder_for_tracking_activities': folder_for_tracking_activities});
167 function breeding_program_change_move_folders() {
168     var breeding_program_id = jQuery("#move_folder_breeding_program_id").val();
169     var folder_for_trials;
170     var folder_for_crosses;
171     var folder_for_genotyping_trials;
172     var folder_for_genotyping_projects;
173     var folder_for_tracking_activities;
175 % if ($folder_for_trials){
176     folder_for_trials = true;
177 % }
178 % if ($folder_for_crosses){
179     folder_for_crosses = true;
180 % }
181 % if ($folder_for_genotyping_trials){
182     folder_for_genotyping_trials = true;
183 % }
184 % if ($folder_for_genotyping_projects){
185     folder_for_genotyping_projects = true;
186 % }
187 % if ($folder_for_tracking_activities){
188     folder_for_tracking_activities = true;
189 % }
191   get_select_box('folders', 'move_folder_select_div', { 'name' : 'move_folder_id', 'id' : 'move_folder_id', 'breeding_program_id' : breeding_program_id, 'folder_for_trials' : folder_for_trials, 'folder_for_crosses' : folder_for_crosses, 'folder_for_genotyping_trials': folder_for_genotyping_trials, 'folder_for_genotyping_projects': folder_for_genotyping_projects , 'folder_for_tracking_activities': folder_for_tracking_activities});
194 function move_folder() {
195   var parent_folder_id = jQuery('#move_folder_parent_folder_id').val();
196   var folder_id = jQuery('#move_folder_id').val();
197   //console.log(parent_folder_id);
198   //console.log(folder_id);
199   if (parent_folder_id == folder_id) {
200     alert("Cannot make a folder its own parent.");
201     return;
202   }
203   jQuery.ajax( {
204     url: '/ajax/folder/'+folder_id+'/associate/parent/'+parent_folder_id,
205     success: function(response) {
206       if (response.error) {
207         alert(response.error);
208         jQuery('#move_folder_dialog').modal("hide");
209       }
210       else {
211         refreshTrailJsTree(0);
212         jQuery('#folder_move_success_dialog_message').modal("show");
213         jQuery('#move_folder_dialog').modal("hide");
214       }
215     },
216     error: function(response) {
217       alert('An error occurred trying to move folder.');
218       jQuery('#move_folder_dialog').modal("hide");
219     }
220   });
224 </script>