Advertisement
amr_aly

Open_pop_up_window

Jun 24th, 2022 (edited)
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.61 KB | None | 0 0
  1. ################# In your templates
  2.  
  3. {% block content %}
  4.    
  5.     <div class="card-body">
  6.                 <!-- -->
  7.                 <table class="table table-bordered">
  8.                     <thead>
  9.                         <tr>
  10.                             <th style="width: 10px"># ID</th>
  11.                             <th>Post Title</th>
  12.                             <th>Creation Date </th>
  13.                             <th>Description</th>
  14.                             <th>Status</th>
  15.                             <th style="width: 5%"><span class="fas fa-eye"></span></th>
  16.                             <th style="width: 5%"><span class="fas fa-edit"></span></th>
  17.                             <th style="width: 10%"><span class="fas fa-trash-alt"></span></th>
  18.                             <th style="width: 10%"><span class="fas fa-image"></span></th>
  19.                         </tr>
  20.                     </thead>
  21.                     {% for obj in main_page %}
  22.                     <tbody>
  23.                         <tr>
  24.                             <td>{{obj.id}}</td>
  25.                             <td>{{obj.title}}</td>
  26.                             <td>{{obj.created_at}}</td>
  27.                             <td>{{obj.description}}</td>
  28.                             <td>
  29.                                 {% if obj.active %}
  30.                                     <a href="{% url 'switch_active' obj.id 'branding' 'Posts' %}">
  31.                                         <span class="badge bg-gradient-success">active</span>
  32.                                     </a>
  33.                                 {% else %}
  34.                                     <a href="{% url 'switch_active' obj.id 'branding' 'Posts' %}">
  35.                                         <span class="badge bg-gradient-secondary">inactive</span>
  36.                                     </a>
  37.                                 {% endif %}
  38.                             </td>
  39.                             <td>
  40.                                 <a href="#">
  41.                                     <span class="badge bg-gradient-purple">view</span>
  42.                                 </a>
  43.                             </td>
  44.                             <td>
  45.                                 <a href="{% url 'edit_post' obj.id %}">
  46.                                     <span class="badge bg-gradient-primary">edit</span>
  47.                                 </a>
  48.                             </td>
  49.                             {% if obj.is_deleted %}
  50.                                 <td>
  51.                                     <a href="{% url 'switch_delete' obj.id 'branding' 'Posts' %}">
  52.                                         <span class="badge bg-gradient-danger">deleted</span>
  53.                                         <span class="fa fa-recycle"></span>
  54.                                     </a>
  55.                                 </td>
  56.                             {% else %}
  57.                                 <td>
  58.                                     <a href="{% url 'switch_delete' obj.id 'branding' 'Posts' %}" onclick="return
  59.                                           confirm('Are you sure, you will delete this record ?')">
  60.                                         <span class="fas fa-trash-alt"></span>
  61.                                     </a>
  62.                                 </td>
  63.                                
  64.                             {% endif %}
  65.                             <td>
  66.                                 {% if obj.image %}
  67.                                     <a href="#" onclick="openWindow('{{obj.image.url}}')">
  68.                                         <img src="{{obj.image.url}}" alt="pic" width ="50%" height="auto">
  69.                                     </a>
  70.  
  71.                                 {% endif %}
  72.                             </td>
  73.                         </tr>
  74.                     </tbody>
  75.                     {% endfor %}
  76.                 </table>
  77.             </div>
  78.  
  79. {% endblock %}
  80.  
  81. {% block scripts %}
  82.  
  83.     <script>
  84.         //** for open a good popup window nice code to perform the mission
  85.         function openWindow(url) {
  86.             var w = 480,
  87.                 h = 340;
  88.             if (document.getElementById) {
  89.                 w = screen.availWidth;
  90.                 h = screen.availHeight;
  91.             }
  92.  
  93.             var popW = 900, //300,
  94.                 popH = 500; //200;
  95.  
  96.             var leftPos = (w - popW) / 2;
  97.             var topPos = (h - popH) / 2;
  98.  
  99.             msgWindow = window.open(url, 'popup', 'width=' + popW + ',height=' + popH +
  100.             ',top=' + topPos + ',left=' + leftPos + ', scrollbars=yes');
  101.  
  102.            
  103.         }
  104.     </script>
  105.  
  106. {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement