This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Custom Widgets-Touch Config
#2
Hi
No special tool, notepad++ or similar will just do.
You have to zip it to tra.gz format. You can use 7zip for that.
What is important while uploading the widget ID must be unique for example here



Code:
$(function() {
   $.i18n.add('mosaic.alarm_fire_alert', {"ru" :{
       ctitle:"Датчик задымления с оповещениями",
       alert: "Сработал датчик задымления"
   }}),
   
   Widget.alarm_fire_alert3 = Widget.extend({
       config : {
           title : $.tr('mosaic.alarm_fire_alert.ctitle', 'Fire sensor with alerts'),
           fields : {
               title : {
                   datatype : "string",
                  title :  $.tr('mosaic.wtitle', 'Title')
               }  
           },
           objects : {
               object : {
                   datatype : 1,
                   title : $.tr('mosaic.alarmobject', 'Alarm Status Object')
               }
           },
           settings : {}            
       },
       changeValue : function(name, value) {
           if (value) {
               alertShow(
                   $.tr('mosaic.alarm_fire_alert.alert', 'Smoke detector triggered'),
                   false,
                   this,
                   "danger"
               )
           }
           return this.trigger("changed_value");
       }
   })

   WidgetView.alarm_fire_alert3 = WidgetView.extend({
        width : 2,
        height : 2,  

        init : function() {
           if($(window).width()<=800) {
              this.width=1;
              this.height=1;
           }
           this.listenTo(this.model, "changed_value", this.changed_value);
        },
        changed_value : function() {
           if (this.model.getValue("object")) $(".widget", this.$el).addClass('widget_alarm');
           else  $(".widget", this.$el).removeClass('widget_alarm');
        },
        template: _.template(" \
            <div class=\"widget widget_protection w-protect widget-fire<%=(getValue('object') ? ' widget_alarm' : '')%>\"> \
                <div class=\"widget-title widget-title_fire\"> \
                    <div class=\"txt\"><%=title() || ctitle()%></div> \
                </div> \
                <span class=\"indicator-protection\"> \
                    <span class=\"on\">on</span> \
                    <span class=\"alarm\">alarm</span> \
                </span> \
           </div> \
        "),
        afterRender : function() {
           var t = this;
           $(window).on('resize', function(){
               var w = $(window).width();
               if (t.width==2 && w<=800) t.size(1, 1);
               else if (t.width==1 && w>800) t.size(2, 2);
           });
        },
   })

})

alarm_fire_alert3 is the ID and it is used twice.
While importing widget in Mosaic the Key field must be widget ID. alarm_fire_alert3 in this case.

BR
------------------------------
Ctrl+F5
Reply


Messages In This Thread
RE: Custom Widgets-Touch Config - by Daniel - 26.02.2018, 17:08
RE: Custom Widgets-Touch Config - by Daniel - 28.02.2018, 11:40
RE: Custom Widgets-Touch Config - by Daniel - 28.02.2018, 11:57
RE: Custom Widgets-Touch Config - by Daniel - 28.02.2018, 12:43
RE: Custom Widgets-Touch Config - by Daniel - 01.03.2018, 09:18
RE: Custom Widgets-Touch Config - by Daniel - 02.03.2018, 13:10

Forum Jump: