<commit_before>/* -------------------------------------------------------------------------- */
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                */
/*                                                                            */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
/* not use this file except in compliance with the License. You may obtain    */
/* a copy of the License at                                                   */
/*                                                                            */
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
/*                                                                            */
/* Unless required by applicable law or agreed to in writing, software        */
/* distributed under the License is distributed on an "AS IS" BASIS,          */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
/* See the License for the specific language governing permissions and        */
/* limitations under the License.                                             */
/* -------------------------------------------------------------------------- */

define(function(require) {
//  require('foundation.alert');
  var OpenNebula = require('opennebula');
  var Locale = require('utils/locale');
  var Config = require('sunstone-config');
  var Notifier = require('utils/notifier');
  var Humanize = require('utils/humanize');
  var ResourceSelect = require('utils/resource-select');
  var LabelsUtils = require('utils/labels/utils');
  var TemplateUtils = require('utils/template-utils');

  var TemplateTemplatesList = require('hbs!./list');

  var _accordionId = 0;
  var TEMPLATE_LABELS_COLUMN = 3;

  return {
    'generate': generate_provision_templates_list,
    'show': show_provision_template_list,
    'updateDatatable': update_provision_templates_datatable,
  };

  function show_provision_template_list(timeout) {
    $(".section_content").hide();
    $(".provision_templates_list_section").fadeIn();

    $(".provision_templates_list_refresh_button", $(".provision_templates_list_section")).trigger("click");
  }

  function generate_provision_templates_list(context, opts) {
    context.off();
    context.html(html(opts));
    Foundation.reflow(context, 'accordion');
    setup_provision_templates_list(context, opts);
  }

  function html(opts_arg){
    opts = $.extend({
        title: Locale.tr("Templates"),
        refresh: true,
        create: true,
        active: true,
        filter: true
      },opts_arg)

    _accordionId += 1;
    return TemplateTemplatesList({'accordionId': _accordionId, 'opts': opts});
  }

  function update_provision_templates_datatable(datatable, timeout) {
    datatable.html('<div class="text-center">'+
      '<span class="fa-stack fa-5x">'+
        '<i class="fa fa-cloud fa-stack-2x"></i>'+
        '<i class="fa  fa-spinner fa-spin fa-stack-1x fa-inverse"></i>'+
      '</span>'+
      '<br>'+
      '<br>'+
      '<span>'+
      '</span>'+
      '</div>');

    setTimeout( function(){
      OpenNebula.Template.list({
        timeout: true,
        success: function (request, item_list){
          datatable.fnClearTable(true);
          if (item_list.length == 0) {
            datatable.html('<div class="text-center">'+
              '<span class="fa-stack fa-5x">'+
                '<i class="fa fa-cloud fa-stack-2x"></i>'+
                '<i class="fa fa-info-circle fa-stack-1x fa-inverse"></i>'+
              '</span>'+
              '<br>'+
              '<br>'+
              '<span>'+
                Locale.tr("There are no templates available")+
              '</span>'+
              '</div>');
          } else {
            datatable.fnAddData(item_list);

            // Labels are inserted only in the new VM wizard
            LabelsUtils.clearLabelsFilter(datatable, TEMPLATE_LABELS_COLUMN);
            var context = $('.labels-dropdown', datatable.closest('#provisionVMInstantiateTemplatesRow'));
            LabelsUtils.insertLabelsMenu({
              'context': context,
              'dataTable': datatable,
              'labelsColumn': TEMPLATE_LABELS_COLUMN,
              'labelsPath': 'VMTEMPLATE.TEMPLATE.LABELS',
              'placeholder': Locale.tr("No labels defined")
            });<commit_msg>Bug #4350: Filter out VR templates in cloud view<commit_after>/* -------------------------------------------------------------------------- */
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                */
/*                                                                            */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
/* not use this file except in compliance with the License. You may obtain    */
/* a copy of the License at                                                   */
/*                                                                            */
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
/*                                                                            */
/* Unless required by applicable law or agreed to in writing, software        */
/* distributed under the License is distributed on an "AS IS" BASIS,          */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
/* See the License for the specific language governing permissions and        */
/* limitations under the License.                                             */
/* -------------------------------------------------------------------------- */

define(function(require) {
//  require('foundation.alert');
  var OpenNebula = require('opennebula');
  var Locale = require('utils/locale');
  var Config = require('sunstone-config');
  var Notifier = require('utils/notifier');
  var Humanize = require('utils/humanize');
  var ResourceSelect = require('utils/resource-select');
  var LabelsUtils = require('utils/labels/utils');
  var TemplateUtils = require('utils/template-utils');

  var TemplateTemplatesList = require('hbs!./list');

  var _accordionId = 0;
  var TEMPLATE_LABELS_COLUMN = 3;

  return {
    'generate': generate_provision_templates_list,
    'show': show_provision_template_list,
    'updateDatatable': update_provision_templates_datatable,
  };

  function show_provision_template_list(timeout) {
    $(".section_content").hide();
    $(".provision_templates_list_section").fadeIn();

    $(".provision_templates_list_refresh_button", $(".provision_templates_list_section")).trigger("click");
  }

  function generate_provision_templates_list(context, opts) {
    context.off();
    context.html(html(opts));
    Foundation.reflow(context, 'accordion');
    setup_provision_templates_list(context, opts);
  }

  function html(opts_arg){
    opts = $.extend({
        title: Locale.tr("Templates"),
        refresh: true,
        create: true,
        active: true,
        filter: true
      },opts_arg)

    _accordionId += 1;
    return TemplateTemplatesList({'accordionId': _accordionId, 'opts': opts});
  }

  function update_provision_templates_datatable(datatable, timeout) {
    datatable.html('<div class="text-center">'+
      '<span class="fa-stack fa-5x">'+
        '<i class="fa fa-cloud fa-stack-2x"></i>'+
        '<i class="fa  fa-spinner fa-spin fa-stack-1x fa-inverse"></i>'+
      '</span>'+
      '<br>'+
      '<br>'+
      '<span>'+
      '</span>'+
      '</div>');

    setTimeout( function(){
      OpenNebula.Template.list({
        timeout: true,
        success: function (request, item_list){
          datatable.fnClearTable(true);

          item_list = item_list.filter(function(tmpl){
            return (tmpl.VMTEMPLATE.TEMPLATE.VROUTER == undefined ||
                    tmpl.VMTEMPLATE.TEMPLATE.VROUTER.toUpperCase() != "YES");
          });

          if (item_list.length == 0) {
            datatable.html('<div class="text-center">'+
              '<span class="fa-stack fa-5x">'+
                '<i class="fa fa-cloud fa-stack-2x"></i>'+
                '<i class="fa fa-info-circle fa-stack-1x fa-inverse"></i>'+
              '</span>'+
              '<br>'+
              '<br>'+
              '<span>'+
                Locale.tr("There are no templates available")+
              '</span>'+
              '</div>');
          } else {
            datatable.fnAddData(item_list);

            // Labels are inserted only in the new VM wizard
            LabelsUtils.clearLabelsFilter(datatable, TEMPLATE_LABELS_COLUMN);
            var context = $('.labels-dropdown', datatable.closest('#provisionVMInstantiateTemplatesRow'));
            LabelsUtils.insertLabelsMenu({
              'context': context,
              'dataTable': datatable,
              'labelsColumn': TEMPLATE_LABELS_COLUMN,
              'labelsPath': 'VMTEMPLATE.TEMPLATE.LABELS',
              'placeholder': Locale.tr("No labels defined")
            });
{'fraction_non_alphanumeric': 0.16209310076658148, 'fraction_numerical': 0.005332740806577047, 'mean_word_length': 1.8263736263736263, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1691757', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2347, 'n_words': 527}